Diana Software
QBaseType.hh
Go to the documentation of this file.
1 #ifndef _Q_BASETYPE_HH_
2 #define _Q_BASETYPE_HH_
3 
13 #include "QObject.hh"
14 
16 
17 template<class T> class QBaseType : public QObject {
18 
19  public:
21  void Clear();
22 
24  QBaseType() { Clear(); }
25 
28  {
29  this->operator=(bt);
30  }
31 
33  QBaseType(const T& value)
34  {
35  this->operator=(value);
36  }
37 
39  QBaseType<T>& operator=(const T& value)
40  {
41  fValue = value;
42  Validate();
43  return *this;
44  }
45 
47  bool operator==(const T& value) const
48  {
49  return fValue == value;
50  }
52  bool operator!=(const T& value) const
53  {
54  return fValue != value;
55  }
56 
58  bool operator<(const T& value) const
59  {
60  return fValue < value;
61  }
62 
64  bool operator<=(const T& value) const
65  {
66  return fValue <= value;
67  }
68 
70  bool operator>=(const T& value) const
71  {
72  return fValue >= value;
73  }
74 
76  bool operator>(const T& value) const
77  {
78  return fValue > value;
79  }
80 
82  QBaseType<T>& operator+=(const T& value)
83  {
84  this->operator=(fValue+value);
85  return *this;
86  }
87 
89  QBaseType<T>& operator-=(const T& value)
90  {
91  this->operator=(fValue-value);
92  return *this;
93  }
94 
96  QBaseType<T>& operator*=(const T& value)
97  {
98  this->operator=(fValue*value);
99  return *this;
100  }
101 
103  QBaseType<T>& operator/=(const T& value)
104  {
105  this->operator=(fValue/value);
106  return *this;
107  }
108 
118  operator T () const { return fValue; }
119 
121  void Dump(std::ostream& ob) const { ob<<fValue; }
122 
124  bool Fill(Diana::QObject* obj) const
125  {
126  QBaseType<T>* bt = dynamic_cast<QBaseType<T>* >(obj);
127  if(bt) {
128  *bt = *this;
129  }
130  return bt != NULL;
131  }
132 
134  QObject* Duplicate() const {
135  QBaseType<T> * obj = new QBaseType<T>;
136  return obj;
137  }
138 
139  private:
144 
145 };
146 
147 
148 template <class T> void QBaseType<T>::Clear() {};
149 
150 template <> inline void QBaseType<int>::Clear()
151 {
152  fValue = Q_INT_DEFAULT;
153 }
154 template <> inline void QBaseType<float>::Clear()
155 {
156  fValue = Q_FLOAT_DEFAULT;
157 }
158 
159 template <> inline void QBaseType<double>::Clear()
160 {
161  fValue = Q_DOUBLE_DEFAULT;
162 }
163 
164 template <> inline void QBaseType<Long64_t>::Clear()
165 {
166  fValue = Q_INT_DEFAULT;
167 }
168 
169 
190 
197 
199 
200 /* the cast operator replaces them, however cint seems not able to call it
201  * so we should do a manual cast
202 template<class T> bool operator>(const T& b,const Diana::QBaseType<T> & qb)
203 {
204  return qb < b;
205 }
206 
207 template<class T> bool operator<(const T& b,const Diana::QBaseType<T> & qb)
208 {
209  return qb > b;
210 }
211 
212 template<class T> bool operator==(const T& b,const Diana::QBaseType<T> & qb)
213 {
214  return qb == b;
215 }
216 */
217 
218 #endif
QBaseType< double > QDouble
double wrapped in a QObject
Definition: QBaseType.hh:184
QBaseType< int > QInt
int wrapped in a QObject
Definition: QBaseType.hh:174
QBaseType< float > QFloat
float wrapped in a QObject
Definition: QBaseType.hh:179
QBaseType< Long64_t > QLong64
double wrapped in a QObject
Definition: QBaseType.hh:189
QBaseType< ULong64_t > QULong64
unsigned long wrapped in a QObject
Definition: QBaseType.hh:196
#define Q_DOUBLE_DEFAULT
Definition: QDiana.hh:24
#define Q_END_NAMESPACE
Definition: QDiana.hh:22
#define Q_BEGIN_NAMESPACE
Definition: QDiana.hh:20
#define Q_FLOAT_DEFAULT
Definition: QDiana.hh:32
#define Q_INT_DEFAULT
Definition: QDiana.hh:26
base types wrapped into a QObject. Currently implemented types are QInt QDouble and QFloat....
Definition: QBaseType.hh:17
QBaseType< T > & operator*=(const T &value)
operator*=
Definition: QBaseType.hh:96
void Clear()
clear members
Definition: QBaseType.hh:148
ClassDef(QBaseType, 2)
This is the only QObject where we do not use QObjectDef, because of templates.
QBaseType()
constructor
Definition: QBaseType.hh:24
QBaseType< T > & operator/=(const T &value)
operator/=
Definition: QBaseType.hh:103
bool operator>(const T &value) const
greater operator
Definition: QBaseType.hh:76
QBaseType(const QBaseType< T > &bt)
copy constructor
Definition: QBaseType.hh:27
bool operator<(const T &value) const
less operator
Definition: QBaseType.hh:58
QBaseType< T > & operator-=(const T &value)
operator-=
Definition: QBaseType.hh:89
bool operator==(const T &value) const
comparison operator
Definition: QBaseType.hh:47
bool operator!=(const T &value) const
difference operator
Definition: QBaseType.hh:52
QBaseType(const T &value)
copy constructor from base type
Definition: QBaseType.hh:33
bool operator>=(const T &value) const
greater equal operator
Definition: QBaseType.hh:70
QObject * Duplicate() const
create object of same type
Definition: QBaseType.hh:134
QBaseType< T > & operator+=(const T &value)
operator+=
Definition: QBaseType.hh:82
bool operator<=(const T &value) const
less equal operator
Definition: QBaseType.hh:64
bool Fill(Diana::QObject *obj) const
fill object of same type (like operator=)
Definition: QBaseType.hh:124
T fValue
the base type
Definition: QBaseType.hh:141
QBaseType< T > & operator=(const T &value)
operator= to base type
Definition: QBaseType.hh:39
void Dump(std::ostream &ob) const
dump value to stream
Definition: QBaseType.hh:121
base class for objects handled by QEvent and QGlobalDataManager.
Definition: QObject.hh:76
void Validate()
make object valid
Definition: QObject.hh:108