parseline/ParseLine.hh

00001 /* -*- mode: c++; c-basic-offset: 4; -*- */
00002 #ifndef PARSELINE_HH
00003 #define PARSELINE_HH
00004 
00005 #include <time.h>
00006 #include <fstream>
00007 #include <string>
00008 
00009 //======================================  Line Parser class
00033 class ParseLine {
00034 public: 
00039   ParseLine(const char* file);
00040 
00045   ParseLine(std::istream& stream);
00046 
00050   ~ParseLine(void);
00051 
00059   int getLine(void);
00060 
00066   const char* getArg(int i) const;
00067 
00072   int getCount(void) const;
00073 
00078   double getDouble(int i) const;
00079 
00085   unsigned long getHex(int i) const;
00086 
00092   long getInt(int i) const;
00093 
00096   long getLineNumber(void) const;
00097 
00111   void getRange(int i, double& lo, double& hi, char sep='-') const;
00112 
00117   bool isOpen(void) const;
00118 
00124   const char* operator[](int i) const;
00125 
00128   void setComment(const std::string& st);
00129 
00132   void setDefault(void);
00133 
00136   void setDelim(const std::string& st);
00137 
00143   void setLog(std::ostream& log);
00144 
00149   void setParen(const std::string& st);
00150 
00154   void setQuote(const std::string& st);
00155 
00159   void setEscape(const std::string& st);
00160 
00161 private:
00162   int  appendLine(int offset);
00163   enum chtype {
00164     kDefault,
00165     kDelim,
00166     kParen,
00167     kQuote,
00168     kComment,
00169     kEscape
00170   };
00171 
00172 private:
00173   static const int table_size=256;          // table_size must be a power of 2
00174   static const int table_mask=table_size-1;
00175   std::ifstream mFile;
00176   std::istream& mStream;
00177   std::ostream* mLog;
00178   int         mCount;
00179   char        mTable[table_size];
00180   const char* mArg[128];
00181   char        mLine[1024];
00182   long        mLineNumber;
00183 };
00184 
00185 //======================================  Inline functions
00186 inline bool
00187 ParseLine::isOpen(void) const {
00188     return mStream.good();
00189 }
00190 
00191 inline int
00192 ParseLine::getCount(void) const {
00193     return mCount;
00194 }
00195 
00196 inline long
00197 ParseLine::getLineNumber(void) const {
00198     return mLineNumber;
00199 }
00200 
00201 inline const char* 
00202 ParseLine::operator[](int i) const {
00203     return getArg(i);
00204 }
00205 
00206 #endif  //   PARSELINE_HH

Generated on Sun Mar 8 19:20:51 2009 for dmt by  doxygen 1.5.4