Jpp  master_rocky
the software that should make you happy
JStatic.hh
Go to the documentation of this file.
1 #ifndef __JLANG_JSTATIC__
2 #define __JLANG_JSTATIC__
3 
4 #include <istream>
5 #include <ostream>
6 
7 #include "JLang/JClass.hh"
8 #include "JLang/JEquals.hh"
9 
10 
11 namespace JLANG {}
12 namespace JPP { using namespace JLANG; }
13 
14 namespace JLANG {
15 
16  /**
17  * Template data structure for static member declaration.
18  */
19  template<class T, int N>
20  struct JStatic :
21  public JEquals<JStatic<T, N>, T>
22  {
23 
25 
26 
27  /**
28  * Constructor.
29  *
30  * \param value value
31  */
33  {
34  this->value = value;
35  }
36 
37 
38  /**
39  * Assignment operator
40  *
41  * \param value value
42  * \return this value
43  */
45  {
46  this->value = value;
47 
48  return *this;
49  }
50 
51 
52  /**
53  * Type conversion operator.
54  *
55  * \return value
56  */
57  operator const T& () const
58  {
59  return value;
60  }
61 
62 
63  /**
64  * Type conversion operator.
65  *
66  * \return value
67  */
68  operator T& ()
69  {
70  return value;
71  }
72 
73 
74  /**
75  * Smart pointer.
76  *
77  * \return value
78  */
79  const T* operator->() const
80  {
81  return &value;
82  }
83 
84 
85  /**
86  * Smart pointer.
87  *
88  * \return value
89  */
91  {
92  return &value;
93  }
94 
95 
96  /**
97  * Equals method.
98  *
99  * \param object object
100  * \return true if this object equals given object; else false
101  */
102  bool equals(const JStatic& object) const
103  {
104  return this->value == object.value;
105  }
106 
107 
108  /**
109  * Equals method.
110  *
111  * \param value value
112  * \return true if this value equals given value; else false
113  */
114  bool equals(argument_type value) const
115  {
116  return this->value == value;
117  }
118 
119 
120  /**
121  * Read static object from input stream.
122  *
123  * \param in input stream
124  * \param object object
125  * \return input stream
126  */
127  friend inline std::istream& operator>>(std::istream& in, JStatic& object)
128  {
129  return in >> object.value;
130  }
131 
132 
133  /**
134  * Write static object to output stream.
135  *
136  * \param out output stream
137  * \param object object
138  * \return output stream
139  */
140  friend inline std::ostream& operator<<(std::ostream& out, const JStatic& object)
141  {
142  return out << object.value;
143  }
144 
145  protected:
146  static T value;
147  };
148 
149 
150  /**
151  * Declaration of static data member.
152  */
153  template<class T, int N>
155 
156 
157  /**
158  * Template specialisation of JStatic for static member declaration of pointer.
159  */
160  template<class T, int N>
161  struct JStatic<T*, N> :
162  public JEquals<JStatic<T*, N>, T*>
163  {
164 
166 
167  /**
168  * Assignment operator
169  *
170  * \param value value
171  * \return this value
172  */
174  {
175  this->value = value;
176 
177  return *this;
178  }
179 
180 
181  /**
182  * Smart pointer.
183  *
184  * \return value
185  */
186  const T* operator->() const
187  {
188  return value;
189  }
190 
191 
192  /**
193  * Smart pointer.
194  *
195  * \return value
196  */
198  {
199  return value;
200  }
201 
202 
203  /**
204  * Equals method.
205  *
206  * \param object object
207  * \return true if this object equals given object; else false
208  */
209  bool equals(const JStatic& object) const
210  {
211  return this->value == object.value;
212  }
213 
214 
215  /**
216  * Equals method.
217  *
218  * \param value value
219  * \return true if this value equals given value; else false
220  */
221  bool equals(argument_type value) const
222  {
223  return this->value == value;
224  }
225 
226  protected:
227  static T* value;
228  };
229 
230 
231  /**
232  * Declaration of static data member.
233  */
234  template<class T, int N>
236 }
237 
238 /**
239  * Static data member declaration.
240  *
241  * \param TYPE data type
242  */
243 #define STATIC_DATA_MEMBER(TYPE) static JLANG::JStatic<TYPE, __COUNTER__>
244 
245 #endif
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JArgument< T >::argument_type argument_type
Definition: JClass.hh:82
Template definition of auxiliary base class for comparison of data structures.
Definition: JEquals.hh:84
JStatic & operator=(argument_type value)
Assignment operator.
Definition: JStatic.hh:173
const T * operator->() const
Smart pointer.
Definition: JStatic.hh:186
bool equals(argument_type value) const
Equals method.
Definition: JStatic.hh:221
JClass< T * >::argument_type argument_type
Definition: JStatic.hh:165
static T * value
Declaration of static data member.
Definition: JStatic.hh:227
bool equals(const JStatic &object) const
Equals method.
Definition: JStatic.hh:209
T * operator->()
Smart pointer.
Definition: JStatic.hh:197
Template data structure for static member declaration.
Definition: JStatic.hh:22
friend std::ostream & operator<<(std::ostream &out, const JStatic &object)
Write static object to output stream.
Definition: JStatic.hh:140
static T value
Declaration of static data member.
Definition: JStatic.hh:146
JStatic & operator=(argument_type value)
Assignment operator.
Definition: JStatic.hh:44
const T * operator->() const
Smart pointer.
Definition: JStatic.hh:79
bool equals(argument_type value) const
Equals method.
Definition: JStatic.hh:114
JClass< T >::argument_type argument_type
Definition: JStatic.hh:24
JStatic(argument_type value)
Constructor.
Definition: JStatic.hh:32
friend std::istream & operator>>(std::istream &in, JStatic &object)
Read static object from input stream.
Definition: JStatic.hh:127
T * operator->()
Smart pointer.
Definition: JStatic.hh:90
bool equals(const JStatic &object) const
Equals method.
Definition: JStatic.hh:102