Skip to content

Commit f871e72

Browse files
committed
fix DelimWriter constructor over a filename
cherry pick and modify: /vincentlaucsb/csv-parser/pull/vincentlaucsb#251
1 parent e24d625 commit f871e72

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

include/internal/csv_writer.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#pragma once
66
#include <fstream>
77
#include <iostream>
8+
#include <memory>
89
#include <string>
910
#include <tuple>
1011
#include <type_traits>
@@ -205,7 +206,11 @@ namespace csv {
205206
*
206207
* @param[out] filename File to write to
207208
*/
208-
DelimWriter(const std::string& filename) : DelimWriter(std::ifstream(filename)) {};
209+
DelimWriter(const std::string& filename)
210+
: inner_os(new std::ofstream(filename))
211+
, out(*inner_os)
212+
, quote_minimal(true)
213+
{}
209214

210215
/** Destructor will flush remaining data
211216
*
@@ -360,6 +365,7 @@ namespace csv {
360365
IF_CONSTEXPR(Flush) out.flush();
361366
}
362367

368+
std::unique_ptr<std::ofstream> inner_os;
363369
OutputStream & out;
364370
bool quote_minimal;
365371
};

single_include/csv.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6524,6 +6524,7 @@ namespace csv {
65246524

65256525
#include <fstream>
65266526
#include <iostream>
6527+
#include <memory>
65276528
#include <string>
65286529
#include <tuple>
65296530
#include <type_traits>
@@ -6722,7 +6723,11 @@ namespace csv {
67226723
*
67236724
* @param[out] filename File to write to
67246725
*/
6725-
DelimWriter(const std::string& filename) : DelimWriter(std::ifstream(filename)) {};
6726+
DelimWriter(const std::string& filename)
6727+
: inner_os(new std::ofstream(filename))
6728+
, out(*inner_os)
6729+
, quote_minimal(true)
6730+
{}
67266731

67276732
/** Destructor will flush remaining data
67286733
*
@@ -6877,6 +6882,7 @@ namespace csv {
68776882
IF_CONSTEXPR(Flush) out.flush();
68786883
}
68796884

6885+
std::unique_ptr<std::ofstream> inner_os;
68806886
OutputStream & out;
68816887
bool quote_minimal;
68826888
};

single_include_test/csv.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6524,6 +6524,7 @@ namespace csv {
65246524

65256525
#include <fstream>
65266526
#include <iostream>
6527+
#include <memory>
65276528
#include <string>
65286529
#include <tuple>
65296530
#include <type_traits>
@@ -6722,7 +6723,11 @@ namespace csv {
67226723
*
67236724
* @param[out] filename File to write to
67246725
*/
6725-
DelimWriter(const std::string& filename) : DelimWriter(std::ifstream(filename)) {};
6726+
DelimWriter(const std::string& filename)
6727+
: inner_os(new std::ofstream(filename))
6728+
, out(*inner_os)
6729+
, quote_minimal(true)
6730+
{}
67266731

67276732
/** Destructor will flush remaining data
67286733
*
@@ -6877,6 +6882,7 @@ namespace csv {
68776882
IF_CONSTEXPR(Flush) out.flush();
68786883
}
68796884

6885+
std::unique_ptr<std::ofstream> inner_os;
68806886
OutputStream & out;
68816887
bool quote_minimal;
68826888
};

0 commit comments

Comments
 (0)