[Positioning] Add Point3D::Point3D(string)

This commit is contained in:
Matteo Cypriani 2011-04-27 18:47:56 +02:00
parent ceb035ed19
commit ccb57c86ec
3 changed files with 33 additions and 3 deletions

View File

@ -133,6 +133,8 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cc $(SRC_DIR)/%.hh
$(LD) $(LDFLAGS) -o $@ $^
# Dependencies
$(OBJ_DIR)/point3d.o: \
$(OBJ_DIR)/posexcept.o
$(OBJ_DIR)/posutil.o: \
$(OBJ_DIR)/posexcept.o
$(OBJ_DIR)/owlps-positioning.o: \

View File

@ -1,8 +1,33 @@
#include "point3d.hh"
#include "posexcept.hh"
#include <sstream>
#include <boost/functional/hash.hpp>
using namespace std ;
/* *** Constructors *** */
Point3D::Point3D(const string &source)
{
float pos[3] ;
istringstream iss(source) ;
for (int i = 0 ; i < 2 ; ++i)
{
iss >> pos[i] ;
if (iss.get() != ';')
throw malformed_input_data(
"Point3D(string): cannot extract coordinates!") ;
}
iss >> pos[2] ;
set_coordinates(pos) ;
}
/* *** Distance operations *** */
@ -84,16 +109,16 @@ bool Point3D::operator<(const Point3D &source) const
}
Point3D::operator std::string(void) const
Point3D::operator string(void) const
{
std::ostringstream oss ;
ostringstream oss ;
oss << *this ;
return oss.str() ;
}
std::ostream& operator<<(std::ostream &os, const Point3D &p)
ostream& operator<<(ostream &os, const Point3D &p)
{
os << "(" << p.x << ";" << p.y << ";" << p.z << ")" ;
return os ;

View File

@ -1,6 +1,7 @@
#ifndef _OWLPS_POSITIONING_POINT3D_HH_
#define _OWLPS_POSITIONING_POINT3D_HH_
#include <string>
#include <ostream>
#include <cmath>
@ -22,6 +23,8 @@ public:
Point3D(const float source[3]):
x(source[0]), y(source[1]), z(source[2]) {}
Point3D(const std::string &source) ;
virtual ~Point3D(void) {}
/** @name Read accessors */