Jpp  19.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JLocation_t.hh
Go to the documentation of this file.
1 #ifndef __JDB__JLOCATION_T_
2 #define __JDB__JLOCATION_T_
3 
4 #include <ostream>
5 
6 #include "JLang/JComparable.hh"
7 #include "JLang/JManip.hh"
8 
9 
10 /**
11  * \author mdejong
12  */
13 namespace JDATABASE {}
14 namespace JPP { using namespace JDATABASE; }
15 
16 namespace JDATABASE {
17 
18  using JLANG::JComparable;
19 
20 
21  /**
22  * Auxiliary data structure for location of product in detector.
23  */
24  struct JLocation_t :
25  public JComparable<JLocation_t>
26  {
27  /**
28  * Default constructor.\n
29  * The default corresponds to an invalid location.
30  */
32  string (-1),
33  floor (-1),
34  position(-1)
35  {}
36 
37 
38  /**
39  * Constructor.
40  *
41  * \param string string
42  * \param floor floor
43  * \param position position
44  */
45  JLocation_t(const int string,
46  const int floor,
47  const int position) :
48  string (string),
49  floor (floor),
50  position(position)
51  {}
52 
53 
54  /**
55  * Check validity of location.
56  *
57  * \return true if valid; else false
58  */
59  bool is_valid() const
60  {
61  return *this != JLocation_t();
62  }
63 
64 
65  /**
66  * Less-than method.
67  *
68  * \param location location
69  * \return true if this location less than given location; else false
70  */
71  bool less(const JLocation_t& location) const
72  {
73  if (this->string == location.string) {
74 
75  if (this->floor == location.floor)
76  return this->position < location.position;
77  else
78  return this->floor < location.floor;
79 
80  } else {
81 
82  return this->string < location.string;
83  }
84  }
85 
86 
87  /**
88  * Write location to output stream.
89  *
90  * \param out output stream
91  * \param object location
92  * \return output stream
93  */
94  friend inline std::ostream& operator<<(std::ostream& out, const JLocation_t& object)
95  {
96  using namespace std;
97  using namespace JPP;
98 
99  return out << FILL(4,'0') << object.string << '.'
100  << FILL(2,'0') << object.floor << '.'
101  << FILL(2,'0') << object.position << FILL();
102  }
103 
104 
105  int string; //!< position in detector
106  int floor; //!< position in string
107  int position; //!< position in floor
108  };
109 }
110 
111 #endif
JLocation_t(const int string, const int floor, const int position)
Constructor.
Definition: JLocation_t.hh:45
bool less(const JLocation_t &location) const
Less-than method.
Definition: JLocation_t.hh:71
int floor
position in string
Definition: JLocation_t.hh:106
bool is_valid() const
Check validity of location.
Definition: JLocation_t.hh:59
Auxiliary data structure for location of product in detector.
Definition: JLocation_t.hh:24
JLocation_t()
Default constructor.
Definition: JLocation_t.hh:31
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:24
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
I/O manipulators.
friend std::ostream & operator<<(std::ostream &out, const JLocation_t &object)
Write location to output stream.
Definition: JLocation_t.hh:94
int position
position in floor
Definition: JLocation_t.hh:107
int string
position in detector
Definition: JLocation_t.hh:105