00001 00002 // 00003 // This file is part of the MADELINE 2 program 00004 // written by Edward H. Trager and Ritu Khanna 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.10.RK.ET 00024 // 00025 00026 #ifndef DATA_INCLUDED 00027 #define DATA_INCLUDED 00028 00029 #include <string> 00030 #include <set> 00031 #include <iostream> 00032 #include "DataTypes.h" 00033 00034 class DataMissingValueLoader; 00035 class Data { 00036 private: 00037 friend class DataMissingValueLoader; // initializes global missing values 00038 //static _locale; 00039 static bool _displayNumberSeparators; 00040 static bool _displayNativeDigitsInDates; 00041 static bool _displayNativeDigitsInNumbers; 00042 00043 00044 00045 protected: 00046 static std::set<std::string> _missingValue; // container that holds the global missing values 00047 00048 // Used to suppress warnings when the "isA()" methods in derived classes call "set()" methods 00049 // to test whether strings conform to patterns expected for that class: 00050 //static bool _suppressWarnings; 00051 00052 00053 00054 00055 public: 00056 00057 00058 Data() {} 00059 // 00060 // This must be declared virtual so that 00061 // the destructors of derived classes are called only, 00062 // --This base class destructor must *never* be called 00063 // 00064 virtual ~Data(){}; 00065 // Static methods 00066 static void addGlobalMissingValue(std::string value); 00067 static bool isGlobalMissingValue(std::string value); 00068 00069 // 00070 // NOTE BENE: this "trim" function operates on a reference 00071 // and modifies the original string. The trimmed string is 00072 // returned: 00073 // 00074 // Note also that the default drop string includes Unicode characters 00075 // for ZWSP,NBSP, EN SPACE, EM SPACE etc.: 00076 // 00077 static std::string & trim(std::string& s,const std::string &drop = " "); 00078 // Virtual methods: 00079 00080 // 00081 // We'll pretend that C++ allows virtual static methods: 00082 // 00083 //virtual static bool isA(const std::string&); 00084 // 00085 00086 virtual bool isMissing( void ) const =0; 00087 virtual void setMissing( void ) =0; 00088 00089 // Minimal Setters common to all derived classes: 00090 virtual void set(const std::string &)=0; 00091 virtual void set(const char *)=0; 00092 00093 // Get a display (string) version 00094 // of the data value: 00095 virtual const std::string get( void ) const =0; 00096 // Get the type of data value: 00097 virtual const DATATYPE getDataType( void ) const=0; 00098 // Virtual copy constructor 00099 virtual Data* clone() const = 0; 00100 // Virtual operators 00101 virtual bool operator==(const Data&) const =0; 00102 virtual bool operator<(const Data&) const =0; 00103 00104 }; 00105 00106 // 00107 // Friend class: initializes global missing values 00108 // 00109 class DataMissingValueLoader 00110 { 00111 00112 public: 00113 static DataMissingValueLoader dataMissingValueLoader; 00114 DataMissingValueLoader(){ 00115 Data::_missingValue.insert("."); 00116 } 00117 00118 }; 00119 00120 #endif 00121 00122