TplConvert< E > Class Template Reference

#include <TplConvert.h>


Detailed Description

template<class E>
class TplConvert< E >

TplConvert Some methods that convert 0-terminated char-arrays of any type into other values (numerical/boolean) or into std::strings

Definition at line 48 of file TplConvert.h.


Static Public Member Functions

static bool _2bool (const E *const data, unsigned length)
static bool _2bool (const E *const data)
static char * _2charp (const E *const data, int length)
static char * _2charp (const E *const data)
static int _2int (const E *const data, unsigned length)
static int _2int (const E *const data)
static long _2long (const E *const data, unsigned length)
static long _2long (const E *const data)
static std::string _2str (const E *const data, unsigned length)
static std::string _2str (const E *const data)
static SUMOReal _2SUMOReal (const E *const data, unsigned length)
static SUMOReal _2SUMOReal (const E *const data)
static unsigned getLength (const E *const data)

Member Function Documentation

template<class E>
static bool TplConvert< E >::_2bool ( const E *const   data,
unsigned  length 
) [inline, static]

converts a char-type array into the SUMOReal value described by it considering the given length returns true when the first char is one of the following: '1', 'x', 't', 'T' throws an EmptyData - exception if the given string is empty

Definition at line 275 of file TplConvert.h.

00275                                                               {
00276         if (data==0||length==0||data[0]==0) {
00277             throw EmptyData();
00278         }
00279         char akt = (char) data[0];
00280         if (akt=='1' || akt=='x' || akt=='t' || akt=='T') {
00281             return true;
00282         }
00283         if (akt=='0' || akt=='-' || akt=='f' || akt=='F') {
00284             return false;
00285         }
00286         throw BoolFormatException();
00287     }

template<class E>
static bool TplConvert< E >::_2bool ( const E *const   data  )  [inline, static]

converts a 0-terminated char-type array into the SUMOReal value described by it returns true when the first char is one of the following: '1', 'x', 't', 'T' throws an EmptyData - exception if the given string is empty

Definition at line 93 of file TplConvert.h.

Referenced by TplConvertSec< E >::_2boolSec(), SUMOSAXAttributesImpl_Xerces::getBool(), NIImporter_VISUM::getWeightedBool(), GUISettingsHandler::myStartElement(), NIImporter_VISUM::parse_Edges(), and NIImporter_VISUM::parse_TrafficLights().

00093                                              {
00094         return _2bool(data, 1);
00095     }

template<class E>
static char* TplConvert< E >::_2charp ( const E *const   data,
int  length 
) [inline, static]

converts a char-type array into a 0-terminated 0-terminated c-char-string considering the given length throws an EmptyData - exception if the given string is empty

Definition at line 293 of file TplConvert.h.

00293                                                            {
00294         if (length==0||data==0) {
00295             throw EmptyData();
00296         }
00297         char *ret = new char[length+1];
00298         unsigned i = 0;
00299         for (; i<length; i++) {
00300             ret[i] = (char) data[i];
00301         }
00302         ret[i] = 0;
00303         return ret;
00304     }

template<class E>
static char* TplConvert< E >::_2charp ( const E *const   data  )  [inline, static]

converts a 0-terminated char-type array into a 0-terminated 0-terminated c-char-string throws an EmptyData - exception if the given string is empty

Definition at line 101 of file TplConvert.h.

References TplConvert< E >::getLength().

Referenced by TplConvertSec< E >::_2charpSec().

00101                                                {
00102         return _2charp(data, getLength(data));
00103     }

template<class E>
static int TplConvert< E >::_2int ( const E *const   data,
unsigned  length 
) [inline, static]

converts a char-type array into the integer value described by it considering the given length throws an EmptyData - exception if the given string is empty throws a NumberFormatException - exception when the string does not contain an integer

Definition at line 134 of file TplConvert.h.

