FileOutputImpl Class Reference
Inheritance diagram for FileOutputImpl:
Collaboration diagram for FileOutputImpl:

Public Member Functions

virtual bool Open (const std::string &filename, bool binary)
 
virtual std::ostream & Stream ()
 
virtual bool Close ()
 
virtual ~FileOutputImpl ()
 
- Public Member Functions inherited from OutputImplBase
virtual ~OutputImplBase ()
 

Private Attributes

std::string filename_
 
std::ofstream os_
 

Detailed Description

Definition at line 199 of file kaldi-io.cc.

Constructor & Destructor Documentation

◆ ~FileOutputImpl()

virtual ~FileOutputImpl ( )
inlinevirtual

Definition at line 225 of file kaldi-io.cc.

References KALDI_ERR.

225  {
226  if (os_.is_open()) {
227  os_.close();
228  if (os_.fail())
229  KALDI_ERR << "Error closing output file " << filename_;
230  }
231  }
std::string filename_
Definition: kaldi-io.cc:233
std::ofstream os_
Definition: kaldi-io.cc:234
#define KALDI_ERR
Definition: kaldi-error.h:147

Member Function Documentation

◆ Close()

virtual bool Close ( )
inlinevirtual

Implements OutputImplBase.

Definition at line 218 of file kaldi-io.cc.

References KALDI_ERR.

218  {
219  if (!os_.is_open())
220  KALDI_ERR << "FileOutputImpl::Close(), file is not open.";
221  // I believe this error can only arise from coding error.
222  os_.close();
223  return !(os_.fail());
224  }
std::ofstream os_
Definition: kaldi-io.cc:234
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ Open()

virtual bool Open ( const std::string &  filename,
bool  binary 
)
inlinevirtual

Implements OutputImplBase.

Definition at line 201 of file kaldi-io.cc.

References KALDI_ERR, and MapOsPath.

201  {
202  if (os_.is_open()) KALDI_ERR << "FileOutputImpl::Open(), "
203  << "open called on already open file.";
204  filename_ = filename;
205  os_.open(MapOsPath(filename_).c_str(),
206  binary ? std::ios_base::out | std::ios_base::binary
207  : std::ios_base::out);
208  return os_.is_open();
209  }
#define MapOsPath(x)
Definition: kaldi-io.cc:36
std::string filename_
Definition: kaldi-io.cc:233
std::ofstream os_
Definition: kaldi-io.cc:234
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ Stream()

virtual std::ostream& Stream ( )
inlinevirtual

Implements OutputImplBase.

Definition at line 211 of file kaldi-io.cc.

References KALDI_ERR.

211  {
212  if (!os_.is_open())
213  KALDI_ERR << "FileOutputImpl::Stream(), file is not open.";
214  // I believe this error can only arise from coding error.
215  return os_;
216  }
std::ofstream os_
Definition: kaldi-io.cc:234
#define KALDI_ERR
Definition: kaldi-error.h:147

Member Data Documentation

◆ filename_

std::string filename_
private

Definition at line 233 of file kaldi-io.cc.

◆ os_

std::ofstream os_
private

Definition at line 234 of file kaldi-io.cc.


The documentation for this class was generated from the following file: