Skip to content

Commit

Permalink
fix DelimWriter constructor over a filename
Browse files Browse the repository at this point in the history
cherry pick and modify: /vincentlaucsb/csv-parser/pull/vincentlaucsb#251
  • Loading branch information
hirohira9119 committed Oct 23, 2024
1 parent e24d625 commit f871e72
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 7 additions & 1 deletion include/internal/csv_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once
#include <fstream>
#include <iostream>
#include <memory>
#include <string>
#include <tuple>
#include <type_traits>
Expand Down Expand Up @@ -205,7 +206,11 @@ namespace csv {
*
* @param[out] filename File to write to
*/
DelimWriter(const std::string& filename) : DelimWriter(std::ifstream(filename)) {};
DelimWriter(const std::string& filename)
: inner_os(new std::ofstream(filename))
, out(*inner_os)
, quote_minimal(true)
{}

/** Destructor will flush remaining data
*
Expand Down Expand Up @@ -360,6 +365,7 @@ namespace csv {
IF_CONSTEXPR(Flush) out.flush();
}

std::unique_ptr<std::ofstream> inner_os;
OutputStream & out;
bool quote_minimal;
};
Expand Down
8 changes: 7 additions & 1 deletion single_include/csv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6524,6 +6524,7 @@ namespace csv {

#include <fstream>
#include <iostream>
#include <memory>
#include <string>
#include <tuple>
#include <type_traits>
Expand Down Expand Up @@ -6722,7 +6723,11 @@ namespace csv {
*
* @param[out] filename File to write to
*/
DelimWriter(const std::string& filename) : DelimWriter(std::ifstream(filename)) {};
DelimWriter(const std::string& filename)
: inner_os(new std::ofstream(filename))
, out(*inner_os)
, quote_minimal(true)
{}

/** Destructor will flush remaining data
*
Expand Down Expand Up @@ -6877,6 +6882,7 @@ namespace csv {
IF_CONSTEXPR(Flush) out.flush();
}

std::unique_ptr<std::ofstream> inner_os;
OutputStream & out;
bool quote_minimal;
};
Expand Down
8 changes: 7 additions & 1 deletion single_include_test/csv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6524,6 +6524,7 @@ namespace csv {

#include <fstream>
#include <iostream>
#include <memory>
#include <string>
#include <tuple>
#include <type_traits>
Expand Down Expand Up @@ -6722,7 +6723,11 @@ namespace csv {
*
* @param[out] filename File to write to
*/
DelimWriter(const std::string& filename) : DelimWriter(std::ifstream(filename)) {};
DelimWriter(const std::string& filename)
: inner_os(new std::ofstream(filename))
, out(*inner_os)
, quote_minimal(true)
{}

/** Destructor will flush remaining data
*
Expand Down Expand Up @@ -6877,6 +6882,7 @@ namespace csv {
IF_CONSTEXPR(Flush) out.flush();
}

std::unique_ptr<std::ofstream> inner_os;
OutputStream & out;
bool quote_minimal;
};
Expand Down

0 comments on commit f871e72

Please sign in to comment.