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

Iovar.hh

Go to the documentation of this file.
00001 #ifndef IOVAR_TMPL_HEADER
00002 #define IOVAR_TMPL_HEADER
00003 
00004 // ==== TEMPLATE HEADER Iovar.hh ====
00005 
00012 // 28-Sep-2001, Andras Aszodi
00013 
00014 // ==== STANDARD HEADERS ====
00015 
00016 #include <stdlib.h>
00017 
00018 #ifdef _STANDARD_C_PLUS_PLUS
00019 #include <iostream>
00020 #else
00021 #include <iostream.h>
00022 #endif
00023 
00024 #include <string>
00025 using namespace std;
00026 #ifndef NPOS
00027 #define NPOS string::npos
00028 #endif
00029 
00030 // ==== MODULE HEADERS ====
00031 
00032 #include "Rangedimexc.hh"
00033 
00034 // ==== CLASSES ====
00035 
00036 namespace RazorBack {
00037 
00038 // silly predefs for friend templates
00039 template <class T_> class Iovar_;
00040 template <class T_>
00041 istream& operator>>(istream& In, Iovar_<T_>& Iov);
00042 template <class T_>
00043 ostream& operator<<(ostream& Out, const Iovar_<T_>& Iov);
00044 
00066 template <class T_>
00067 class Iovar_
00068 {
00069     // data
00070     private:
00071             
00072     string Descr;    //< description string
00073     bool Nocase;    //< true if description is case-insensitive
00074     char Eqchar;    //< the "equals" char, '\0' when not prescribed
00075     T_ Value;       //< the value of the variable
00076     
00077     // methods
00078     public:
00079             
00090     explicit Iovar_(const char *Dtok, T_ Defval=T_(0), bool Noc=false, char Eq='=');
00091     
00093     const string& descr() const { return Descr; }
00094     
00096     size_t dlen() const { return Descr.size(); }
00097     
00103     bool match_descr(const string& Str) const;
00104     
00109     bool nocase() const { return Nocase; }
00110     
00112     char eqchar() const { return Eqchar; }
00113     
00115     const T_& value() const { return Value; }
00116     
00118     T_ value(const T_& V) { T_ Ov=Value; Value=V; return Ov; }
00119     
00120     // Input: reads an Iov object from In accepting the formats
00121     // "Descr Value" or "Descr=Value" (where '=' is eqchar() and
00122     // it can be surrounded by >=0 whitespace chars on either side).
00123     // On error, no warnings are printed but In's failbit is set
00124     // and the stream is rewound to its original position.
00125     friend
00126     istream& operator>> <>(istream& In, Iovar_<T_>& Iov);
00127 
00128     // Output: uses the format "Descr Value" or "Descr = Value"
00129     // when Eqchar (here '=') is specified. No newline at the end.
00130     friend
00131     ostream& operator<< <>(ostream& Out, const Iovar_<T_>& Iov);
00132     
00133     // hidden methods
00134     protected:
00135             
00136     istream& read_value(istream& In);
00137     ostream& write_value(ostream& Out) const;
00138 };
00139 // END OF CLASS Iovar_
00140 
00141 #ifndef RAZORBACK_LIB_COMPILE
00142 // I/O for bool: the case-insensitive tokens "true","on","yes" are accepted
00143 // in addition to "1", and "false","off","no" in addition to 0.
00144 // The output strings are always lowercase "true" and "false".
00145 // The matches are case-independent.
00146 
00147 template<> istream& Iovar_<bool>::read_value(istream& In);
00148 template<> ostream& Iovar_<bool>::write_value(ostream& Out) const;
00149 #endif
00150 
00151 } // RazorBack
00152 
00153 #ifdef INCLUDE_TMPL_DEFS
00154 #include "Iovar.cc"
00155 #endif
00156 
00157 // ==== END OF TEMPLATE HEADER Iovar.hh ====
00158 
00159 #endif      // IOVAR_TMPL_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