#include <text_file.h>
A collection file is simply a text file containing a list of objects specially formatted for input and output. Each entry in the text file is of the form:
object_type object_name object_version word_number word1 word2 word3 ...
The type, name, and version are all strings that contain no whitespace. "a_name" is a valid name but, "a name" is not.
Parts of the object definition may be separated by any amount of whitespace, with the exception of 'strings'.
The collection file may contain comments, which are lines that begin with the '#' character. Comments may last more than one line (so long as every line begins with '#'), but they may not occur in the middle of an object definition.
# comment 1 double a 4.0 double[] c 4 4.5 3.4 2.3 4.2 # comment 2 double b 5.0
# comment 1 double a 4.0 double[] c 4 4.5 3.4 2.3 4.2 double b # comment 2 5.0
Normal variable: type name version word data1 ... data2
Object containing pointer: type name version word data1 ... ptr_type ptr_name ... data2
where ptr_type is the type of the object being pointed to and ptr_name is the name of the object. If it's not in the list, then the object is assigned a unique name of the form ptrX where 'X' is an integer >= 0.
Static objects are the same, except they are preceeded by the keyword static
and do not have a name associated with them.
This is useful for output to text files and to std::cout, i.e. text_out_file tf(&cout);
Note: Text files are not entirely architecture-independent, For example, a larger integer will not be read correctly on small integer systems.
Definition at line 97 of file text_file.h.
Public Member Functions | |
text_out_file (std::ostream *out_file, int width=80) | |
Use output stream out_file for text output. | |
text_out_file (std::string file_name, std::ostream *prop=NULL, bool append=false, int width=80) | |
Create an output file with name file_name . | |
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 an long 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 () |
Finish the 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. | |
bool | is_hc_type (std::string type) |
If true, then type is a "hard-coded" type. | |
Protected Attributes | |
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. |
text_out_file | ( | std::ostream * | out_file, | |
int | width = 80 | |||
) |
Use output stream out_file
for text output.
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.
text_out_file | ( | std::string | file_name, | |
std::ostream * | prop = NULL , |
|||
bool | append = false , |
|||
int | width = 80 | |||
) |
Create an output file with name file_name
.
If prop
is not null, then the I/O properties (precision, fill, flags, etc) for the newly created file are taken to be the same as prop
.
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page