33 inline std::ostream&
operator<<( std::ostream& strm,
const FileParser::icstring& s )
35 return strm << std::string(s.data(),s.length() );
49 if ( !
load( file ) ) {
51 sprintf( error,
"File '%s' was not found.\n", file.c_str() );
52 fprintf( stderr,
"%s", error );
70 FILE *fd = fopen( file.c_str(),
"r" );
76 const int size = 1024;
79 while ( fgets( line, size, fd ) ) {
81 char *sep = strchr( line,
'#' );
95 char *start_key = line;
96 while ( isspace( *start_key ) && (*start_key !=
'\0') ) {
101 if ( *start_key ==
'\0' )
105 sep = strchr( line,
'=' );
108 char *start_val = sep+1;
110 while ( isspace( *start_val ) && ( *start_val !=
'\0' ) ) {
114 if ( *start_val ==
'\0' )
120 while( isspace( *sep ) )
124 sep = start_val + strlen( start_val ) - 1;
127 while ( isspace( *sep ) && ( *sep !=
'\0' ) )
133 f_lst.push_back( std::make_pair( start_key, start_val ) );
147 ItemList::const_iterator it =
f_lst.begin();
149 while ( it !=
f_lst.end() ) {
151 if ( (*it).first == key.c_str() ) {
169 ItemList::const_iterator it =
f_lst.begin();
171 while ( it !=
f_lst.end() ) {
173 if ( it->first == key.c_str() ) {
184 std::vector<std::string>
187 std::vector<std::string> values;
188 ItemList::const_iterator it =
f_lst.begin();
190 while ( it !=
f_lst.end() ) {
192 if ( it->first == key.c_str() ) {
194 values.push_back( it->second );
int count(const std::string &key) const
FileParser(const std::string &file)
int load(const std::string &file)
ostream & operator<<(ostream &os, const Sample &value)
std::vector< std::string > getAll(const std::string &key) const
std::string get(const std::string &key) const