Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JObjectID.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JOBJECTID__
2 #define __JLANG__JOBJECTID__
3 
4 #include <istream>
5 #include <ostream>
6 
7 #include "JIO/JSerialisable.hh"
8 #include "JLang/JComparable.hh"
9 
10 
11 /**
12  * \author mdejong
13  */
14 
15 namespace JLANG {}
16 namespace JPP { using namespace JLANG; }
17 
18 namespace JLANG {
19 
20  using JIO::JReader;
21  using JIO::JWriter;
22 
23 
24  /**
25  * Auxiliary class for object identification.
26  */
27  class JObjectID :
28  public JComparable<JObjectID>,
29  public JComparable<JObjectID, int>
30  {
31  public:
32  /**
33  * Default constructor.
34  */
36  __id(-1)
37  {}
38 
39 
40  /**
41  * Constructor.
42  *
43  * \param id identifier
44  */
45  JObjectID(const int id) :
46  __id(id)
47  {}
48 
49 
50  /**
51  * Get identifier.
52  *
53  * \return identifier
54  */
55  int getID() const
56  {
57  return __id;
58  }
59 
60 
61  /**
62  * Set identifier.
63  *
64  * \param id identifier
65  */
66  void setID(const int id)
67  {
68  this->__id = id;
69  }
70 
71 
72  /**
73  * Less than method.
74  *
75  * \param object object identifier
76  * \return true if this identifier less than given identifier; else false
77  */
78  inline bool less(const JObjectID& object) const
79  {
80  return this->getID() < object.getID();
81  }
82 
83 
84  /**
85  * Less than method.
86  *
87  * \param id identifier
88  * \return true if this identifier less than given identifier; else false
89  */
90  inline bool less(const int id) const
91  {
92  return this->getID() < id;
93  }
94 
95 
96  /**
97  * More than method.
98  *
99  * \param id identifier
100  * \return true if this identifier greater than given identifier; else false
101  */
102  inline bool more(const int id) const
103  {
104  return this->getID() > id;
105  }
106 
107 
108  /**
109  * Read object identifier from input.
110  *
111  * \param in input stream
112  * \param object object identifier
113  * \return input stream
114  */
115  friend inline std::istream& operator>>(std::istream& in, JObjectID& object)
116  {
117  return in >> object.__id;
118  }
119 
120 
121  /**
122  * Write object identifier to output.
123  *
124  * \param out output stream
125  * \param object object identifier
126  * \return output stream
127  */
128  friend inline std::ostream& operator<<(std::ostream& out, const JObjectID& object)
129  {
130  return out << object.__id;
131  }
132 
133 
134  /**
135  * Read object identifier from input.
136  *
137  * \param in reader
138  * \param object object identifier
139  * \return reader
140  */
141  friend inline JReader& operator>>(JReader& in, JObjectID& object)
142  {
143  return in >> object.__id;
144  }
145 
146 
147  /**
148  * Write object identifier to output.
149  *
150  * \param out writer
151  * \param object object identifier
152  * \return writer
153  */
154  friend inline JWriter& operator<<(JWriter& out, const JObjectID& object)
155  {
156  return out << object.__id;
157  }
158 
159  protected:
160  int __id;
161  };
162 
163 
164  /**
165  * Get undefined object identifier.
166  *
167  * \return undefined object identifier
168  */
170  {
171  static JObjectID id;
172 
173  return id;
174  }
175 }
176 
177 #endif
Interface for binary output.
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
JObjectID(const int id)
Constructor.
Definition: JObjectID.hh:45
JObjectID()
Default constructor.
Definition: JObjectID.hh:35
int getID() const
Get identifier.
Definition: JObjectID.hh:55
bool more(const int id) const
More than method.
Definition: JObjectID.hh:102
bool less(const JObjectID &object) const
Less than method.
Definition: JObjectID.hh:78
Interface for binary input.
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:24
friend std::istream & operator>>(std::istream &in, JObjectID &object)
Read object identifier from input.
Definition: JObjectID.hh:115
friend JReader & operator>>(JReader &in, JObjectID &object)
Read object identifier from input.
Definition: JObjectID.hh:141
Auxiliary class for object identification.
Definition: JObjectID.hh:27
void setID(const int id)
Set identifier.
Definition: JObjectID.hh:66
const JObjectID & getUndefinedObjectID()
Get undefined object identifier.
Definition: JObjectID.hh:169
friend std::ostream & operator<<(std::ostream &out, const JObjectID &object)
Write object identifier to output.
Definition: JObjectID.hh:128
bool less(const int id) const
Less than method.
Definition: JObjectID.hh:90
friend JWriter & operator<<(JWriter &out, const JObjectID &object)
Write object identifier to output.
Definition: JObjectID.hh:154