cttl
defines publicly visible classes and functions of CTTL library.
More...
Classes | |
class | guard_node_stack |
Utility class to track positions of parseable substrings. More... | |
struct | inode_reader |
Represents readable node of a syntax tree, modeled on top of STL sequence container. More... | |
struct | inode_writer |
Represents writable node of a syntax tree, modeled on top of STL sequence container. More... | |
Functions | |
time_t | current_time () |
Returns current time. | |
template<typename StringT > | |
StringT | file2string (StringT const &filename_) |
Reads data from a text file and returns a string containing the data. | |
template<typename CharT > | |
void | file2string (CTTL_STD_CHAR filename_[], std::basic_string< CharT > &str_) |
Inputs data from a text file and stores results in a string provided by the user. | |
template<typename CharT > | |
void | file2string (CTTL_STD_CHAR const *filename_, std::basic_string< CharT > &str_) |
Inputs data from a text file and stores results in a string provided by the user. | |
template<typename CharT , typename StringT > | |
void | file2string (StringT const &filename_, std::basic_string< CharT > &str_) |
Inputs data from a text file and stores results in a string provided by the user. | |
template<typename SourceT > | |
CTTL_STD_STRING | itos (SourceT source_) |
Converts C++ built-in data types to std::string. | |
template<typename NodeDescriptorT , typename ContainerT > | |
bool | operator! (inode_writer< NodeDescriptorT, ContainerT > const &inode_) |
Bidirectional iterator: true if node position is zero. | |
template<typename NodeDescriptorT , typename ContainerT > | |
bool | operator!= (inode_writer< NodeDescriptorT, ContainerT > const &one_, inode_writer< NodeDescriptorT, ContainerT > const &another_) |
Bidirectional iterator: true if node positions are different. | |
template<typename NodeDescriptorT , typename ContainerT > | |
bool | operator!= (typename ContainerT::size_type offset_, inode_writer< NodeDescriptorT, ContainerT > const &inode_) |
Compare offsets. | |
template<typename NodeDescriptorT , typename ContainerT > | |
bool | operator!= (inode_writer< NodeDescriptorT, ContainerT > const &inode_, typename ContainerT::size_type offset_) |
Compare offsets. | |
template<typename NodeDescriptorT , typename ContainerT > | |
bool | operator< (typename ContainerT::size_type offset_, inode_writer< NodeDescriptorT, ContainerT > const &inode_) |
Compare offsets. | |
template<typename NodeDescriptorT , typename ContainerT > | |
bool | operator< (inode_writer< NodeDescriptorT, ContainerT > const &inode_, typename ContainerT::size_type offset_) |
Compare offsets. | |
template<typename NodeDescriptorT , typename ContainerT > | |
inode_writer< NodeDescriptorT, ContainerT > const & | operator<< (inode_writer< NodeDescriptorT, ContainerT > const &lhs_, int size_) |
Inserts N copies of default values at the end of the sequence container. | |
template<typename NodeDescriptorT , typename ContainerT > | |
bool | operator<= (typename ContainerT::size_type offset_, inode_writer< NodeDescriptorT, ContainerT > const &inode_) |
Compare offsets. | |
template<typename NodeDescriptorT , typename ContainerT > | |
bool | operator<= (inode_writer< NodeDescriptorT, ContainerT > const &inode_, typename ContainerT::size_type offset_) |
Compare offsets. | |
template<typename NodeDescriptorT , typename ContainerT > | |
bool | operator== (inode_writer< NodeDescriptorT, ContainerT > const &one_, inode_writer< NodeDescriptorT, ContainerT > const &another_) |
Bidirectional iterator: comparison of two inode_writer objects returns true if positions of the nodes are equal, false otherwise. | |
template<typename NodeDescriptorT , typename ContainerT > | |
bool | operator== (typename ContainerT::size_type offset_, inode_writer< NodeDescriptorT, ContainerT > const &inode_) |
Compare offsets. | |
template<typename NodeDescriptorT , typename ContainerT > | |
bool | operator== (inode_writer< NodeDescriptorT, ContainerT > const &inode_, typename ContainerT::size_type offset_) |
Compare offsets. | |
template<typename NodeDescriptorT , typename ContainerT > | |
bool | operator> (typename ContainerT::size_type offset_, inode_writer< NodeDescriptorT, ContainerT > const &inode_) |
Compare offsets. | |
template<typename NodeDescriptorT , typename ContainerT > | |
bool | operator> (inode_writer< NodeDescriptorT, ContainerT > const &inode_, typename ContainerT::size_type offset_) |
Compare offsets. | |
template<typename NodeDescriptorT , typename ContainerT > | |
bool | operator>= (typename ContainerT::size_type offset_, inode_writer< NodeDescriptorT, ContainerT > const &inode_) |
Compares offsets of two nodes. | |
template<typename NodeDescriptorT , typename ContainerT > | |
bool | operator>= (inode_writer< NodeDescriptorT, ContainerT > const &inode_, typename ContainerT::size_type offset_) |
Compare offsets. | |
template<typename CharT > | |
size_t | pipe_input_2_string (std::basic_string< CharT > &str_output_) |
Inputs data from standard input and stores it in a string provided by the user. | |
template<typename CharT > | |
size_t | pipe_input_2_string (std::basic_string< CharT > &str_output_, CharT delimiter_) |
Inputs data from standard input and stores it in a string provided by the user. | |
template<typename CharT > | |
size_t | pipe_input_2_vector (std::vector< std::basic_string< CharT > > &vect_input_) |
Inputs data from standard input and stores it in a vector provided by the user. | |
template<typename CharT > | |
size_t | pipe_input_2_vector (std::vector< std::basic_string< CharT > > &vect_input_, CharT const *filter_) |
Inputs data from standard input and stores it in a vector provided by the user. | |
template<typename CharT > | |
size_t | pipe_input_2_vector (std::vector< std::basic_string< CharT > > &vect_input_, std::basic_string< CharT > filter_) |
Inputs data from standard input and stores it in a vector provided by the user. | |
template<typename CharT > | |
void | string2file (CTTL_STD_CHAR filename_[], std::basic_string< CharT > const &str_) |
Writes data from string provided by the user into a text file. | |
template<typename CharT > | |
void | string2file (CTTL_STD_CHAR const *filename_, std::basic_string< CharT > const &str_) |
Writes data from string provided by the user into a text file. | |
template<typename CharT , typename StringT > | |
void | string2file (StringT const &filename_, std::basic_string< CharT > const &str_) |
Writes data from string provided by the user into a text file. | |
template<typename TargetT > | |
bool | string2type (CTTL_STD_STRING const &source_, TargetT &target_) |
Converts STL string to C++ type. | |
template<typename TargetT , typename FormatT > | |
bool | string2type (CTTL_STD_STRING const &source_, TargetT &target_, FormatT *ios_base_) |
Converts STL string to C++ type. | |
CTTL_STD_STRING | time2string (time_t time_) |
Converts time_t to string. | |
template<typename SourceT > | |
CTTL_STD_STRING | type2string (SourceT const &source_) |
Converts C++ type to string. | |
template<typename SourceT , typename FormatT > | |
CTTL_STD_STRING | type2string (SourceT const &source_, FormatT *ios_base_) |
Converts C++ type to string. | |
template<typename SourceT , typename FormatT > | |
CTTL_STD_STRING | type2string (SourceT const &source_, FormatT *ios_base_, int precision_) |
Converts C++ floating-point type to string. |
cttl
defines publicly visible classes and functions of CTTL library.
time_t cttl::current_time | ( | ) |
StringT cttl::file2string | ( | StringT const & | filename_ | ) |
Reads data from a text file and returns a string containing the data.
Definition at line 135 of file fileio.h.
00136 { 00137 StringT str_temp; 00138 file2string( filename_, str_temp ); 00139 return str_temp; 00140 }
void cttl::file2string | ( | CTTL_STD_CHAR | filename_[], | |
std::basic_string< CharT > & | str_ | |||
) |
Inputs data from a text file and stores results in a string provided by the user.
Definition at line 107 of file fileio.h.
00108 { 00109 // on windows platform \r\n are converted into single \n 00110 #ifdef __MINGW32__ 00111 std::ifstream fs( filename_ ); 00112 str_.erase(); 00113 str_.reserve( fs.rdbuf()->in_avail() ); 00114 CTTL_STD_CHAR ch; 00115 while( fs.get( ch ) ) { 00116 if( str_.capacity() == str_.size() ) 00117 str_.reserve( str_.capacity() * 3 ); 00118 str_.append( 1, CharT( ch ) ); 00119 } 00120 #else 00121 std::basic_ifstream< CharT > fs( filename_ ); 00122 str_.erase(); 00123 str_.reserve( fs.rdbuf()->in_avail() ); 00124 CharT ch; 00125 while( fs.get( ch ) ) { 00126 if( str_.capacity() == str_.size() ) 00127 str_.reserve( str_.capacity() * 3 ); 00128 str_.append( 1, ch ); 00129 } 00130 #endif // __MINGW32__ 00131 }
void cttl::file2string | ( | CTTL_STD_CHAR const * | filename_, | |
std::basic_string< CharT > & | str_ | |||
) |
Inputs data from a text file and stores results in a string provided by the user.
Definition at line 79 of file fileio.h.
00080 { 00081 // on windows platform \r\n are converted into single \n 00082 #ifdef __MINGW32__ 00083 std::ifstream fs( filename_ ); 00084 str_.erase(); 00085 str_.reserve( fs.rdbuf()->in_avail() ); 00086 CTTL_STD_CHAR ch; 00087 while( fs.get( ch ) ) { 00088 if( str_.capacity() == str_.size() ) 00089 str_.reserve( str_.capacity() * 3 ); 00090 str_.append( 1, CharT( ch ) ); 00091 } 00092 #else 00093 std::basic_ifstream< CharT > fs( filename_ ); 00094 str_.erase(); 00095 str_.reserve( fs.rdbuf()->in_avail() ); 00096 CharT ch; 00097 while( fs.get( ch ) ) { 00098 if( str_.capacity() == str_.size() ) 00099 str_.reserve( str_.capacity() * 3 ); 00100 str_.append( 1, ch ); 00101 } 00102 #endif // __MINGW32__ 00103 }
void cttl::file2string | ( | StringT const & | filename_, | |
std::basic_string< CharT > & | str_ | |||
) |
Inputs data from a text file and stores results in a string provided by the user.
Definition at line 51 of file fileio.h.
00052 { 00053 // on windows platform \r\n are converted into single \n 00054 #ifdef __MINGW32__ 00055 std::ifstream fs( filename_.c_str() ); 00056 str_.erase(); 00057 str_.reserve( fs.rdbuf()->in_avail() ); 00058 typename StringT::value_type ch; 00059 while( fs.get( ch ) ) { 00060 if( str_.capacity() == str_.size() ) 00061 str_.reserve( str_.capacity() * 3 ); 00062 str_.append( 1, CharT( ch ) ); 00063 } 00064 #else 00065 std::basic_ifstream< CharT > fs( filename_.c_str() ); 00066 str_.erase(); 00067 str_.reserve( fs.rdbuf()->in_avail() ); 00068 CharT ch; 00069 while( fs.get( ch ) ) { 00070 if( str_.capacity() == str_.size() ) 00071 str_.reserve( str_.capacity() * 3 ); 00072 str_.append( 1, ch ); 00073 } 00074 #endif // __MINGW32__ 00075 }
CTTL_STD_STRING cttl::itos | ( | SourceT | source_ | ) |
Converts C++ built-in data types to std::string.
For example,
int i = 127; std::string ss = itos( i );
Definition at line 49 of file itos.h.
00050 { 00051 return type2string( source_ ); 00052 }
bool cttl::operator! | ( | inode_writer< NodeDescriptorT, ContainerT > const & | inode_ | ) |
Bidirectional iterator: true if node position is zero.
Definition at line 650 of file inode_writer.h.
bool cttl::operator!= | ( | inode_writer< NodeDescriptorT, ContainerT > const & | one_, | |
inode_writer< NodeDescriptorT, ContainerT > const & | another_ | |||
) |
Bidirectional iterator: true if node positions are different.
Definition at line 640 of file inode_writer.h.
bool cttl::operator!= | ( | typename ContainerT::size_type | offset_, | |
inode_writer< NodeDescriptorT, ContainerT > const & | inode_ | |||
) |
bool cttl::operator!= | ( | inode_writer< NodeDescriptorT, ContainerT > const & | inode_, | |
typename ContainerT::size_type | offset_ | |||
) |
bool cttl::operator< | ( | typename ContainerT::size_type | offset_, | |
inode_writer< NodeDescriptorT, ContainerT > const & | inode_ | |||
) |
bool cttl::operator< | ( | inode_writer< NodeDescriptorT, ContainerT > const & | inode_, | |
typename ContainerT::size_type | offset_ | |||
) |
inode_writer< NodeDescriptorT, ContainerT > const& cttl::operator<< | ( | inode_writer< NodeDescriptorT, ContainerT > const & | lhs_, | |
int | size_ | |||
) |
Inserts N copies of default values at the end of the sequence container.
Adjusts node position accordingly to the insertion point. If N is zero, no insertions are made.
Definition at line 471 of file inode_writer.h.
00475 { 00476 inode_writer< NodeDescriptorT, ContainerT >* plhs_ = const_cast< inode_writer< NodeDescriptorT, ContainerT >* >( &lhs_ ); 00477 plhs_->offset( lhs_.container().size() ); 00478 if ( size_ ) { 00479 plhs_->container().resize( lhs_.offset() + size_ ); 00480 } 00481 00482 return lhs_; 00483 }
bool cttl::operator<= | ( | typename ContainerT::size_type | offset_, | |
inode_writer< NodeDescriptorT, ContainerT > const & | inode_ | |||
) |
bool cttl::operator<= | ( | inode_writer< NodeDescriptorT, ContainerT > const & | inode_, | |
typename ContainerT::size_type | offset_ | |||
) |
bool cttl::operator== | ( | inode_writer< NodeDescriptorT, ContainerT > const & | one_, | |
inode_writer< NodeDescriptorT, ContainerT > const & | another_ | |||
) |
Bidirectional iterator: comparison of two inode_writer objects returns true if positions of the nodes are equal, false otherwise.
Definition at line 630 of file inode_writer.h.
bool cttl::operator== | ( | typename ContainerT::size_type | offset_, | |
inode_writer< NodeDescriptorT, ContainerT > const & | inode_ | |||
) |
bool cttl::operator== | ( | inode_writer< NodeDescriptorT, ContainerT > const & | inode_, | |
typename ContainerT::size_type | offset_ | |||
) |
bool cttl::operator> | ( | typename ContainerT::size_type | offset_, | |
inode_writer< NodeDescriptorT, ContainerT > const & | inode_ | |||
) |
bool cttl::operator> | ( | inode_writer< NodeDescriptorT, ContainerT > const & | inode_, | |
typename ContainerT::size_type | offset_ | |||
) |
bool cttl::operator>= | ( | typename ContainerT::size_type | offset_, | |
inode_writer< NodeDescriptorT, ContainerT > const & | inode_ | |||
) |
bool cttl::operator>= | ( | inode_writer< NodeDescriptorT, ContainerT > const & | inode_, | |
typename ContainerT::size_type | offset_ | |||
) |
size_t cttl::pipe_input_2_string | ( | std::basic_string< CharT > & | str_output_ | ) |
Inputs data from standard input and stores it in a string provided by the user.
Definition at line 94 of file pipe_input.h.
00095 { 00096 return pipe_input_2_string( str_output_, CharT( '\t' ) ); 00097 }
size_t cttl::pipe_input_2_string | ( | std::basic_string< CharT > & | str_output_, | |
CharT | delimiter_ | |||
) |
Inputs data from standard input and stores it in a string provided by the user.
Definition at line 80 of file pipe_input.h.
00081 { 00082 std::basic_string< char > inp_text; 00083 while ( std::cin >> inp_text ) { 00084 // line by line: 00085 str_output_ += inp_text; 00086 str_output_ += delimiter_; 00087 } 00088 00089 return str_output_.length(); 00090 }
size_t cttl::pipe_input_2_vector | ( | std::vector< std::basic_string< CharT > > & | vect_input_ | ) |
Inputs data from standard input and stores it in a vector provided by the user.
Definition at line 69 of file pipe_input.h.
00070 { 00071 std::basic_string< CharT > inp_text; 00072 while ( std::cin >> inp_text ) { 00073 vect_input_.push_back( inp_text ); 00074 } 00075 return vect_input_.size(); 00076 }
size_t cttl::pipe_input_2_vector | ( | std::vector< std::basic_string< CharT > > & | vect_input_, | |
CharT const * | filter_ | |||
) |
Inputs data from standard input and stores it in a vector provided by the user.
Definition at line 62 of file pipe_input.h.
00063 { 00064 return pipe_input_2_vector( vect_input_, std::basic_string< CharT >( filter_ ) ); 00065 }
size_t cttl::pipe_input_2_vector | ( | std::vector< std::basic_string< CharT > > & | vect_input_, | |
std::basic_string< CharT > | filter_ | |||
) |
Inputs data from standard input and stores it in a vector provided by the user.
Definition at line 42 of file pipe_input.h.
00043 { 00044 std::basic_string< CharT > inp_text; 00045 while ( std::cin >> inp_text ) { 00046 // line by line: 00047 if ( filter_.length() ) { 00048 if ( inp_text.find( filter_ ) != std::basic_string< CharT >::npos ) { 00049 vect_input_.push_back( inp_text ); 00050 } else { 00051 } 00052 } else { 00053 // no filter was specified 00054 vect_input_.push_back( inp_text ); 00055 } 00056 } 00057 return vect_input_.size(); 00058 }
void cttl::string2file | ( | CTTL_STD_CHAR | filename_[], | |
std::basic_string< CharT > const & | str_ | |||
) |
Writes data from string provided by the user into a text file.
Definition at line 180 of file fileio.h.
00181 { 00182 // on windows platform single \n are converted into \r\n 00183 #ifdef __MINGW32__ 00184 std::ofstream file; 00185 file.open( filename_, std::ios_base::trunc ); 00186 file << reinterpret_cast< CTTL_STD_CHAR const* >( str_.c_str() );; 00187 file.close(); 00188 #else 00189 std::basic_ofstream< CharT > file; 00190 file.open( filename_, std::ios_base::trunc ); 00191 file << str_; 00192 file.close(); 00193 #endif // __MINGW32__ 00194 }
void cttl::string2file | ( | CTTL_STD_CHAR const * | filename_, | |
std::basic_string< CharT > const & | str_ | |||
) |
Writes data from string provided by the user into a text file.
Definition at line 162 of file fileio.h.
00163 { 00164 // on windows platform single \n are converted into \r\n 00165 #ifdef __MINGW32__ 00166 std::ofstream file; 00167 file.open( filename_, std::ios_base::trunc ); 00168 file << reinterpret_cast< CTTL_STD_CHAR const* >( str_.c_str() ); 00169 file.close(); 00170 #else 00171 std::basic_ofstream< CharT > file; 00172 file.open( filename_, std::ios_base::trunc ); 00173 file << str_; 00174 file.close(); 00175 #endif // __MINGW32__ 00176 }
void cttl::string2file | ( | StringT const & | filename_, | |
std::basic_string< CharT > const & | str_ | |||
) |
Writes data from string provided by the user into a text file.
Definition at line 144 of file fileio.h.
00145 { 00146 // on windows platform single \n are converted into \r\n 00147 #ifdef __MINGW32__ 00148 std::ofstream file; 00149 file.open( filename_.c_str(), std::ios_base::trunc ); 00150 file << reinterpret_cast< typename StringT::value_type const* >( str_.c_str() ); 00151 file.close(); 00152 #else 00153 std::basic_ofstream< CharT > file; 00154 file.open( filename_.c_str(), std::ios_base::trunc ); 00155 file << str_; 00156 file.close(); 00157 #endif // __MINGW32__ 00158 }
bool cttl::string2type | ( | CTTL_STD_STRING const & | source_, | |
TargetT & | target_ | |||
) |
Converts STL string to C++ type.
TargetT | specifies output variable type. |
source_ | Input string with textual representation of the input value, such as 12345. | |
target_ | reference to C++ object representing output variable to receive the result of conversion. |
Definition at line 218 of file string_format.h.
bool cttl::string2type | ( | CTTL_STD_STRING const & | source_, | |
TargetT & | target_, | |||
FormatT * | ios_base_ | |||
) |
Converts STL string to C++ type.
TargetT | specifies output variable type. | |
FormatT | specifies STL stream manipulator, usually a function pointer: std::ios_base& ( *ios_base_ ) ( std::ios_base& ). |
source_ | Input string with textual representation of the source value, such as 1234.56789, true, 0xFF, etc. | |
target_ | reference to C++ object representing output variable to receive the result of conversion. | |
ios_base_ | STL stream manipulator, such as std::dec (base ten) std::hex (hexidecimal, base 16) std::oct (octal, base 8) etc. |
Definition at line 185 of file string_format.h.
00190 { 00191 std::istringstream iss( source_ ); 00192 return !( iss >> ios_base_ >> target_ ).fail(); 00193 }
CTTL_STD_STRING cttl::time2string | ( | time_t | time_ | ) |
Converts time_t to string.
Definition at line 59 of file timeutils.h.
00060 { 00061 CTTL_STD_CHAR* ptime = reinterpret_cast< CTTL_STD_CHAR* >( ctime( &time_ ) ); // get rid of the trailing \n 00062 return CTTL_STD_STRING( ptime, strlen( reinterpret_cast< char const* >( ptime ) ) - 1 ); 00063 }
CTTL_STD_STRING cttl::type2string | ( | SourceT const & | source_ | ) |
Converts C++ type to string.
SourceT | specifies input variable type. |
source_ | constant reference to C++ object representing input variable to convert to STL string. |
Definition at line 139 of file string_format.h.
00140 { 00141 std::basic_stringstream< CTTL_STD_CHAR > stream_; 00142 stream_ << source_; 00143 return stream_.str(); 00144 }
CTTL_STD_STRING cttl::type2string | ( | SourceT const & | source_, | |
FormatT * | ios_base_ | |||
) |
Converts C++ type to string.
SourceT | specifies input variable type. | |
FormatT | specifies STL stream manipulator, usually a function pointer: std::ios_base& ( *ios_base_ ) ( std::ios_base& ). |
source_ | constant reference to C++ object representing input variable to convert to STL string. | |
ios_base_ | STL stream manipulator, such as std::dec (base ten) std::hex (hexidecimal, base 16) std::oct (octal, base 8) etc. |
Definition at line 118 of file string_format.h.
00119 { 00120 std::basic_stringstream< CTTL_STD_CHAR > stream_; 00121 stream_ << ios_base_ << source_; 00122 return stream_.str(); 00123 }
CTTL_STD_STRING cttl::type2string | ( | SourceT const & | source_, | |
FormatT * | ios_base_, | |||
int | precision_ | |||
) |
Converts C++ floating-point type to string.
SourceT | specifies floating-point type. | |
FormatT | specifies STL stream manipulator, usually a function pointer: std::ios_base& ( *ios_base_ ) ( std::ios_base& ). |
source_ | constant reference to C++ object representing floating-point input variable to convert to STL string. | |
precision_ | an integer specifying desired precision. | |
ios_base_ | STL stream manipulator, such as std::showpoint (always show floating point) std::scientific (e.g. 1.234568e+003) std::fixed (no exponent field) etc. |
Definition at line 80 of file string_format.h.
00081 { 00082 std::basic_stringstream< CTTL_STD_CHAR > stream_; 00083 stream_.precision( precision_ ); 00084 stream_ << ios_base_ << source_; 00085 return stream_.str(); 00086 }