Main Page   Namespace List   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Symvar.hh

Go to the documentation of this file.
00001 #ifndef SYMVAR_HEADER
00002 #define SYMVAR_HEADER
00003 
00004 // ==== CLASS HEADER Symvar.hh ====
00005 
00012 // 5-Oct-2001. Andras Aszodi
00013 
00014 // ==== STANDARD HEADERS ====
00015 
00016 #include <stdlib.h>
00017 
00018 #ifdef _STANDARD_C_PLUS_PLUS
00019 #include <list>
00020 #include <iostream>
00021 #include <iomanip>
00022 #include <algorithm>
00023 #else
00024 #include <list.h>
00025 #include <iostream.h>
00026 #include <iomanip.h>
00027 #include <algo.h>
00028 #endif
00029 
00030 #include <string>
00031 using namespace std;
00032 #ifndef NPOS
00033 #define NPOS string::npos
00034 #endif
00035 
00036 // ==== MODULE HEADERS ====
00037 
00038 #include "Utilsexc.hh"
00039 
00040 // ==== CLASSES ====
00041 
00042 namespace RazorBack {
00043 
00048 class Symvar_
00049 {
00050     // data
00051     private:
00052             
00053     const string Separators;
00054     list<string> Toklist;
00055     list<string>::iterator Curtokptr;
00056     
00057     // methods
00058     public:
00059             
00067     explicit Symvar_(const string& Tokenstr="", const string& Seps="|, \t"):
00068             Separators(Seps), Toklist() { set_tokens(Tokenstr); }
00069     
00071     Symvar_(const Symvar_& Sv):
00072             Separators(Sv.Separators), Toklist(Sv.Toklist)
00073             { curtokptr_offset(Sv.curtokptr_offset()); }
00074     
00076     virtual ~Symvar_() {}
00077     
00079     Symvar_& operator=(const Symvar_& Rhs)
00080     {
00081         if (this!=&Rhs)
00082         {
00083             Toklist=Rhs.Toklist;
00084             curtokptr_offset(Rhs.curtokptr_offset());
00085         }
00086         return *this;
00087     }
00088     
00097     unsigned int set_tokens(const string& Tokenstr);
00098     
00100     void add_token(const string& Newtok) { Toklist.push_back(Newtok); }
00101     
00107     void remove_token(const string& Tok);
00108     
00109     // ---- Access ----
00110     
00112     const string& separators() { return Separators; }
00113     
00115     bool valid_token(const string& Tok) const
00116     {
00117         return (Toklist.end()!=find(Toklist.begin(),Toklist.end(), Tok));
00118     }
00119     
00121     bool empty() const { return Toklist.empty(); }
00122     
00127     const string& token() const
00128     {
00129         if (empty())
00130             throw Emptyexc_("Symvar_::token()");
00131         return *Curtokptr;
00132     }
00133     
00139     const string& token(const string& Tok);
00140     
00141     // ---- I/O ----
00142     
00148     friend istream& operator>>(istream& In, Symvar_& Sv);
00149     
00151     friend ostream& operator<<(ostream& Out, const Symvar_& Sv);
00152     
00158     string all_tokens() const;
00159     
00160     // hidden methods
00161     protected:
00162     
00163     unsigned int curtokptr_offset() const;
00164     void curtokptr_offset(unsigned int Offs);
00165 };
00166 // END OF CLASS Symvar_
00167 
00168 } // RazorBack
00169 
00170 // ==== END OF HEADER Symvar.hh ====
00171 
00172 #endif      // SYMVAR_HEADER

Generated at Wed Aug 21 09:33:40 2002 for The Razorback C++ Library: Miscellaneous by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001