Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

Parser.h

00001 #ifndef Parser_h
00002 #define Parser_h 1
00003 
00004 //#include "lcio.h"
00005 #include "IParser.h"
00006 #include "StringParameters.h"
00007 
00008 #include <fstream>
00009 #include <string>
00010 #include <iostream>
00011 
00012 namespace marlin{
00013 
00014 class LCTokenizer ;
00015 
00016 
00017 typedef std::map< std::string ,  StringParameters* > StringParametersMap ;
00018 
00019 
00035 class Parser : public IParser {
00036   
00037 
00038 public:
00039   
00040 
00041   //  Parser(const std::string[] & namespaces ) ;
00042   //   void parse( const std::string& fileName )
00043   
00044   Parser( const std::string& fileName ) ;
00045   virtual ~Parser() ; 
00046 
00047   StringParameters* getParameters( const std::string& sectionName ) const ;
00048   
00051   void parse() ;
00052 
00053 
00054 protected:
00055 
00059   int readNextValidLine( std::string& str , std::istream& stream) ;
00060 
00061 
00062   mutable StringParametersMap _map ;
00063   StringParameters* _current ;
00064 
00065   std::string _fileName ;
00066 
00067 private:
00068   Parser() ;
00069 
00070 };
00071 
00072 
00073 
00074 
00075 
00078 class LCTokenizer{
00079 
00080   std::vector< std::string >& _tokens ;
00081   char _del ;
00082   char _last ;
00083  public:
00084 
00085   LCTokenizer( std::vector< std::string >& tokens, char del ) : _tokens(tokens) , _del(del), _last(del) {
00086   }
00087 
00088 
00089   void operator()(const char& c) { 
00090 
00091     if( c != _del  ) {
00092 
00093         if( _last == _del  ) {
00094           _tokens.push_back("") ; 
00095         }
00096       _tokens.back() += c ;
00097       result() ;
00098     }
00099     _last = c ;
00100 
00101   } 
00102 
00103   ~LCTokenizer(){
00104   }
00105   
00106   std::vector<std::string> & result()  { 
00107     
00108     return _tokens ; 
00109     
00110   }
00111 };
00112 
00113 
00114 } // end namespace marlin 
00115 #endif

Generated on Mon Jan 12 09:48:51 2009 for Marlin by doxygen 1.3.5