Skip to content

Commit e4caa7d

Browse files
committed
Common close function
1 parent 7dbe94d commit e4caa7d

File tree

6 files changed

+15
-30
lines changed

6 files changed

+15
-30
lines changed

core/include/core/dataio.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ g3_istream_from_path(std::istream &stream, const std::string &path,
3535
*/
3636
int g3_istream_handle(std::istream &stream);
3737

38-
/**
39-
* Clean up the input stream.
40-
*
41-
* @param stream A reference to the input stream, as configured by
42-
* g3_istream_from_path.
43-
*/
44-
void g3_istream_close(std::istream &stream);
45-
4638
/**
4739
* Configure a filtering stream for G3Frame compression to a local file.
4840
*
@@ -60,12 +52,12 @@ g3_ostream_to_path(std::ostream &stream, const std::string &path, bool append=fa
6052
size_t buffersize=1024*1024, const std::string &ext=".g3");
6153

6254
/**
63-
* Clean up the output stream.
55+
* Clean up the IO stream.
6456
*
65-
* @param stream A reference to the output stream, as configured by
66-
* g3_istream_from_path.
57+
* @param stream A reference to the IO stream, as configured by
58+
* g3_istream_from_path or g3_ostream_to_path.
6759
*/
68-
void g3_ostream_close(std::ostream &stream);
60+
void g3_stream_close(std::ios &stream);
6961

7062
/**
7163
* Check that the input filename is a valid filename on disk.

core/src/G3MultiFileWriter.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ G3MultiFileWriter::G3MultiFileWriter(boost::python::object filename,
7777

7878
G3MultiFileWriter::~G3MultiFileWriter()
7979
{
80-
g3_ostream_close(stream_);
80+
g3_stream_close(stream_);
8181
}
8282

8383
bool
@@ -103,7 +103,7 @@ G3MultiFileWriter::CheckNewFile(G3FramePtr frame)
103103
return false;
104104
}
105105

106-
g3_ostream_close(stream_);
106+
g3_stream_close(stream_);
107107

108108
std::string filename;
109109
if (filename_ != "") {
@@ -137,7 +137,7 @@ void G3MultiFileWriter::Process(G3FramePtr frame, std::deque<G3FramePtr> &out)
137137
bool new_file(false), meta_cached(false);
138138

139139
if (frame->type == G3Frame::EndProcessing) {
140-
g3_ostream_close(stream_);
140+
g3_stream_close(stream_);
141141
goto done;
142142
}
143143

core/src/G3Reader.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ G3Reader::G3Reader(const std::vector<std::string> &filename, int n_frames_to_rea
3131

3232
G3Reader::~G3Reader()
3333
{
34-
g3_istream_close(stream_);
34+
g3_stream_close(stream_);
3535
}
3636

3737
void G3Reader::StartFile(const std::string &path)

core/src/G3Writer.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ G3Writer::G3Writer(std::string filename,
1313

1414
G3Writer::~G3Writer()
1515
{
16-
g3_ostream_close(stream_);
16+
g3_stream_close(stream_);
1717
}
1818

1919
void G3Writer::Process(G3FramePtr frame, std::deque<G3FramePtr> &out)
@@ -27,7 +27,7 @@ void G3Writer::Process(G3FramePtr frame, std::deque<G3FramePtr> &out)
2727
G3PythonContext ctx("G3Writer", false);
2828

2929
if (frame->type == G3Frame::EndProcessing)
30-
g3_ostream_close(stream_);
30+
g3_stream_close(stream_);
3131
else if (streams_.size() == 0 ||
3232
std::find(streams_.begin(), streams_.end(), frame->type) !=
3333
streams_.end())

core/src/dataio.cxx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ void
290290
g3_istream_from_path(std::istream &stream, const std::string &path, float timeout,
291291
size_t buffersize, const std::string &ext)
292292
{
293-
g3_istream_close(stream);
293+
g3_stream_close(stream);
294294

295295
std::streambuf *sbuf = nullptr;
296296

@@ -337,15 +337,6 @@ g3_istream_handle(std::istream &stream)
337337
return rbuf->fd();
338338
}
339339

340-
void
341-
g3_istream_close(std::istream &stream)
342-
{
343-
std::streambuf* sbuf = stream.rdbuf();
344-
if (sbuf)
345-
delete sbuf;
346-
stream.rdbuf(nullptr);
347-
}
348-
349340
class OutputFileStreamCounter : public std::streambuf {
350341
public:
351342
OutputFileStreamCounter(const std::string& path, size_t size, bool append)
@@ -408,6 +399,8 @@ void
408399
g3_ostream_to_path(std::ostream &stream, const std::string &path, bool append,
409400
size_t buffersize, const std::string &ext)
410401
{
402+
g3_stream_close(stream);
403+
411404
std::streambuf *sbuf = nullptr;
412405

413406
Codec codec = get_codec(path, ext);
@@ -439,7 +432,7 @@ g3_ostream_to_path(std::ostream &stream, const std::string &path, bool append,
439432
}
440433

441434
void
442-
g3_ostream_close(std::ostream &stream)
435+
g3_stream_close(std::ios &stream)
443436
{
444437
std::streambuf* sbuf = stream.rdbuf();
445438
if (sbuf)

gcp/src/ARCFileReader.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ ARCFileReader::ARCFileReader(const std::vector<std::string> &filename,
165165

166166
ARCFileReader::~ARCFileReader()
167167
{
168-
g3_istream_close(stream_);
168+
g3_stream_close(stream_);
169169
}
170170

171171

0 commit comments

Comments
 (0)