kexi
tristate.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _TRISTATE_TYPE_H_
00021 #define _TRISTATE_TYPE_H_
00022
00039 static const char cancelled = 2;
00040
00044 static const char dontKnow = cancelled;
00045
00097 class tristate
00098 {
00099 public:
00103 tristate()
00104 : m_value(Cancelled)
00105 {
00106 }
00107
00111 tristate(bool boolValue)
00112 : m_value(boolValue ? True : False)
00113 {
00114 }
00115
00123 tristate(char c)
00124 : m_value(c==cancelled ? tristate::Cancelled : (c==1 ? True : False))
00125 {
00126 }
00127
00134 tristate(int intValue)
00135 : m_value(intValue==(int)cancelled ? tristate::Cancelled : (intValue==1 ? True : False))
00136 {
00137 }
00138
00143 operator bool() const { return m_value==True; }
00144
00149 bool operator!() const { return m_value==False; }
00150
00155 bool operator~() const { return m_value==Cancelled; }
00156
00157 tristate& operator=(const tristate& tsValue) { m_value = tsValue.m_value; return *this; }
00158
00159 friend inline bool operator!=(bool boolValue, tristate tsValue);
00160 friend inline bool operator!=(tristate tsValue, bool boolValue);
00161
00162 private:
00167 enum Value {
00168 False = 0,
00169 True = 1,
00170 Cancelled = 2
00171 };
00172
00176 Value m_value;
00177 };
00178
00186 inline bool operator!=(bool boolValue, tristate tsValue)
00187 {
00188 return !( (tsValue.m_value==tristate::True && boolValue)
00189 || (tsValue.m_value==tristate::False && !boolValue) );
00190 }
00191
00196 inline bool operator!=(tristate tsValue, bool boolValue)
00197 {
00198 return !( (tsValue.m_value==tristate::True && boolValue)
00199 || (tsValue.m_value==tristate::False && !boolValue) );
00200 }
00201
00202 #endif
|