SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00008 // Some conversion methods (from strings to other) 00009 /****************************************************************************/ 00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00012 /****************************************************************************/ 00013 // 00014 // This file is part of SUMO. 00015 // SUMO is free software: you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation, either version 3 of the License, or 00018 // (at your option) any later version. 00019 // 00020 /****************************************************************************/ 00021 #ifndef TplConvertSec_h 00022 #define TplConvertSec_h 00023 00024 00025 // =========================================================================== 00026 // included modules 00027 // =========================================================================== 00028 #ifdef _MSC_VER 00029 #include <windows_config.h> 00030 #else 00031 #include <config.h> 00032 #endif 00033 00034 #include <string> 00035 #include "TplConvert.h" 00036 00037 00038 // =========================================================================== 00039 // class definitions 00040 // =========================================================================== 00048 template<class E> 00049 class TplConvertSec { 00050 public: 00051 // conversion methods not throwing an exeption without a length 00054 static std::string _2strSec(const E* const data, 00055 const std::string& def) { 00056 return _2strSec(data, TplConvert<E>::getLength(data), def); 00057 } 00058 00059 00063 static int _2intSec(const E* const data, int def) { 00064 return _2intSec(data, INT_MAX, def); 00065 } 00066 00067 00071 static long _2longSec(const E* const data, long def) { 00072 return _2longSec(data, INT_MAX, def); 00073 } 00074 00075 00079 static SUMOReal _2SUMORealSec(const E* const data, SUMOReal def) { 00080 return _2SUMORealSec(data, INT_MAX, def); 00081 } 00082 00083 00088 static bool _2boolSec(const E* const data, bool def) { 00089 return _2boolSec(data, 1, def); 00090 } 00091 00092 00096 static char* _2charpSec(const E* const data, char* def) { 00097 return _2charpSec(data, TplConvert<E>::getLength(data), def); 00098 } 00099 00100 00101 // conversion not throwing an exception methods with a length 00105 static std::string _2strSec(const E* const data, int length, 00106 const std::string& def) { 00107 if (data == 0 || length == 0) { 00108 return def; 00109 } 00110 return TplConvert<E>::_2str(data, length); 00111 } 00112 00113 00117 static int _2intSec(const E* const data, int length, int def) { 00118 if (data == 0 || length == 0 || data[0] == 0) { 00119 return def; 00120 } 00121 return TplConvert<E>::_2int(data, length); 00122 } 00123 00124 00128 static long _2longSec(const E* const data, int length, long def) { 00129 if (data == 0 || length == 0 || data[0] == 0) { 00130 return def; 00131 } 00132 return TplConvert<E>::_2long(data, length); 00133 } 00134 00135 00139 static SUMOReal _2SUMORealSec(const E* const data, int length, SUMOReal def) { 00140 if (data == 0 || length == 0 || data[0] == 0) { 00141 return def; 00142 } 00143 return TplConvert<E>::_2SUMOReal(data, length); 00144 } 00145 00146 00150 static bool _2boolSec(const E* const data, int length, bool def) { 00151 if (data == 0 || length == 0 || data[0] == 0) { 00152 return def; 00153 } 00154 return TplConvert<E>::_2bool(data, length); 00155 } 00156 00157 00161 static char* _2charpSec(const E* const data, int length, char* def) { 00162 if (data == 0 || length == 0) { 00163 return TplConvert<E>::copy(def); 00164 } 00165 return TplConvert<E>::_2charp(data, length); 00166 } 00167 00168 00169 }; 00170 00171 00172 #endif 00173 00174 /****************************************************************************/ 00175