Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

tristate.h

Go to the documentation of this file.
00001 
00007 #ifndef ___TRISTATE_H___
00008 #define ___TRISTATE_H___
00009 
00010 #include <fstream>
00011 #include <cassert>
00012 #include <string>
00013 using std::string;
00014 #include <strstream>
00015 
00016 
00022 enum Tristate {Uninitialized=-1,False=false,True=true};
00023 
00024 
00025 /* Double-check assumption */
00026 // check is not allowed under ISO C++
00027 //#if (false!=0)
00028 //#error 'false' must denote zero
00029 //#endif
00030 
00031 
00032 
00034 inline std::ostream& operator<<(std::ostream &s, const Tristate& t) {
00035   switch(t){
00036   case Uninitialized: return s << "Uninitialized";  
00037   case False:         return s << "False";          
00038   case True:          return s << "True";          
00039   default:            return s << int(t); // Unknown value
00040   }
00041 }
00042 
00043 
00045 inline std::istream& operator>>(std::istream &s, Tristate& t) {
00046   string r;
00047   s >> r;
00048   if      (r == "Uninitialized") t=Uninitialized;
00049   else if (r == "False")         t=False;
00050   else if (r == "True")          t=True;
00051   else {
00052     std::istrstream ss(r.c_str(),r.length());
00053     int x=0;
00054     ss >> x;
00055     t=Tristate(x);
00056   }
00057   
00058   return s;
00059 }
00060 
00061 #endif /* ___TRISTATE_H___ */

Generated on Mon Jan 20 02:35:45 2003 for RF-LISSOM by doxygen1.3-rc2