text_out_file Class Reference

An output text file. More...

#include <text_file.h>

Inheritance diagram for text_out_file:

out_file_format

Detailed Description

This class is experimental.

Todo:
Test output with <'s and >'s and document this
Todo:
Document why the collection class is a friend
Note:
  • Text files are not entirely architecture-independent, For example, a larger integer will not be read correctly on small integer systems.
  • Long integer I/O is experimental

Definition at line 51 of file text_file.h.


Public Member Functions

 text_out_file (std::ostream *out_file, int width=80, bool bracket_objs=true)
 Use output stream out_file for text output.
 text_out_file (std::string file_name, std::ostream *prop=0, bool append=false, int width=80, bool bracket_objs=true)
 Create an output file with name file_name.
virtual int open (std::ostream *out_file, int width=80, bool bracket_objs=true)
 Use stream out_file for text output.
virtual int open (std::string file_name, std::ostream *prop=0, bool append=false, int width=80, bool bracket_objs=true)
 Create an output file with name file_name.
virtual int close ()
 Close the file or stream.
virtual int bool_out (bool dat, std::string name="")
 Output a bool variable.
virtual int char_out (char dat, std::string name="")
 Output a char variable.
virtual int char_out_internal (char dat, std::string name="")
 Output a char variable.
virtual int double_out (double dat, std::string name="")
 Output a double variable.
virtual int float_out (float dat, std::string name="")
 Output a float variable.
virtual int int_out (int dat, std::string name="")
 Output an int variable.
virtual int long_out (unsigned long int dat, std::string name="")
 Output a long integer variable.
virtual int string_out (std::string dat, std::string name="")
 Output a string.
virtual int word_out (std::string dat, std::string name="")
 Output a word.
virtual int start_object (std::string type, std::string name)
 Start object output.
virtual int end_object ()
 End object output.
virtual int end_line ()
 End line.
virtual int init_file ()
 Output initialization.
virtual int clean_up ()
 Perform any final write commands before the end of file.
int comment_out (std::string comment)
 Output a comment (only for text files).
std::string reformat_string (std::string in)
 Add brackets and replace carriage returns with spaces.

Protected Member Functions

virtual int flush ()
 Flush the string buffer if the current string is long enough.
bool is_hc_type (std::string type)
 If true, then type is a "hard-coded" type.

Protected Attributes

bool extra_brackets
 If true, add extra brackets.
std::stack< bool > hcs
 A list to indicate if the current object and subobjects are "hard-coded".
bool from_string
 True if the constructor was called with a string, false otherwise.
bool compressed
 True if the file is to be compressed.
bool gzip
 True if the file is to be compressed with gzip.
int file_width
 The width of the file.
std::ostream * outs
 The output stream.
std::ostream * props
 A pointer to an output stream to define output properties.
std::ostringstream * strout
 The temporary buffer as a stringstream.
std::string user_filename
 The user-specified filename.
std::string temp_filename
 The temporary filename used.

Constructor & Destructor Documentation

text_out_file ( std::ostream *  out_file,
int  width = 80,
bool  bracket_objs = true 
)

This constructor assumes that the I/O properties of out_file have already been set.

Note that the stream out_file should not have been opened in binary mode, and errors will likely occur if this is the case.

Todo:
Ensure streams are not opened in binary mode for safety.

text_out_file ( std::string  file_name,
std::ostream *  prop = 0,
bool  append = false,
int  width = 80,
bool  bracket_objs = true 
)

If prop is not 0 (i.e. not NULL), then the I/O properties (precision, fill, flags, etc) for the newly created file are taken to be the same as prop .


Member Function Documentation

virtual int end_line (  )  [virtual]

This calls flush() in case the current string buffer is larger than the width, and then outputs the remaining characters and creates a new stringstream.

Implements out_file_format.


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

Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page