TplConvertSec.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Some conversion methods (from strings to other)
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 #ifndef TplConvertSec_h
00020 #define TplConvertSec_h
00021 
00022 
00023 // ===========================================================================
00024 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 #include <string>
00033 #include "TplConvert.h"
00034 
00035 
00036 // ===========================================================================
00037 // class definitions
00038 // ===========================================================================
00046 template<class E>
00047 class TplConvertSec {
00048 public:
00049     // conversion methods not throwing an exeption without a length
00052     static std::string _2strSec(const E * const data,
00053                                 const std::string &def) {
00054         return _2strSec(data, TplConvert<E>::getLength(data), def);
00055     }
00056 
00057 
00061     static int _2intSec(const E * const data, int def) {
00062         return _2intSec(data, INT_MAX, def);
00063     }
00064 
00065 
00069     static long _2longSec(const E * const data, long def) {
00070         return _2longSec(data, INT_MAX, def);
00071     }
00072 
00073 
00077     static SUMOReal _2SUMORealSec(const E * const data, SUMOReal def) {
00078         return _2SUMORealSec(data, INT_MAX, def);
00079     }
00080 
00081 
00086     static bool _2boolSec(const E * const data, bool def) {
00087         return _2boolSec(data, 1, def);
00088     }
00089 
00090 
00094     static char *_2charpSec(const E * const data, char *def) {
00095         return _2charpSec(data, TplConvert<E>::getLength(data), def);
00096     }
00097 
00098 
00099     // conversion not throwing an exception methods with a length
00103     static std::string _2strSec(const E * const data, int length,
00104                                 const std::string &def) {
00105         if (data==0||length==0) {
00106             return def;
00107         }
00108         return TplConvert<E>::_2str(data, length);
00109     }
00110 
00111 
00115     static int _2intSec(const E * const data, int length, int def) {
00116         if (data==0||length==0||data[0]==0) {
00117             return def;
00118         }
00119         return TplConvert<E>::_2int(data, length);
00120     }
00121 
00122 
00126     static long _2longSec(const E * const data, int length, long def) {
00127         if (data==0||length==0||data[0]==0) {
00128             return def;
00129         }
00130         return TplConvert<E>::_2long(data, length);
00131     }
00132 
00133 
00137     static SUMOReal _2SUMORealSec(const E * const data, int length, SUMOReal def) {
00138         if (data==0||length==0||data[0]==0) {
00139             return def;
00140         }
00141         return TplConvert<E>::_2SUMOReal(data, length);
00142     }
00143 
00144 
00148     static bool _2boolSec(const E * const data, int length, bool def) {
00149         if (data==0||length==0||data[0]==0) {
00150             return def;
00151         }
00152         return TplConvert<E>::_2bool(data, length);
00153     }
00154 
00155 
00159     static char *_2charpSec(const E * const data, int length, char *def) {
00160         if (data==0||length==0) {
00161             return TplConvert<E>::copy(def);
00162         }
00163         return TplConvert<E>::_2charp(data, length);
00164     }
00165 
00166 
00167 };
00168 
00169 
00170 #endif
00171 
00172 /****************************************************************************/
00173 

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