Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
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#include <ctype.h>
9
10#include "JLang/JException.hh"
11#include "JLang/JEquals.hh"
12#include "JIO/JSerialisable.hh"
13#include "JIO/JSTDIO.hh"
14
15
16/**
17 * \author mdejong
18 */
19
20namespace JUTM {}
21namespace JPP { using namespace JUTM; }
22
23namespace JUTM {
24
26 using JLANG::JEquals;
27 using JIO::JReader;
28 using JIO::JWriter;
29
30
31 /**
32 * Data structure for UTM grid.
33 * This data structure is composed of:
34 * - World Geodetic System;
35 * - UTM zone;
36 */
37 class JUTMGrid :
38 public JEquals<JUTMGrid>
39 {
40 public:
41 /**
42 * Default constructor.
43 */
45 key ("?"),
46 wgs ("?"),
47 zone("?")
48 {}
49
50
51 /**
52 * Constructor.
53 *
54 * \param key key
55 * \param wgs WGS
56 * \param zone UTM zone
57 */
58 JUTMGrid(const std::string& key,
59 const std::string& wgs,
60 const std::string& zone)
61 {
62 this->key = key;
63 this->wgs = wgs;
64 this->zone = zone;
65 }
66
67
68 /**
69 * Get UTM grid.
70 *
71 * \return UTM grid
72 */
73 const JUTMGrid& getUTMGrid() const
74 {
75 return static_cast<const JUTMGrid&>(*this);
76 }
77
78
79 /**
80 * Set UTM grid.
81 *
82 * \param grid UTM grid
83 */
84 void setUTMGrid(const JUTMGrid& grid)
85 {
86 static_cast<JUTMGrid&>(*this) = grid;
87 }
88
89
90 /**
91 * Get key.
92 *
93 * \return key
94 */
95 const std::string& getKey() const
96 {
97 return key;
98 }
99
100
101 /**
102 * Get WGS.
103 *
104 * \return WGS
105 */
106 const std::string& getWGS() const
107 {
108 return wgs;
109 }
110
111
112 /**
113 * Get UTM zone.
114 *
115 * \return UTM zone
116 */
117 const std::string& getUTMZone() const
118 {
119 return zone;
120 }
121
122
123 /**
124 * Get UTM zone by numerical value.
125 *
126 * \return UTM zone
127 */
128 int getUTMValue() const
129 {
130 using namespace std;
131
132 int value = 0;
133
134 for (string::const_iterator i = zone.begin(); i != zone.end(); ++i) {
135 if (isdigit(*i))
136 value = 10 * value + (*i - '0');
137 else
138 break;
139 }
140
141 return value;
142 }
143
144
145 /**
146 * Check equality.
147 *
148 * \param grid UTM grid
149 * \return true if grids are equal; else false
150 */
151 bool equals(const JUTMGrid& grid) const
152 {
153 return (this->getKey() == grid.getKey() &&
154 this->getWGS() == grid.getWGS() &&
155 this->getUTMValue() == grid.getUTMValue());
156 }
157
158
159 /**
160 * Convert UTM grid.
161 *
162 * \return UTM grid
163 */
164 std::string toString() const
165 {
166 return (key + " " + wgs + " " + zone);
167 }
168
169
170 /**
171 * Extract UTM grid.
172 *
173 * \param buffer WGS and UTM zone
174 * \return UTM grid
175 */
176 static JUTMGrid valueOf(const std::string& buffer)
177 {
178 JUTMGrid grid;
179
180 std::istringstream is(buffer);
181
182 if (is >> grid)
183 return grid;
184 else
185 throw JParseError("JUTMGrid::valueOf()");
186 }
187
188
189 /**
190 * Read UTM grid from input.
191 *
192 * \param in input stream
193 * \param grid UTM grid
194 * \return input stream
195 */
196 friend inline std::istream& operator>>(std::istream& in, JUTMGrid& grid)
197 {
198 return in >> grid.key >> grid.wgs >> grid.zone;
199 }
200
201
202 /**
203 * Write UTM grid to output.
204 *
205 * \param out output stream
206 * \param grid UTM grid
207 * \return output stream
208 */
209 friend inline std::ostream& operator<<(std::ostream& out, const JUTMGrid& grid)
210 {
211 return out << grid.key << ' ' << grid.wgs << ' ' << grid.zone;
212 }
213
214
215 /**
216 * Read UTM grid from input.
217 *
218 * \param in input stream
219 * \param grid UTM grid
220 * \return input stream
221 */
222 friend inline JReader& operator>>(JReader& in, JUTMGrid& grid)
223 {
224 using namespace JIO;
225
226 return in >> grid.key >> grid.wgs >> grid.zone;
227 }
228
229
230 /**
231 * Write UTM grid to output.
232 *
233 * \param out output stream
234 * \param grid UTM grid
235 * \return output stream
236 */
237 friend inline JWriter& operator<<(JWriter& out, const JUTMGrid& grid)
238 {
239 using namespace JIO;
240
241 return out << grid.key << grid.wgs << grid.zone;
242 }
243
244
245 protected:
246 std::string key;
247 std::string wgs;
248 std::string zone;
249 };
250}
251
252#endif
Exceptions.
STD extensions for binary I/O.
Interface for binary input.
Interface for binary output.
Exception for parsing value.
Data structure for UTM grid.
Definition JUTMGrid.hh:39
std::string toString() const
Convert UTM grid.
Definition JUTMGrid.hh:164
int getUTMValue() const
Get UTM zone by numerical value.
Definition JUTMGrid.hh:128
JUTMGrid(const std::string &key, const std::string &wgs, const std::string &zone)
Constructor.
Definition JUTMGrid.hh:58
friend std::ostream & operator<<(std::ostream &out, const JUTMGrid &grid)
Write UTM grid to output.
Definition JUTMGrid.hh:209
friend JReader & operator>>(JReader &in, JUTMGrid &grid)
Read UTM grid from input.
Definition JUTMGrid.hh:222
static JUTMGrid valueOf(const std::string &buffer)
Extract UTM grid.
Definition JUTMGrid.hh:176
const std::string & getKey() const
Get key.
Definition JUTMGrid.hh:95
friend std::istream & operator>>(std::istream &in, JUTMGrid &grid)
Read UTM grid from input.
Definition JUTMGrid.hh:196
const JUTMGrid & getUTMGrid() const
Get UTM grid.
Definition JUTMGrid.hh:73
friend JWriter & operator<<(JWriter &out, const JUTMGrid &grid)
Write UTM grid to output.
Definition JUTMGrid.hh:237
const std::string & getWGS() const
Get WGS.
Definition JUTMGrid.hh:106
bool equals(const JUTMGrid &grid) const
Check equality.
Definition JUTMGrid.hh:151
void setUTMGrid(const JUTMGrid &grid)
Set UTM grid.
Definition JUTMGrid.hh:84
const std::string & getUTMZone() const
Get UTM zone.
Definition JUTMGrid.hh:117
std::string key
Definition JUTMGrid.hh:246
JUTMGrid()
Default constructor.
Definition JUTMGrid.hh:44
std::string wgs
Definition JUTMGrid.hh:247
std::string zone
Definition JUTMGrid.hh:248
Auxiliary classes and methods for binary I/O.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliaries for handling universal transverse mercator coordinate system (UTM).
Definition JUTMGrid.hh:20
Template definition of auxiliary base class for comparison of data structures.
Definition JEquals.hh:84