Jpp  18.0.0-rc.3
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JLocation.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JLOCATION__
2 #define __JDETECTOR__JLOCATION__
3 
4 #include <istream>
5 #include <ostream>
6 #include <iomanip>
7 #include <string>
8 
9 #include "JLang/JComparable.hh"
10 #include "JLang/JString.hh"
11 #include "JIO/JSerialisable.hh"
12 #include "Jeep/JPrint.hh"
13 
14 
15 /**
16  * \file
17  *
18  * Logical location of module.
19  * \author mdejong
20  */
21 namespace JDETECTOR {}
22 namespace JPP { using namespace JDETECTOR; }
23 
24 namespace JDETECTOR {
25 
26  using JLANG::JComparable;
27  using JIO::JReader;
28  using JIO::JWriter;
29 
30 
31  /**
32  * Logical location of module.
33  *
34  * The logical location of a module consists of a string and floor number.\n
35  * This class implements the JLANG::JComparable interface.
36  */
37  class JLocation :
38  public JComparable<JLocation>
39  {
40  public:
41  /**
42  * Default constructor.
43  */
45  string(-1),
46  floor (-1)
47  {}
48 
49 
50  /**
51  * Constructor.
52  *
53  * \param string string
54  * \param floor floor
55  */
56  JLocation(const int string,
57  const int floor)
58  {
59  this->string = string;
60  this->floor = floor;
61  }
62 
63 
64  /**
65  * Get location.
66  *
67  * \return location
68  */
69  const JLocation& getLocation() const
70  {
71  return static_cast<const JLocation&>(*this);
72  }
73 
74 
75  /**
76  * Get location.
77  *
78  * \return location
79  */
81  {
82  return static_cast<JLocation&>(*this);
83  }
84 
85 
86  /**
87  * Set location.
88  *
89  * \param location location
90  */
91  void setLocation(const JLocation& location)
92  {
93  static_cast<JLocation&>(*this) = location;
94  }
95 
96 
97  /**
98  * Convert module location to string.
99  *
100  * \return string
101  */
103  {
104  return toString("% %");
105  }
106 
107 
108  /**
109  * Convert module loation to string.
110  *
111  * The targets <tt>target</tt> in the format string <tt>fmt</tt> are
112  * consecutively replaced by <tt>floor</tt> and <tt>string</tt>.
113  *
114  * \param fmt format
115  * \param target target
116  * \return string
117  */
118  std::string toString(const std::string& fmt, const std::string target = "%") const
119  {
120  JLANG::JString buffer(fmt);
121 
122  buffer.replace(target, string, 1);
123  buffer.replace(target, floor, 1);
124 
125  return buffer;
126  }
127 
128 
129  /**
130  * Get string number.
131  *
132  * \return string number
133  */
134  int getString() const
135  {
136  return string;
137  }
138 
139 
140  /**
141  * Get floor number.
142  *
143  * \return floor number
144  */
145  int getFloor() const
146  {
147  return floor;
148  }
149 
150 
151  /**
152  * Less than method.
153  *
154  * \param location module location
155  * \result true if first location before second location; else false
156  */
157  bool less(const JLocation& location) const
158  {
159  if (this->getString() == location.getString())
160  return this->getFloor() < location.getFloor();
161  else
162  return this->getString() < location.getString();
163  }
164 
165 
166  /**
167  * Read module location from input.
168  *
169  * \param in input stream
170  * \param location module location
171  * \return input stream
172  */
173  friend inline std::istream& operator>>(std::istream& in, JLocation& location)
174  {
175  in >> location.string;
176  in >> location.floor;
177 
178  return in;
179  }
180 
181 
182  /**
183  * Write module location to output.
184  *
185  * \param out output stream
186  * \param location module location
187  * \return output stream
188  */
189  friend inline std::ostream& operator<<(std::ostream& out, const JLocation& location)
190  {
191  using namespace std;
192 
193  out << setw(4) << location.string;
194  out << ' ';
195  out << setw(2) << location.floor;
196 
197  return out;
198  }
199 
200 
201  /**
202  * Read module location from input.
203  *
204  * \param in reader
205  * \param location module location
206  * \return reader
207  */
208  friend inline JReader& operator>>(JReader& in, JLocation& location)
209  {
210  in >> location.string;
211  in >> location.floor;
212 
213  return in;
214  }
215 
216 
217  /**
218  * Write module location to output.
219  *
220  * \param out writer
221  * \param location module location
222  * \return writer
223  */
224  friend inline JWriter& operator<<(JWriter& out, const JLocation& location)
225  {
226  out << location.string;
227  out << location.floor;
228 
229  return out;
230  }
231 
232 
233  protected:
234  int string;
235  int floor;
236  };
237 
238 
239  /**
240  * Get module label for monitoring and other applications.\n
241  * The format is "(XXXX,YY)", where XXXX is the string number and YY the floor.
242  *
243  * \param location module location
244  * \return label
245  */
246  inline std::string getLabel(const JLocation& location)
247  {
248  using namespace std;
249  using namespace JPP;
250 
251  return MAKE_STRING("(" << FILL(4,'0') << location.getString() << "." << FILL(2,'0') << location.getFloor() << ")");
252  }
253 }
254 
255 #endif
friend std::ostream & operator<<(std::ostream &out, const JLocation &location)
Write module location to output.
Definition: JLocation.hh:189
Interface for binary output.
Wrapper class around STL string class.
Definition: JString.hh:27
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
void setLocation(const JLocation &location)
Set location.
Definition: JLocation.hh:91
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications.
Definition: JLocation.hh:246
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:127
I/O formatting auxiliaries.
bool less(const JLocation &location) const
Less than method.
Definition: JLocation.hh:157
Logical location of module.
Definition: JLocation.hh:37
const JLocation & getLocation() const
Get location.
Definition: JLocation.hh:69
std::string toString() const
Convert module location to string.
Definition: JLocation.hh:102
JLocation()
Default constructor.
Definition: JLocation.hh:44
then awk string
Interface for binary input.
JLocation & getLocation()
Get location.
Definition: JLocation.hh:80
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
JLocation(const int string, const int floor)
Constructor.
Definition: JLocation.hh:56
int getString() const
Get string number.
Definition: JLocation.hh:134
JString & replace(const char target, const char replacement, const std::size_t max=std::numeric_limits< std::size_t >::max())
Replace characters.
Definition: JString.hh:170
friend JReader & operator>>(JReader &in, JLocation &location)
Read module location from input.
Definition: JLocation.hh:208
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
friend std::istream & operator>>(std::istream &in, JLocation &location)
Read module location from input.
Definition: JLocation.hh:173
friend JWriter & operator<<(JWriter &out, const JLocation &location)
Write module location to output.
Definition: JLocation.hh:224
std::string toString(const std::string &fmt, const std::string target="%") const
Convert module loation to string.
Definition: JLocation.hh:118