00134                                                             {
00135         if (data==0||length==0||data[0]==0) {
00136             throw EmptyData();
00137         }
00138         int sgn = 1;
00139         unsigned i=0;
00140         if (data[0]=='+') {
00141             i++;
00142         }
00143         if (data[0]=='-') {
00144             i++;
00145             sgn = -1;
00146         }
00147         int val = 0;
00148         for (; i<length&&data[i]!=0; i++) {
00149             val = val * 10;
00150             char akt = (char) data[i];
00151             if (akt<'0'||akt>'9') {
00152                 throw NumberFormatException();
00153             }
00154             val = val + akt - 48;
00155         }
00156         if (i==0) {
00157             throw EmptyData();
00158         }
00159         return val * sgn;
00160     }

template<class E>
static int TplConvert< E >::_2int ( const E *const   data  )  [inline, static]

converts a 0-terminated char-type array into the integer value described by it throws an EmptyData - exception if the given string is empty throws a NumberFormatException - exception when the string does not contain an integer

Definition at line 63 of file TplConvert.h.

Referenced by TplConvertSec< E >::_2intSec(), TplConvert< E >::_2SUMOReal(), NIImporter_SUMO::addSuccEdge(), SUMOVehicleParameter::arrivallaneValidate(), SUMOVehicleParameter::departlaneValidate(), OutputDevice::getDevice(), SUMOSAXAttributesImpl_Xerces::getInt(), NINavTeqHelper::getLaneNumber(), NINavTeqHelper::getSpeed(), getVehicleEmissionTypeID(), PCLoaderVisum::load(), NIImporter_SUMO::loadNetwork(), NIXMLEdgesHandler::myStartElement(), NIImporter_OpenStreetMap::EdgesHandler::myStartElement(), GUISettingsHandler::myStartElement(), GUIDialog_Breakpoints::onCmdEditTable(), GUIDialog_Breakpoints::onCmdLoad(), NIVissimSingleTypeParser_VWunschentscheidungsdefinition::parse(), NIVissimSingleTypeParser_Verbindungsdefinition::parse(), NIVissimSingleTypeParser_Streckendefinition::parse(), NIVissimSingleTypeParser_Knotendefinition::parse(), NIVissimSingleTypeParser_Fahrzeugtypdefinition::parse(), NIVissimSingleTypeParser_Fahrzeugklassendefinition::parse(), NIImporter_VISUM::parse_AreaSubPartElement(), NIImporter_VISUM::parse_EdgePolys(), NIImporter_VISUM::parse_Lanes(), NIImporter_VISUM::parse_LanesConnections(), NIImporter_VISUM::parse_Types(), SUMOVehicleParserHelper::parseCommonAttributes(), NIVissimSingleTypeParser_Querverkehrsstoerungsdefinition::parsePos(), parseSingleTime(), NIXMLEdgesHandler::parseSplitLanes(), parseTimeLine(), RODFDetFlowLoader::read(), NIImporter_Vissim::VissimSingleTypeParser::readExtEdgePointDef(), readO(), readV(), NIImporter_DlrNavteq::EdgesHandler::report(), Option_Integer::set(), and string2time().

00063                                            {
00064         return _2int(data, INT_MAX);
00065     }

template<class E>
static long TplConvert< E >::_2long ( const E *const   data,
unsigned  length 
) [inline, static]

converts a char-type array into the long value described by it considering the given length throws an EmptyData - exception if the given string is empty throws a NumberFormatException - exception when the string does not contain a long

Definition at line 168 of file TplConvert.h.

00168                                                               {
00169         if (data==0||length==0||data[0]==0) {
00170             throw EmptyData();
00171         }
00172         long sgn = 1;
00173         unsigned i=0;
00174         if (data[0]=='+') {
00175             i++;
00176         }
00177         if (data[0]=='-') {
00178             i++;
00179             sgn = -1;
00180         }
00181         long ret = 0;
00182         for (; i<length&&data[i]!=0; i++) {
00183             ret = ret * 10;
00184             char akt = (char) data[i];
00185             if (akt<'0'||akt>'9') {
00186                 throw NumberFormatException();
00187             }
00188             ret = ret + akt - 48;
00189         }
00190         if (i==0) {
00191             throw EmptyData();
00192         }
00193         return ret * sgn;
00194     }

