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, int>
29  {
30  public:
31  /**
32  * Default constructor.
33  */
35  __id(-1)
36  {}
37 
38 
39  /**
40  * Constructor.
41  *
42  * \param id identifier
43  */
44  JObjectID(const int id) :
45  __id(id)
46  {}
47 
48 
49  /**
50  * Get identifier.
51  *
52  * \return identifier
53  */
54  int getID() const
55  {
56  return __id;
57  }
58 
59 
60  /**
61  * Set identifier.
62  *
63  * \param id identifier
64  */
65  void setID(const int id)
66  {
67  this->__id = id;
68  }
69 
70 
71  /**
72  * Less than method.
73  *
74  * \param object object identifier
75  * \return true if this identifier less than given identifier; else false
76  */
77  inline bool less(const JObjectID& object) const
78  {
79  return this->getID() < object.getID();
80  }
81 
82 
83  /**
84  * Less than method.
85  *
86  * \param id identifier
87  * \return true if this identifier less than given identifier; else false
88  */
89  inline bool less(const int id) const
90  {
91  return this->getID() < id;
92  }
93 
94 
95  /**
96  * More than method.
97  *
98  * \param id identifier
99  * \return true if this identifier greater than given identifier; else false
100  */
101  inline bool more(const int id) const
102  {
103  return this->getID() > id;
104  }
105 
106 
107  /**
108  * Read object identifier from input.
109  *
110  * \param in input stream
111  * \param object object identifier
112  * \return input stream
113  */
114  friend inline std::istream& operator>>(std::istream& in, JObjectID& object)
115  {
116  return in >> object.__id;
117  }
118 
119 
120  /**
121  * Write object identifier to output.
122  *
123  * \param out output stream
124  * \param object object identifier
125  * \return output stream
126  */
127  friend inline std::ostream& operator<<(std::ostream& out, const JObjectID& object)
128  {
129  return out << object.__id;
130  }
131 
132 
133  /**
134  * Read object identifier from input.
135  *
136  * \param in reader
137  * \param object object identifier
138  * \return reader
139  */
140  friend inline JReader& operator>>(JReader& in, JObjectID& object)
141  {
142  return in >> object.__id;
143  }
144 
145 
146  /**
147  * Write object identifier to output.
148  *
149  * \param out writer
150  * \param object object identifier
151  * \return writer
152  */
153  friend inline JWriter& operator<<(JWriter& out, const JObjectID& object)
154  {
155  return out << object.__id;
156  }
157 
158  protected:
159  int __id;
160  };
161 
162 
163  /**
164  * Get undefined object identifier.
165  *
166  * \return undefined object identifier
167  */
169  {
170  static JObjectID id;
171 
172  return id;
173  }
174 }
175 
176 #endif
Interface for binary output.
JObjectID(const int id)
Constructor.
Definition: JObjectID.hh:44
JObjectID()
Default constructor.
Definition: JObjectID.hh:34
int getID() const
Get identifier.
Definition: JObjectID.hh:54
bool more(const int id) const
More than method.
Definition: JObjectID.hh:101
bool less(const JObjectID &object) const
Less than method.
Definition: JObjectID.hh:77
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:114
friend JReader & operator>>(JReader &in, JObjectID &object)
Read object identifier from input.
Definition: JObjectID.hh:140
Auxiliary class for object identification.
Definition: JObjectID.hh:27
void setID(const int id)
Set identifier.
Definition: JObjectID.hh:65
const JObjectID & getUndefinedObjectID()
Get undefined object identifier.
Definition: JObjectID.hh:168
friend std::ostream & operator<<(std::ostream &out, const JObjectID &object)
Write object identifier to output.
Definition: JObjectID.hh:127
bool less(const int id) const
Less than method.
Definition: JObjectID.hh:89
friend JWriter & operator<<(JWriter &out, const JObjectID &object)
Write object identifier to output.
Definition: JObjectID.hh:153