00001 00002 // 00003 // This file is part of the MADELINE 2 program 00004 // written by Edward H. Trager, Ritu Khanna and Adrian Marrs 00005 // Copyright (c) 2005 by the 00006 // Regents of the University of Michigan. 00007 // All Rights Reserved. 00008 // 00009 // The latest version of this program is available from: 00010 // 00011 // http://eyegene.ophthy.med.umich.edu/madeline/ 00012 // 00013 // Released under the GNU General Public License. 00014 // A copy of the GPL is included in the distribution 00015 // package of this software, or see: 00016 // 00017 // http://www.gnu.org/copyleft/ 00018 // 00019 // ... for licensing details. 00020 // 00022 // 00023 // 2005.03.07.ET.RK 00024 // 00025 00026 // 00027 // Boolean.h 00028 // 00029 #ifndef Boolean_INCLUDED 00030 #define Boolean_INCLUDED 00031 00032 #include <string> 00033 #include <iostream> 00034 #include <map> 00035 #include "Data.h" 00036 00037 class BooleanMapLoader; 00039 00041 class Boolean : public Data 00042 { 00043 private: 00044 00045 friend class BooleanMapLoader; 00046 static std::map<std::string, bool> _lookupTable; 00047 00048 protected: 00049 00050 bool _value; 00051 bool _isMissing; 00052 00053 public: 00054 00055 // 00056 // Constructors: 00057 // 00058 Boolean(){ _isMissing=true; } 00059 Boolean(const char *value){ set(value); } 00060 Boolean(const std::string &value){ set( value.c_str() ); } 00061 00062 // 00063 // Methods required by Variable virtual base class: 00064 // 00065 virtual bool isMissing( void ) const { return _isMissing; } 00066 virtual void setMissing( void ){ _isMissing=true;} 00067 virtual void set( const char *value ); 00068 virtual void set( const std::string &value); 00069 virtual const std::string get( void ) const { if(isMissing()) return "."; if(_value) return "T"; else return "F";} 00070 char getAsChar(void) const {if(isMissing()) return '.'; if(_value) return 'T'; else return 'F';} 00071 00072 static void addLookupTableEntry(std::string label, bool value); 00073 // 00074 // Additional Setters/Getters not present in virtual base class: 00075 // 00076 virtual void set(const bool value) { _value=value; _isMissing = false; } 00077 virtual const bool getBoolean( void ) const { if(_isMissing) return false; return _value; } 00078 00079 bool operator==(const Data& b) const; 00080 bool operator<(const Data& b) const; 00081 virtual Boolean* clone() const; 00082 const DATATYPE getDataType( void ) const { return BOOLEAN; } 00083 00084 }; 00085 00086 std::ostream& operator<<(std::ostream& s,const Boolean& g); 00087 // 00088 // Boolean Friend class that initializes the lookup table: 00089 // 00090 class BooleanMapLoader 00091 { 00092 public: 00093 static BooleanMapLoader booleanMapLoader; 00094 BooleanMapLoader(){ 00095 Boolean::_lookupTable["f"] = false; 00096 Boolean::_lookupTable["t"] = true; 00097 Boolean::_lookupTable["F"] = false; 00098 Boolean::_lookupTable["T"] = true; 00099 Boolean::_lookupTable["假"] = false; 00100 Boolean::_lookupTable["真"] = true; 00101 } 00102 }; 00103 00104 #endif
1.4.4