template<class E>
static long TplConvert< E >::_2long ( const E *const   data  )  [inline, static]

converts a 0-terminated char-type array into the long value described by it throws an EmptyData - exception if the given string is empty throws a NumberFormatException - exception when the string does not contain a long

Definition at line 73 of file TplConvert.h.

Referenced by TplConvertSec< E >::_2longSec(), PCLoaderVisum::load(), NIImporter_VISUM::parse_AreaSubPartElement(), NIImporter_VISUM::parse_Districts(), NIImporter_VISUM::parse_Kante(), NIImporter_VISUM::parse_PartOfArea(), and NIImporter_VISUM::parse_Point().

00073                                              {
00074         return _2long(data, INT_MAX);
00075     }

template<class E>
static std::string TplConvert< E >::_2str ( const E *const   data,
unsigned  length 
) [inline, static]

converts a char-type array into std::string considering the given length throws an EmptyData - exception if the given string is empty

Definition at line 110 of file TplConvert.h.

00110                                                                   {
00111         if (data==0) {
00112             throw EmptyData();
00113         }
00114         if (length==0) {
00115             return "";
00116         }
00117         char *buf = new char[length+1];
00118         unsigned i = 0;
00119         for (i=0; i<length; i++) {
00120             buf[i] = (char) data[i];
00121         }
00122         buf[i] = 0;
00123         std::string ret = buf;
00124         delete[] buf;
00125         return ret;
00126     }

template<class E>
static std::string TplConvert< E >::_2str ( const E *const   data  )  [inline, static]

converts a 0-terminated char-type array into std::string throws an EmptyData - exception if the given string is empty

Definition at line 53 of file TplConvert.h.

References TplConvert< E >::getLength().

Referenced by TplConvertSec< E >::_2strSec(), OptionsLoader::characters(), GenericSAXHandler::endElement(), SUMOSAXAttributesImpl_Xerces::getString(), NILoader::loadXMLType(), OptionsLoader::startElement(), and GenericSAXHandler::startElement().

00053                                                  {
00054         return _2str(data, getLength(data));
00055     }

template<class E>
static SUMOReal TplConvert< E >::_2SUMOReal ( const E *const   data,
unsigned  length 
) [inline, static]

converts a char-type array into the SUMOReal value described by it considering the given length throws an EmptyData - exception if the given string is empty throws a NumberFormatException - exception when the string does not contain a SUMOReal

Definition at line 202 of file TplConvert.h.

References TplConvert< E >::_2int(), and SUMOReal.

00202                                                                       {
00203         if (data==0||length==0||data[0]==0) {
00204             throw EmptyData();
00205         }
00206         SUMOReal ret = 0;
00207         unsigned i = 0;
00208         SUMOReal sgn = 1;
00209         if (data[0]=='+') {
00210             i++;
00211         }
00212         if (data[0]=='-') {
00213             i++;
00214             sgn = -1;
00215         }
00216         for (; i<length&&data[i]!=0&&data[i]!='.'&&data[i]!=','&&data[i]!='e'&&data[i]!='E'; i++) {
00217             ret = ret * 10;
00218             char akt = (char) data[i];
00219             if (akt<'0'||akt>'9') {
00220                 throw NumberFormatException();
00221             }
00222             ret = ret + akt - 48;
00223         }
00224         // check what has happened - end of string, e or decimal point
00225         if ((char) data[i]!='.'&&(char) data[i]!=','&&data[i]!='e'&&data[i]!='E') {
00226             if (i==0) {
00227                 throw EmptyData();
00228             }
00229             return ret * sgn;
00230         }
00231         if (data[i]=='e'||data[i]=='E') {
00232             // no decimal point, just an exponent
00233             try {
00234                 int exp = _2int(data+i+1, length-i-1);
00235                 SUMOReal exp2 = (SUMOReal) pow(10.0, exp);
00236                 return ret*sgn*exp2;
00237             } catch (EmptyData&) {
00238                 // the exponent was empty
00239                 throw NumberFormatException();
00240             }
00241         }
00242         SUMOReal div = 10;
00243         // skip the dot
00244         i++;
00245         // parse values behin decimal point
00246         for (; i<length&&data[i]!=0&&data[i]!='e'&&data[i]!='E'; i++) {
00247             char akt = (char) data[i];
00248             if (akt<'0'||akt>'9') {
00249                 throw NumberFormatException();
00250             }
00251             ret = ret + ((SUMOReal)(akt - 48)) / div;
00252             div = div * 10;
00253         }
00254         if (data[i]!='e'&&data[i]!='E') {
00255             // no exponent
00256             return ret * sgn;
00257         }
00258         // eponent and decimal dot
00259         try {
00260             int exp = _2int(data+i+1, length-i-1);
00261             SUMOReal exp2 = (SUMOReal) pow(10.0, exp);
00262             return ret*sgn*exp2;
00263         } catch (EmptyData&) {
00264             // the exponent was empty
00265             throw NumberFormatException();
00266         }
00267     }

