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 bool operator!() const { return m_value==False; }
00144
00149 bool operator~() const { return m_value==Cancelled; }
00150
00151 tristate& operator=(const tristate& tsValue) { m_value = tsValue.m_value; return *this; }
00152
00153 friend inline bool operator==(bool boolValue, tristate tsValue);
00154
00155 friend inline bool operator==(tristate tsValue, bool boolValue);
00156
00157 friend inline bool operator!=(bool boolValue, tristate tsValue);
00158
00159 friend inline bool operator!=(tristate tsValue, bool boolValue);
00160
00164 QString toString() const {
00165 if (m_value==False)
00166 return QString::fromLatin1("false");
00167 return m_value==True ? QString::fromLatin1("true") : QString::fromLatin1("cancelled");
00168 }
00169
00170 private:
00175 enum Value {
00176 False = 0,
00177 True = 1,
00178 Cancelled = 2
00179 };
00180
00184 Value m_value;
00185 };
00186
00194 inline bool operator!=(bool boolValue, tristate tsValue)
00195 {
00196 return !( (tsValue.m_value==tristate::True && boolValue)
00197 || (tsValue.m_value==tristate::False && !boolValue) );
00198 }
00199
00204 inline bool operator!=(tristate tsValue, bool boolValue)
00205 {
00206 return !( (tsValue.m_value==tristate::True && boolValue)
00207 || (tsValue.m_value==tristate::False && !boolValue) );
00208 }
00209
00217 inline bool operator==(tristate tsValue, bool boolValue)
00218 {
00219 return (tsValue.m_value==tristate::True && boolValue)
00220 || (tsValue.m_value==tristate::False && !boolValue);
00221 }
00222
00230 inline bool operator==(bool boolValue, tristate tsValue)
00231 {
00232 return (tsValue.m_value==tristate::True && boolValue)
00233 || (tsValue.m_value==tristate::False && !boolValue);
00234 }
00235
00236 #endif
|