Bayeux  3.4.1
Core Foundation library for SuperNEMO
geom_id.h
Go to the documentation of this file.
1 /* Author (s): Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date: 2010-02-08
4  * Last modified: 2013-05-30
5  *
6  * License:
7  *
8  * Description:
9  *
10  * Geometry ID
11  *
12  * A geometry ID is composed of two parts:
13  * - the 'type' is an integer representing the category of geometry object
14  * each type object in a geometry setup has an unique category, thus a unique TYPE integer
15  * - the 'address' is a list of integers representing the path to the object located in
16  * the hierarchy tree of the setup.
17  *
18  * History:
19  *
20  */
21 
22 #ifndef GEOMTOOLS_GEOM_ID_H
23 #define GEOMTOOLS_GEOM_ID_H 1
24 
25 // Standard library:
26 #include <iostream>
27 #include <vector>
28 
29 // Third party:
30 // - Boost:
31 #include <boost/cstdint.hpp>
32 // - Bayeux/datatools :
35 
36 // This project :
38 
39 namespace geomtools {
40 
42  {
43  public:
44 
45  static const uint32_t INVALID_TYPE = 0xFFFFFFFF;
46  static const uint32_t INVALID_ADDRESS = 0xFFFFFFFF;
47  static const uint32_t ANY_ADDRESS = 0xFFFFFFFE;
48  static const uint32_t DEFAULT_ADDRESS_DEPTH = 10;
49  static const uint32_t UNIVERSE_TYPE = 0;
50  static const uint32_t WORLD_TYPE = geom_id::UNIVERSE_TYPE;
51 
52  static const char IO_ID_OPEN;
53  static const char IO_ID_SEPARATOR;
54  static const char IO_ADDRESS_SEPARATOR;
55  static const char IO_TYPE_INVALID;
56  static const char IO_ADDRESS_INVALID;
57  static const char IO_ID_CLOSE;
58  static const char IO_ADDRESS_ANY;
59 
61  bool is_type (uint32_t) const;
62 
64  uint32_t get_type () const;
65 
67  void set_type (uint32_t);
68 
70  void set_depth (uint32_t depth_);
71 
73  uint32_t get_depth () const;
74 
76  uint32_t get (int) const;
77 
79  void set (int, uint32_t val_);
80 
82  void set_any (int);
83 
85  void set_invalid (int);
86 
88  bool is_invalid (int) const;
89 
91  bool is_any (int) const;
92 
94  void set_address (uint32_t si0_,
95  uint32_t si1_ = INVALID_ADDRESS,
96  uint32_t si2_ = INVALID_ADDRESS,
97  uint32_t si3_ = INVALID_ADDRESS,
98  uint32_t si4_ = INVALID_ADDRESS,
99  uint32_t si5_ = INVALID_ADDRESS,
100  uint32_t si6_ = INVALID_ADDRESS,
101  uint32_t si7_ = INVALID_ADDRESS,
102  uint32_t si8_ = INVALID_ADDRESS,
103  uint32_t si9_ = INVALID_ADDRESS);
104 
106  void reset_address ();
107 
109  geom_id ();
110 
112  geom_id (uint32_t type_,
113  uint32_t si0_);
114 
116  geom_id (uint32_t type_,
117  uint32_t si0_,
118  uint32_t si1_);
119 
121  geom_id (uint32_t type_,
122  uint32_t si0_,
123  uint32_t si1_,
124  uint32_t si2_);
125 
127  geom_id (uint32_t type_,
128  uint32_t si0_,
129  uint32_t si1_,
130  uint32_t si2_,
131  uint32_t si3_);
132 
134  geom_id (uint32_t type_,
135  uint32_t si0_,
136  uint32_t si1_,
137  uint32_t si2_,
138  uint32_t si3_,
139  uint32_t si4_,
140  uint32_t si5_ = INVALID_ADDRESS,
141  uint32_t si6_ = INVALID_ADDRESS,
142  uint32_t si7_ = INVALID_ADDRESS,
143  uint32_t si8_ = INVALID_ADDRESS,
144  uint32_t si9_ = INVALID_ADDRESS);
145 
147  virtual ~geom_id ();
148 
150  void reset ();
151 
153  void invalidate ();
154 
156  bool is_valid () const;
157 
159  bool is_complete () const;
160 
162  void extract_to (geom_id & target_) const;
163 
164  void extract_from (const geom_id & source_);
165 
166  void inherits_from (const geom_id & source_);
167 
169  bool match_impl (const geom_id & id_, bool exact_) const;
170 
171  bool match (const geom_id & id_, bool exact_ = false) const;
172 
173  static bool match (const geom_id & id1_, const geom_id & id2_,
174  bool exact_ = false);
175 
176  static int compare (const geom_id & id1_, const geom_id & id2_);
177 
178  bool operator== (const geom_id & id_) const;
179 
180  bool operator!= (const geom_id & id_) const;
181 
182  bool operator< (const geom_id & id_) const;
183 
184  bool operator<= (const geom_id & id_) const;
185 
186  bool operator>= (const geom_id & id_) const;
187 
188  bool operator> (const geom_id & id_) const;
189 
190  friend std::ostream & operator<< (std::ostream & out_, const geom_id & id_);
191 
192  friend std::istream & operator>> (std::istream & in_, geom_id & id_);
193 
195  void make (int type_, int depth_);
196 
197  static void make (geom_id & id_, int type_, int depth_);
198 
199  static bool sub_id_comp (uint32_t si1_, uint32_t si2_);
200 
201  private:
202 
203  uint32_t _type_;
204  std::vector<uint32_t> _addresses_;
205 
207 
208 
209  DR_CLASS_RTTI()
210 
211  };
212 
213 } // end of namespace geomtools
214 
215 #include <boost/serialization/export.hpp>
216 BOOST_CLASS_EXPORT_KEY2(geomtools::geom_id, "geomtools::geom_id")
217 
218 //#warning Activate reflection layer for the geomtools::geom_id class
219 // Activate reflection layer for the geomtools::geom_id class :
221 
222 // Class version:
223 #include <boost/serialization/version.hpp>
224 BOOST_CLASS_VERSION(geomtools::geom_id, 1)
225 
226 #endif // GEOMTOOLS_GEOM_ID_H
227 
228 /*
229 ** Local Variables: --
230 ** mode: c++ --
231 ** c-file-style: "gnu" --
232 ** tab-width: 2 --
233 ** End: --
234 */
#define DR_CLASS_INIT(Introspectable)
Inform Camp that class Introspectable exists and trigger the automatic registration of dedicated refl...
Definition: reflection_interface.h:149
bool operator>(const geom_id &id_) const
void set_address(uint32_t si0_, uint32_t si1_=INVALID_ADDRESS, uint32_t si2_=INVALID_ADDRESS, uint32_t si3_=INVALID_ADDRESS, uint32_t si4_=INVALID_ADDRESS, uint32_t si5_=INVALID_ADDRESS, uint32_t si6_=INVALID_ADDRESS, uint32_t si7_=INVALID_ADDRESS, uint32_t si8_=INVALID_ADDRESS, uint32_t si9_=INVALID_ADDRESS)
Set the addresses (up to depth = 10)
Base abstract class of all serializable (and possibly introspectable) classes.
Definition: i_serializable.h:51
void reset()
Reset/invalidate the GID.
virtual ~geom_id()
Destructor.
bool operator!=(const geom_id &id_) const
void extract_from(const geom_id &source_)
void set_depth(uint32_t depth_)
Set the depth.
void set(int, uint32_t val_)
Set the subaddress at given index to a given value.
static const char IO_ADDRESS_INVALID
Definition: geom_id.h:56
static const char IO_TYPE_INVALID
Definition: geom_id.h:55
bool operator>=(const geom_id &id_) const
void extract_to(geom_id &target_) const
Fill the target GID's addresses with current GID's addresses up to the target GID's depth.
static const uint32_t ANY_ADDRESS
Definition: geom_id.h:47
geom_id()
Default constructor.
bool is_invalid(int) const
Check if subaddress at given index is invalid.
#define DATATOOLS_SERIALIZATION_DECLARATION()
Definition: i_serializable.h:266
void inherits_from(const geom_id &source_)
void reset_address()
Reset the address.
void set_type(uint32_t)
Set the type.
uint32_t get(int) const
Returns the subaddress value at given index.
static int compare(const geom_id &id1_, const geom_id &id2_)
static const uint32_t UNIVERSE_TYPE
Definition: geom_id.h:49
void make(int type_, int depth_)
Initialize the GID with a given type and address' depth.
static const char IO_ADDRESS_ANY
Definition: geom_id.h:58
bool is_type(uint32_t) const
Check if the type match a given value.
static const char IO_ADDRESS_SEPARATOR
Definition: geom_id.h:54
static const char IO_ID_SEPARATOR
Definition: geom_id.h:53
void set_invalid(int)
Invalidate the subaddress at given index to 'any'.
bool match_impl(const geom_id &id_, bool exact_) const
Non-overloaded version for CAMP reflection tools:
static const uint32_t INVALID_ADDRESS
Definition: geom_id.h:46
bool is_complete() const
Check if the GID is complete.
static const char IO_ID_OPEN
Definition: geom_id.h:52
bool match(const geom_id &id_, bool exact_=false) const
static bool sub_id_comp(uint32_t si1_, uint32_t si2_)
void set_any(int)
Set the subaddress at given index to the any value.
static const uint32_t WORLD_TYPE
Definition: geom_id.h:50
friend std::ostream & operator<<(std::ostream &out_, const geom_id &id_)
bool operator==(const geom_id &id_) const
Definition: geom_id.h:41
static const uint32_t DEFAULT_ADDRESS_DEPTH
Definition: geom_id.h:48
friend std::istream & operator>>(std::istream &in_, geom_id &id_)
static const uint32_t INVALID_TYPE
Definition: geom_id.h:45
uint32_t get_depth() const
Returns the address' depth.
bool operator<(const geom_id &id_) const
#define DR_CLASS_RTTI()
Declare Camp RTTI within class declaration.
Definition: reflection_interface.h:46
uint32_t get_type() const
Return the type.
bool is_valid() const
Check if the GID is valid.
bool operator<=(const geom_id &id_) const
static const char IO_ID_CLOSE
Definition: geom_id.h:57
void invalidate()
Reset/invalidate the GID.
bool is_any(int) const
Check if subaddress at given index is 'any'.
Top-level namespace of the Bayeux/geomtools module library.
Definition: electromagnetic_field_manager.h:39