Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JUTMGrid.hh
Go to the documentation of this file.
1 #ifndef __JUTM__JUTMGRID__
2 #define __JUTM__JUTMGRID__
3 
4 #include <string>
5 #include <ostream>
6 #include <ostream>
7 #include <sstream>
8 
9 #include "JLang/JException.hh"
10 #include "JLang/JEquals.hh"
11 #include "JIO/JSerialisable.hh"
12 #include "JIO/JSTDIO.hh"
13 
14 
15 /**
16  * \author mdejong
17  */
18 
19 namespace JUTM {}
20 namespace JPP { using namespace JUTM; }
21 
22 namespace JUTM {
23 
24  using JLANG::JParseError;
25  using JLANG::JEquals;
26  using JIO::JReader;
27  using JIO::JWriter;
28 
29 
30  /**
31  * Data structure for UTM grid.
32  * This data structure is composed of:
33  * - World Geodetic System;
34  * - UTM zone;
35  */
36  class JUTMGrid :
37  public JEquals<JUTMGrid>
38  {
39  public:
40  /**
41  * Default constructor.
42  */
44  key ("?"),
45  wgs ("?"),
46  zone("?")
47  {}
48 
49 
50  /**
51  * Constructor.
52  *
53  * \param key key
54  * \param wgs WGS
55  * \param zone UTM zone
56  */
57  JUTMGrid(const std::string& key,
58  const std::string& wgs,
59  const std::string& zone)
60  {
61  this->key = key;
62  this->wgs = wgs;
63  this->zone = zone;
64  }
65 
66 
67  /**
68  * Get UTM grid.
69  *
70  * \return UTM grid
71  */
72  const JUTMGrid& getUTMGrid() const
73  {
74  return static_cast<const JUTMGrid&>(*this);
75  }
76 
77 
78  /**
79  * Set UTM grid.
80  *
81  * \param grid UTM grid
82  */
83  void setUTMGrid(const JUTMGrid& grid)
84  {
85  static_cast<JUTMGrid&>(*this) = grid;
86  }
87 
88 
89  /**
90  * Get key.
91  *
92  * \return key
93  */
94  const std::string& getKey() const
95  {
96  return key;
97  }
98 
99 
100  /**
101  * Get WGS.
102  *
103  * \return WGS
104  */
105  const std::string& getWGS() const
106  {
107  return wgs;
108  }
109 
110 
111  /**
112  * Get UTM zone
113  *
114  * \return UTM zone
115  */
116  const std::string& getUTMZone() const
117  {
118  return zone;
119  }
120 
121 
122  /**
123  * Check equality.
124  *
125  * \param grid UTM grid
126  * \return true if grids are equal; else false
127  */
128  bool equals(const JUTMGrid& grid) const
129  {
130  return (this->getKey() == grid.getKey() &&
131  this->getWGS() == grid.getWGS() &&
132  this->getUTMZone() == grid.getUTMZone());
133  }
134 
135 
136  /**
137  * Convert UTM grid.
138  *
139  * \return UTM grid
140  */
141  std::string toString() const
142  {
143  return (key + " " + wgs + " " + zone);
144  }
145 
146 
147  /**
148  * Extract UTM grid.
149  *
150  * \param buffer WGS and UTM zone
151  * \return UTM grid
152  */
153  static JUTMGrid valueOf(const std::string& buffer)
154  {
155  JUTMGrid grid;
156 
157  std::istringstream is(buffer);
158 
159  if (is >> grid)
160  return grid;
161  else
162  throw JParseError("JUTMGrid::valueOf()");
163  }
164 
165 
166  /**
167  * Read UTM grid from input.
168  *
169  * \param in input stream
170  * \param grid UTM grid
171  * \return input stream
172  */
173  friend inline std::istream& operator>>(std::istream& in, JUTMGrid& grid)
174  {
175  return in >> grid.key >> grid.wgs >> grid.zone;
176  }
177 
178 
179  /**
180  * Write UTM grid to output.
181  *
182  * \param out output stream
183  * \param grid UTM grid
184  * \return output stream
185  */
186  friend inline std::ostream& operator<<(std::ostream& out, const JUTMGrid& grid)
187  {
188  return out << grid.key << ' ' << grid.wgs << ' ' << grid.zone;
189  }
190 
191 
192  /**
193  * Read UTM grid from input.
194  *
195  * \param in input stream
196  * \param grid UTM grid
197  * \return input stream
198  */
199  friend inline JReader& operator>>(JReader& in, JUTMGrid& grid)
200  {
201  using namespace JIO;
202 
203  return in >> grid.key >> grid.wgs >> grid.zone;
204  }
205 
206 
207  /**
208  * Write UTM grid to output.
209  *
210  * \param out output stream
211  * \param grid UTM grid
212  * \return output stream
213  */
214  friend inline JWriter& operator<<(JWriter& out, const JUTMGrid& grid)
215  {
216  using namespace JIO;
217 
218  return out << grid.key << grid.wgs << grid.zone;
219  }
220 
221 
222  protected:
223  std::string key;
224  std::string wgs;
225  std::string zone;
226  };
227 }
228 
229 #endif
Exceptions.
Interface for binary output.
friend JWriter & operator<<(JWriter &out, const JUTMGrid &grid)
Write UTM grid to output.
Definition: JUTMGrid.hh:214
const std::string & getWGS() const
Get WGS.
Definition: JUTMGrid.hh:105
std::string toString() const
Convert UTM grid.
Definition: JUTMGrid.hh:141
is
Definition: JDAQCHSM.chsm:167
const std::string & getKey() const
Get key.
Definition: JUTMGrid.hh:94
friend std::istream & operator>>(std::istream &in, JUTMGrid &grid)
Read UTM grid from input.
Definition: JUTMGrid.hh:173
JUTMGrid()
Default constructor.
Definition: JUTMGrid.hh:43
std::string key
Definition: JUTMGrid.hh:223
std::string zone
Definition: JUTMGrid.hh:225
friend std::ostream & operator<<(std::ostream &out, const JUTMGrid &grid)
Write UTM grid to output.
Definition: JUTMGrid.hh:186
Template definition of auxiliary base class for comparison of data structures.
Definition: JEquals.hh:24
bool equals(const JUTMGrid &grid) const
Check equality.
Definition: JUTMGrid.hh:128
std::string wgs
Definition: JUTMGrid.hh:224
Interface for binary input.
Data structure for UTM grid.
Definition: JUTMGrid.hh:36
static JUTMGrid valueOf(const std::string &buffer)
Extract UTM grid.
Definition: JUTMGrid.hh:153
const JUTMGrid & getUTMGrid() const
Get UTM grid.
Definition: JUTMGrid.hh:72
friend JReader & operator>>(JReader &in, JUTMGrid &grid)
Read UTM grid from input.
Definition: JUTMGrid.hh:199
Exception for parsing value.
Definition: JException.hh:180
void setUTMGrid(const JUTMGrid &grid)
Set UTM grid.
Definition: JUTMGrid.hh:83
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 source JAcoustics sh $DETECTOR_ID typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:36
const std::string & getUTMZone() const
Get UTM zone.
Definition: JUTMGrid.hh:116
STD extensions for binary I/O.
JUTMGrid(const std::string &key, const std::string &wgs, const std::string &zone)
Constructor.
Definition: JUTMGrid.hh:57