00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029
00030 #include <string>
00031 #include <sstream>
00032 #include <utils/geom/Position2DVector.h>
00033 #include <utils/common/MsgHandler.h>
00034 #include <utils/common/StringTokenizer.h>
00035 #include <utils/common/TplConvert.h>
00036 #include "GeomConvHelper.h"
00037
00038 #ifdef CHECK_MEMORY_LEAKS
00039 #include <foreign/nvwa/debug_new.h>
00040 #endif // CHECK_MEMORY_LEAKS
00041
00042
00043
00044
00045
00046 Position2DVector
00047 GeomConvHelper::parseShapeReporting(const std::string &shpdef, const char *objecttype,
00048 const char *objectid, bool &ok, bool allowEmpty, bool report) throw() {
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 }
00081
00082
00083 Boundary
00084 GeomConvHelper::parseBoundaryReporting(const std::string &def, const char *objecttype,
00085 const char *objectid, bool &ok, bool report) throw() {
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 }
00106
00107
00108 void
00109 GeomConvHelper::emitError(bool report, const std::string &what, const char *objecttype,
00110 const char *objectid, const std::string &desc) throw() {
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 }
00130
00131
00132
00133
00134