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 "JIO/JSerialisable.hh"
11 #include "JIO/JSTDIO.hh"
12 
13 
14 /**
15  * \author mdejong
16  */
17 
18 namespace JUTM {}
19 namespace JPP { using namespace JUTM; }
20 
21 namespace JUTM {
22 
23  using JLANG::JParseError;
24  using JIO::JReader;
25  using JIO::JWriter;
26 
27 
28  /**
29  * Data structure for UTM grid.
30  * This data structure is composed of:
31  * - World Geodetic System;
32  * - UTM zone;
33  */
34  class JUTMGrid {
35  public:
36  /**
37  * Default constructor.
38  */
40  key ("?"),
41  wgs ("?"),
42  zone("?")
43  {}
44 
45 
46  /**
47  * Constructor.
48  *
49  * \param key key
50  * \param wgs WGS
51  * \param zone UTM zone
52  */
53  JUTMGrid(const std::string& key,
54  const std::string& wgs,
55  const std::string& zone)
56  {
57  this->key = key;
58  this->wgs = wgs;
59  this->zone = zone;
60  }
61 
62 
63  /**
64  * Get key.
65  *
66  * \return key
67  */
68  const std::string& getKey() const
69  {
70  return key;
71  }
72 
73 
74  /**
75  * Get WGS.
76  *
77  * \return WGS
78  */
79  const std::string& getWGS() const
80  {
81  return wgs;
82  }
83 
84 
85  /**
86  * Get UTM zone
87  *
88  * \return UTM zone
89  */
90  const std::string& getUTMZone() const
91  {
92  return zone;
93  }
94 
95 
96  /**
97  * Convert UTM grid.
98  *
99  * \return UTM grid
100  */
101  std::string toString() const
102  {
103  return (key + " " + wgs + " " + zone);
104  }
105 
106 
107  /**
108  * Extract UTM grid.
109  *
110  * \param buffer WGS and UTM zone
111  * \return UTM grid
112  */
113  static JUTMGrid valueOf(const std::string& buffer)
114  {
115  JUTMGrid grid;
116 
117  std::istringstream is(buffer);
118 
119  if (is >> grid)
120  return grid;
121  else
122  throw JParseError("JUTMGrid::valueOf()");
123  }
124 
125 
126  /**
127  * Read UTM grid from input.
128  *
129  * \param in input stream
130  * \param grid UTM grid
131  * \return input stream
132  */
133  friend inline std::istream& operator>>(std::istream& in, JUTMGrid& grid)
134  {
135  return in >> grid.key >> grid.wgs >> grid.zone;
136  }
137 
138 
139  /**
140  * Write UTM grid to output.
141  *
142  * \param out output stream
143  * \param grid UTM grid
144  * \return output stream
145  */
146  friend inline std::ostream& operator<<(std::ostream& out, const JUTMGrid& grid)
147  {
148  return out << grid.key << ' ' << grid.wgs << ' ' << grid.zone;
149  }
150 
151 
152  /**
153  * Read UTM grid from input.
154  *
155  * \param in input stream
156  * \param grid UTM grid
157  * \return input stream
158  */
159  friend inline JReader& operator>>(JReader& in, JUTMGrid& grid)
160  {
161  using namespace JIO;
162 
163  return in >> grid.key >> grid.wgs >> grid.zone;
164  }
165 
166 
167  /**
168  * Write UTM grid to output.
169  *
170  * \param out output stream
171  * \param grid UTM grid
172  * \return output stream
173  */
174  friend inline JWriter& operator<<(JWriter& out, const JUTMGrid& grid)
175  {
176  using namespace JIO;
177 
178  return out << grid.key << grid.wgs << grid.zone;
179  }
180 
181 
182  protected:
183  std::string key;
184  std::string wgs;
185  std::string zone;
186  };
187 }
188 
189 #endif
Exceptions.
Interface for binary output.
friend JWriter & operator<<(JWriter &out, const JUTMGrid &grid)
Write UTM grid to output.
Definition: JUTMGrid.hh:174
const std::string & getWGS() const
Get WGS.
Definition: JUTMGrid.hh:79
std::string toString() const
Convert UTM grid.
Definition: JUTMGrid.hh:101
const std::string & getKey() const
Get key.
Definition: JUTMGrid.hh:68
friend std::istream & operator>>(std::istream &in, JUTMGrid &grid)
Read UTM grid from input.
Definition: JUTMGrid.hh:133
JUTMGrid()
Default constructor.
Definition: JUTMGrid.hh:39
std::string key
Definition: JUTMGrid.hh:183
std::string zone
Definition: JUTMGrid.hh:185
friend std::ostream & operator<<(std::ostream &out, const JUTMGrid &grid)
Write UTM grid to output.
Definition: JUTMGrid.hh:146
std::string wgs
Definition: JUTMGrid.hh:184
Interface for binary input.
Data structure for UTM grid.
Definition: JUTMGrid.hh:34
static JUTMGrid valueOf(const std::string &buffer)
Extract UTM grid.
Definition: JUTMGrid.hh:113
friend JReader & operator>>(JReader &in, JUTMGrid &grid)
Read UTM grid from input.
Definition: JUTMGrid.hh:159
Exception for parsing value.
Definition: JException.hh:162
const std::string & getUTMZone() const
Get UTM zone.
Definition: JUTMGrid.hh:90
STD extensions for binary I/O.
JUTMGrid(const std::string &key, const std::string &wgs, const std::string &zone)
Constructor.
Definition: JUTMGrid.hh:53