GeomConvHelper Class Reference

#include <GeomConvHelper.h>


Detailed Description

This class holds some helping functions for the parsing of geometries

Definition at line 44 of file GeomConvHelper.h.


Static Public Member Functions

static Boundary parseBoundaryReporting (const std::string &def, const char *objecttype, const char *objectid, bool &ok, bool report=true) throw ()
 Builds a boundary from its string representation, reporting occured errors.
static Position2DVector parseShapeReporting (const std::string &shpdef, const char *objecttype, const char *objectid, bool &ok, bool allowEmpty, bool report=true) throw ()
 Builds a Position2DVector from a string representation, reporting occured errors.

Static Private Member Functions

static void emitError (bool report, const std::string &what, const char *objecttype, const char *objectid, const std::string &desc) throw ()
 Writes an error message into the MessageHandler.

Member Function Documentation

void GeomConvHelper::emitError ( bool  report,
const std::string &  what,
const char *  objecttype,
const char *  objectid,
const std::string &  desc 
) throw () [static, private]

Writes an error message into the MessageHandler.

Parameters:
[in] report Whether errors shall be written to msg handler's error instance
[in] what Name of the parsed object ("Shape", or "Boundary")
[in] objecttype The name of the parsed object type the error occured at
[in] objectid The name of the parsed object type the error occured at
[out] desc Error description

Definition at line 109 of file GeomConvHelper.cpp.

References MsgHandler::getErrorInstance(), and MsgHandler::inform().

00110                                                                                {
00111     if (!report) {
00112         return;
00113     }
00114     std::ostringstream oss;
00115     oss << what << " of ";
00116     if (objectid==0) {
00117         oss << "a(n) ";
00118     }
00119     if (objecttype!=0) {
00120         oss << objecttype;
00121     } else {
00122         oss << "<unknown type>";
00123     }
00124     if (objectid!=0) {
00125         oss << " '" << objectid << "'";
00126     }
00127     oss << " is broken: " << desc << ".";
00128     MsgHandler::getErrorInstance()->inform(oss.str());
00129 }

Boundary GeomConvHelper::parseBoundaryReporting ( const std::string &  def,
const char *  objecttype,
const char *  objectid,
bool ok,
bool  report = true 
) throw () [static]

Builds a boundary from its string representation, reporting occured errors.

It is assumed that the boundary is stored as a quadruple of SUMOReal, divided by ','.

Parameters:
[in] def The boundary definition to parse
[in] objecttype The name of the parsed object type; used for error message generation
[in] objectid The name of the parsed object; used for error message generation
[out] ok Whether the value could be read
[in] report Whether errors shall be written to msg handler's error instance
Returns:
The parsed boundary

Definition at line 84 of file GeomConvHelper.cpp.

References TplConvert< E >::_2SUMOReal(), StringTokenizer::next(), StringTokenizer::size(), and SUMOReal.

Referenced by main(), PCNetProjectionLoader::myCharacters(), NLHandler::myCharacters(), PCNetProjectionLoader::myStartElement(), and NLHandler::setLocation().

00085                                                                                             {
00086     StringTokenizer st(def, ",");
00087     if (st.size()!=4) {
00088         emitError(report, "Bounding box", objecttype, objectid, "mismatching entry number");
00089         ok = false;
00090         return Boundary();
00091     }
00092     try {
00093         SUMOReal xmin = TplConvert<char>::_2SUMOReal(st.next().c_str());
00094         SUMOReal ymin = TplConvert<char>::_2SUMOReal(st.next().c_str());
00095         SUMOReal xmax = TplConvert<char>::_2SUMOReal(st.next().c_str());
00096         SUMOReal ymax = TplConvert<char>::_2SUMOReal(st.next().c_str());
00097         return Boundary(xmin, ymin, xmax, ymax);
00098     } catch (NumberFormatException &) {
00099         emitError(report, "Shape", objecttype, objectid, "not numeric entry");
00100     } catch (EmptyData &) {
00101         emitError(report, "Shape", objecttype, objectid, "empty entry");
00102     }
00103     ok = false;
00104     return Boundary();
00105 }

Position2DVector GeomConvHelper::parseShapeReporting ( const std::string &  shpdef,
const char *  objecttype,
const char *  objectid,
bool ok,
bool  allowEmpty,
bool  report = true 
) throw () [static]

Builds a Position2DVector from a string representation, reporting occured errors.

It is assumed, the vector is stored as "x,y[ x,y]*" where x and y are SUMOReals.

Parameters:
[in] shpdef The shape definition to parse
[in] objecttype The name of the parsed object type; used for error message generation
[in] objectid The name of the parsed object; used for error message generation
[out] ok Whether the value could be read
[in] allowEmpty Whether an empty shape definition is valid
[in] report Whether errors shall be written to msg handler's error instance
Returns:
The parsed position vector

Definition at line 47 of file GeomConvHelper.cpp.

References TplConvert< E >::_2SUMOReal(), StringTokenizer::hasNext(), StringTokenizer::next(), Position2DVector::push_back(), and SUMOReal.

Referenced by NLHandler::addJunctionShape(), NIImporter_SUMO::addLane(), NLHandler::addLaneShape(), NLHandler::addPoly(), PCNetProjectionLoader::myCharacters(), PCLoaderXML::myCharacters(), NLHandler::myCharacters(), NIImporter_SUMO::myCharacters(), PCNetProjectionLoader::myStartElement(), NLHandler::openJunction(), NLHandler::setLocation(), and NIXMLEdgesHandler::tryGetShape().

00048                                                                                                           {
00049     if (shpdef=="") {
00050         if (!allowEmpty) {
00051             emitError(report, "Shape", objecttype, objectid, "the shape is empty");
00052             ok = false;
00053         }
00054         return Position2DVector();
00055     }
00056     StringTokenizer st(shpdef, " ");
00057     Position2DVector shape;
00058     while (st.hasNext()) {
00059         StringTokenizer pos(st.next(), ",");
00060         if (pos.size()%2!=0) {
00061             emitError(report, "Shape", objecttype, objectid, "the position is not made of two dimensions");
00062             ok = false;
00063             return Position2DVector();
00064         }
00065         try {
00066             SUMOReal x = TplConvert<char>::_2SUMOReal(pos.next().c_str());
00067             SUMOReal y = TplConvert<char>::_2SUMOReal(pos.next().c_str());
00068             shape.push_back(Position2D(x, y));
00069         } catch (NumberFormatException &) {
00070             emitError(report, "Shape", objecttype, objectid, "not numeric position entry");
00071             ok = false;
00072             return Position2DVector();
00073         } catch (EmptyData &) {
00074             emitError(report, "Shape", objecttype, objectid, "empty position entry");
00075             ok = false;
00076             return Position2DVector();
00077         }
00078     }
00079     return shape;
00080 }


The documentation for this class was generated from the following files:

Generated on Wed May 5 00:06:41 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6