OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Functions
ossimIpt.cpp File Reference
#include <iostream>
#include <sstream>
#include <ossim/base/ossimIpt.h>
#include <ossim/base/ossimDpt.h>
#include <ossim/base/ossimDpt3d.h>
#include <ossim/base/ossimFpt.h>
#include <ossim/base/ossimCommon.h>
#include <ossim/base/ossimString.h>

Go to the source code of this file.

Functions

std::ostream & operator<< (std::ostream &os, const ossimIpt &pt)
 
std::istream & operator>> (std::istream &is, ossimIpt &pt)
 

Function Documentation

◆ operator<<()

std::ostream& operator<< ( std::ostream &  os,
const ossimIpt pt 
)

Definition at line 134 of file ossimIpt.cpp.

References ossimIpt::print().

135 {
136  return pt.print(os);
137 }
std::ostream & print(std::ostream &os) const
Definition: ossimIpt.cpp:105

◆ operator>>()

std::istream& operator>> ( std::istream &  is,
ossimIpt pt 
)

Expected format: ( 30, -90 ) -x- -y-

This method starts by doing a "makeNan" on pt. So if anything goes wrong with the stream or parsing pt could be all or partially nan.

Parameters
isInput stream istream to formatted text.
ptosimIpt to be initialized from stream.
Returns
istream pass in.

Definition at line 176 of file ossimIpt.cpp.

References ossimString::contains(), ossimString::erase(), ossimString::find(), ossimIpt::makeNan(), OSSIM_INT_NAN, ossimString::toInt32(), ossimIpt::x, and ossimIpt::y.

177 {
178  //---
179  // Expected input format:
180  // ( 30, -90 )
181  // -x- -y-
182  //---
183 
184  // Start with a nan point.
185  pt.makeNan();
186 
187  // Check the stream.
188  if (!is) return is;
189 
190  const int SZ = 64; // Handle real big number...
191  ossimString os;
192  char buf[SZ];
193 
194  //---
195  // X SECTION:
196  //---
197 
198  // Grab data up to the first comma.
199  is.get(buf, SZ, ',');
200 
201  if (!is) return is;
202 
203  // Copy to ossim string.
204  os = buf;
205 
206  // Get rid of the '(' if there is any.
207  std::string::size_type pos = os.find('(');
208  if (pos != std::string::npos)
209  {
210  os.erase(pos, 1);
211  }
212  if (os.contains("nan") == false)
213  {
214  pt.x = os.toInt32();
215  }
216  else
217  {
218  pt.x = OSSIM_INT_NAN;
219  }
220 
221  //---
222  // Y SECTION:
223  //---
224 
225  // Grab the data up to the ')'
226  is.get(buf, SZ, ')');
227 
228  if (!is) return is;
229 
230  // Copy to ossim string.
231  os = buf;
232 
233  // Get rid of the ',' if there is any.
234  pos = os.find(',');
235  if (pos != std::string::npos)
236  {
237  os.erase(pos, 1);
238  }
239 
240  if (os.contains("nan") == false)
241  {
242  pt.y = os.toInt32();
243  }
244  else
245  {
246  pt.y = OSSIM_INT_NAN;
247  }
248 
249  // Gobble the trailing ")".
250  char c = 0;
251  while (c != ')')
252  {
253  is.get(c);
254  if (!is) break;
255  }
256 
257  // Finished
258  return is;
259 }
void makeNan()
Definition: ossimIpt.h:56
bool contains(char aChar) const
Definition: ossimString.h:58
#define OSSIM_INT_NAN
ossim_int32 toInt32() const
std::string::iterator erase(std::string::iterator p)
Erases the character at position p.
Definition: ossimString.h:736
ossim_int32 y
Definition: ossimIpt.h:142
ossim_int32 x
Definition: ossimIpt.h:141
std::string::size_type find(const std::string &s, std::string::size_type pos=0) const
Searches for s as a substring of *this, beginning at character pos of *this.
Definition: ossimString.h:753