Jpp 21.0.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
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
8
9
10/**
11 * \author mdejong
12 */
13
14namespace JLANG {}
15namespace JPP { using namespace JLANG; }
16
17namespace JLANG {
18
19
20 /**
21 * Get undefined object identifier.
22 *
23 * \return undefined object identifier
24 */
26 {
27 return -1;
28 }
29
30
31 /**
32 * Auxiliary base class for object identification.
33 */
34 template<class T>
35 class JObjectID :
36 public JComparable<JObjectID<T> >,
37 public JComparable<JObjectID<T>, int>
38 {
39 public:
40 /**
41 * Default constructor.
42 */
44 _id_(getUndefinedObjectID())
45 {}
46
47
48 /**
49 * Constructor.
50 *
51 * \param id identifier
52 */
53 JObjectID(const int id) :
54 _id_(id)
55 {}
56
57
58 /**
59 * Get identifier.
60 *
61 * \return identifier
62 */
63 int getID() const
64 {
65 return _id_;
66 }
67
68
69 /**
70 * Get identifier.
71 *
72 * \return identifier
73 */
74 int& getID()
75 {
76 return _id_;
77 }
78
79
80 /**
81 * Set identifier.
82 *
83 * \param id identifier
84 */
85 void setID(const int id)
86 {
87 this->_id_ = id;
88 }
89
90
91 /**
92 * Less than method.
93 *
94 * \param object object identifier
95 * \return true if this identifier less than given identifier; else false
96 */
97 inline bool less(const JObjectID& object) const
98 {
99 return this->getID() < object.getID();
100 }
101
102
103 /**
104 * Less than method.
105 *
106 * \param id identifier
107 * \return true if this identifier less than given identifier; else false
108 */
109 inline bool less(const int id) const
110 {
111 return this->getID() < id;
112 }
113
114
115 /**
116 * More than method.
117 *
118 * \param id identifier
119 * \return true if this identifier greater than given identifier; else false
120 */
121 inline bool more(const int id) const
122 {
123 return this->getID() > id;
124 }
125
126
127 /**
128 * Read object identifier from input.
129 *
130 * \param in input stream
131 * \param object object identifier
132 * \return input stream
133 */
134 friend inline std::istream& operator>>(std::istream& in, JObjectID& object)
135 {
136 return in >> object._id_;
137 }
138
139
140 /**
141 * Write object identifier to output.
142 *
143 * \param out output stream
144 * \param object object identifier
145 * \return output stream
146 */
147 friend inline std::ostream& operator<<(std::ostream& out, const JObjectID& object)
148 {
149 return out << object._id_;
150 }
151
152 protected:
153 int _id_;
154 };
155}
156
157#endif
Auxiliary base class for object identification.
Definition JObjectID.hh:38
int getID() const
Get identifier.
Definition JObjectID.hh:63
JObjectID(const int id)
Constructor.
Definition JObjectID.hh:53
bool less(const int id) const
Less than method.
Definition JObjectID.hh:109
int & getID()
Get identifier.
Definition JObjectID.hh:74
bool less(const JObjectID &object) const
Less than method.
Definition JObjectID.hh:97
bool more(const int id) const
More than method.
Definition JObjectID.hh:121
friend std::istream & operator>>(std::istream &in, JObjectID &object)
Read object identifier from input.
Definition JObjectID.hh:134
JObjectID()
Default constructor.
Definition JObjectID.hh:43
void setID(const int id)
Set identifier.
Definition JObjectID.hh:85
friend std::ostream & operator<<(std::ostream &out, const JObjectID &object)
Write object identifier to output.
Definition JObjectID.hh:147
Auxiliary classes and methods for language specific functionality.
int getUndefinedObjectID()
Get undefined object identifier.
Definition JObjectID.hh:25
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Template definition of auxiliary base class for comparison of data structures.