Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

Boolean.h

Go to the documentation of this file.
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 // Last updated 2011.11.18.ET
00026 //
00027 
00028 //
00029 // Boolean.h
00030 //
00031 #ifndef Boolean_INCLUDED
00032 #define Boolean_INCLUDED
00033 
00034 #include <string>
00035 #include <iostream>
00036 #include <map>
00037 #include "Data.h"
00038 
00039 class BooleanMapLoader;
00041 
00043 class Boolean : public Data
00044 {
00045 private:
00046         
00047         friend class BooleanMapLoader;
00048         static std::map<std::string, bool> _lookupTable;
00049         
00050 protected:
00051         
00052         bool _value;
00053         bool _isMissing;
00054         
00055 public:
00056         
00057         //
00058         // Constructors:
00059         //
00060         Boolean(){ _isMissing=true; }
00061         Boolean(const char *value){ set(value); }
00062         Boolean(const std::string &value){ set( value.c_str() ); }
00063         
00064         //
00065         //  Methods required by Variable virtual base class:
00066         //
00067         virtual bool isMissing( void ) const { return _isMissing; }
00068         virtual void setMissing( void ){ _isMissing=true;}
00069         virtual void set( const char *value );
00070         virtual void set( const std::string &value);
00071         virtual const std::string get( void ) const { if(isMissing()) return "."; if(_value) return "T"; else return "F";}
00072         char getAsChar(void) const {if(isMissing()) return '.'; if(_value) return 'T'; else return 'F';}
00073         
00074         static void addLookupTableEntry(std::string label, bool value);
00075         //
00076         // Additional Setters/Getters not present in virtual base class:
00077         //
00078         virtual void set(const bool value) { _value=value; _isMissing = false; }
00079         virtual const bool getBoolean( void ) const { if(_isMissing) return false; return _value; }
00080         
00081         bool operator==(const Data& b) const;
00082         bool operator<(const Data& b) const;
00083         virtual Boolean* clone() const;
00084         const DATATYPE getDataType( void ) const { return BOOLEAN; }
00085         
00086 };
00087 
00088 std::ostream& operator<<(std::ostream& s,const Boolean& g);
00089 //
00090 // Boolean Friend class that initializes the lookup table:
00091 //
00092 class BooleanMapLoader
00093 {
00094 public:
00095         static BooleanMapLoader booleanMapLoader;
00096         BooleanMapLoader(){
00097                 Boolean::_lookupTable["f"] = false;
00098                 Boolean::_lookupTable["t"] = true;
00099                 Boolean::_lookupTable["F"] = false;
00100                 Boolean::_lookupTable["T"] = true;
00101                 Boolean::_lookupTable["false"] = false;
00102                 Boolean::_lookupTable["true" ] = true;
00103                 Boolean::_lookupTable["False"] = false;
00104                 Boolean::_lookupTable["True" ] = true;
00105                 Boolean::_lookupTable["FALSE"] = false;
00106                 Boolean::_lookupTable["TRUE" ] = true;
00107                 Boolean::_lookupTable["假"] = false;
00108                 Boolean::_lookupTable["真"] = true;
00109         }
00110 };
00111 
00112 #endif

Generated on Fri Nov 18 16:24:39 2011 for MADELINE by  doxygen 1.4.4