template<class E>
static SUMOReal TplConvert< E >::_2SUMOReal ( const E *const   data  )  [inline, static]

converts a 0-terminated char-type array into the SUMOReal value described by it throws an EmptyData - exception if the given string is empty throws a NumberFormatException - exception when the string does not contain a SUMOReal

Definition at line 83 of file TplConvert.h.

Referenced by TplConvertSec< E >::_2SUMORealSec(), SUMOVehicleParameter::arrivalposValidate(), SUMOVehicleParameter::arrivalspeedValidate(), SUMOVehicleParameter::departposValidate(), SUMOVehicleParameter::departspeedValidate(), SUMOSAXAttributesImpl_Xerces::getFloat(), MSTLLogicControl::WAUTSwitchProcedure::getGSPValue(), NIImporter_VISUM::getNamedFloat(), MSTLLogicControl::WAUTSwitchProcedure_Stretch::getStretchBereichDef(), getTurningDefaults(), NIImporter_VISUM::getWeightedFloat(), MSAgentbasedTrafficLightLogic::init(), MSActuatedTrafficLightLogic::init(), PCLoaderVisum::load(), PCLoaderDlrNavteq::loadPolyFile(), NIImporter_OpenStreetMap::EdgesHandler::myStartElement(), GUISettingsHandler::myStartElement(), GUIDialog_ViewSettings::onCmdEditTable(), NIVissimSingleTypeParser_Zuflussdefinition::parse(), NIVissimSingleTypeParser_Zeitenverteilungsdefinition::parse(), NIVissimSingleTypeParser_Verbindungsdefinition::parse(), NIVissimSingleTypeParser_Streckendefinition::parse(), NIVissimSingleTypeParser_Simdauer::parse(), NIVissimSingleTypeParser_Laengenverteilungsdefinition::parse(), NIVissimSingleTypeParser_Geschwindigkeitsverteilungsdefinition::parse(), NIImporter_VISUM::parse_Lanes(), NIImporter_VISUM::parse_Point(), GeomConvHelper::parseBoundaryReporting(), RGBColor::parseColor(), SUMOVehicleParserHelper::parseCommonAttributes(), GeomConvHelper::parseShapeReporting(), parseTimeLine(), RODFDetFlowLoader::read(), readFactor(), readO(), readV(), NIImporter_DlrNavteq::EdgesHandler::report(), and Option_Float::set().

00083                                                      {
00084         return _2SUMOReal(data, INT_MAX);
00085     }

template<class E>
static unsigned TplConvert< E >::getLength ( const E *const   data  )  [inline, static]

returns the length of the string (the position of the 0-character)

Definition at line 308 of file TplConvert.h.

Referenced by TplConvert< E >::_2charp(), and TplConvert< E >::_2str().

00308                                                     {
00309         if (data==0) {
00310             return 0;
00311         }
00312         unsigned i = 0;
00313         for (; data[i]!=0; i++);
00314         return i;
00315     }


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

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