SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TplConvertSec.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // Some conversion methods (from strings to other)
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
11 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 #ifndef TplConvertSec_h
22 #define TplConvertSec_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include "TplConvert.h"
36 
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
48 template<class E>
50 public:
51  // conversion methods not throwing an exeption without a length
54  static std::string _2strSec(const E* const data,
55  const std::string& def) {
56  return _2strSec(data, TplConvert<E>::getLength(data), def);
57  }
58 
59 
63  static int _2intSec(const E* const data, int def) {
64  return _2intSec(data, INT_MAX, def);
65  }
66 
67 
71  static long _2longSec(const E* const data, long def) {
72  return _2longSec(data, INT_MAX, def);
73  }
74 
75 
79  static SUMOReal _2SUMORealSec(const E* const data, SUMOReal def) {
80  return _2SUMORealSec(data, INT_MAX, def);
81  }
82 
83 
88  static bool _2boolSec(const E* const data, bool def) {
89  return _2boolSec(data, 1, def);
90  }
91 
92 
96  static char* _2charpSec(const E* const data, char* def) {
97  return _2charpSec(data, TplConvert<E>::getLength(data), def);
98  }
99 
100 
101  // conversion not throwing an exception methods with a length
105  static std::string _2strSec(const E* const data, int length,
106  const std::string& def) {
107  if (data == 0 || length == 0) {
108  return def;
109  }
110  return TplConvert<E>::_2str(data, length);
111  }
112 
113 
117  static int _2intSec(const E* const data, int length, int def) {
118  if (data == 0 || length == 0 || data[0] == 0) {
119  return def;
120  }
121  return TplConvert<E>::_2int(data, length);
122  }
123 
124 
128  static long _2longSec(const E* const data, int length, long def) {
129  if (data == 0 || length == 0 || data[0] == 0) {
130  return def;
131  }
132  return TplConvert<E>::_2long(data, length);
133  }
134 
135 
139  static SUMOReal _2SUMORealSec(const E* const data, int length, SUMOReal def) {
140  if (data == 0 || length == 0 || data[0] == 0) {
141  return def;
142  }
143  return TplConvert<E>::_2SUMOReal(data, length);
144  }
145 
146 
150  static bool _2boolSec(const E* const data, int length, bool def) {
151  if (data == 0 || length == 0 || data[0] == 0) {
152  return def;
153  }
154  return TplConvert<E>::_2bool(data, length);
155  }
156 
157 
161  static char* _2charpSec(const E* const data, int length, char* def) {
162  if (data == 0 || length == 0) {
163  return TplConvert<E>::copy(def);
164  }
165  return TplConvert<E>::_2charp(data, length);
166  }
167 
168 
169 };
170 
171 
172 #endif
173 
174 /****************************************************************************/
175