36 #ifndef CPPUTILS_OBJECT_H
37 #define CPPUTILS_OBJECT_H
110 static const string getOpSys();
116 static string stringReplaceAll(
const string& sf,
const string& sr,
122 static void removeEOL(
string& s);
128 static void addPathSeparator(
string& path);
134 static string insertPathSeparator(
const string& dir,
const string& name);
140 static void removePathSeparator(
string& path);
146 static string itos(
int i,
const string& frmt =
"%d");
147 static string ltos(
LONG_INT l,
const string& frmt =
"%llu");
148 static string ftos(
float f,
const string& frmt =
"%.6f");
149 static string dtos(
double d,
const string& frmt =
"%.14f");
150 static string btos(
bool b);
156 static int stoi(
const string& i,
const string& frmt =
"%d");
157 static LONG_INT stol(
const string& i64,
const string& frmt =
"%llu");
158 static float stof(
const string& f,
const string& frmt =
"%f");
159 static double stod(
const string& d,
const string& frmt =
"%lf");
160 static bool stob(
const string& b);
167 static string trim(
const string& str,
168 const string& delim =
" \t");
169 static string trimLeft(
const string& str,
170 const string& delim =
" \t");
171 static string trimRight(
const string& str,
172 const string& delim =
" \t");
189 static void getProperties(
const string& str,
190 map<string, string>& props);
204 static bool getProperty(
const map<string, string>& props,
205 const string& tag,
string& value);
214 static void tokenizeString(
const string& str,
const string& delim,
215 vector<string>& tokens);
221 static string lowercase_string(
const string& str);
222 static string uppercase_string(
const string& str);
227 template <
typename T>
228 static void minmax(
const vector<T>& v, T& mn, T& mx);
233 static double toDegrees(
double a);
238 static double toRadians(
double a);
243 template <
typename T>
247 for (
int i = 0; i < ni; ++i)
259 template <
typename T>
263 a[0] =
new T [ni*nj];
264 for (
int i=1; i<ni; ++i) a[i] = &a[0][i*nj];
276 template <
typename T>
279 T*** a =
new T** [ni];
280 a[0] =
new T* [ni*nj];
281 a[0][0] =
new T [ni*nj*nk];
282 for (
int i = 0; i < ni; ++i)
285 for (
int j = 0; j < nj; ++j)
286 a[i][j] = &a[0][0][(i*nj + j)*nk];
295 template <
typename T>
296 static void delete2DArray(T**& a);
301 template <
typename T>
306 for (
int i = 0; i < ni; ++i)
delete [] a[i];
315 template <
typename T>
316 static void delete3DArray(T***& a);
321 template <
typename T>
324 for (
int i = 0; i < n; ++i) array[i] = val;
330 template <
typename T>
334 for (
int i=0; i<n; ++i)
342 static bool isBigEndian();
347 static bool isint(
const string& i);
374 f.open(fileName.c_str(), ios::in);
392 inline double CPPUtils::toDegrees(
double a)
394 return RAD_TO_DEG * a;
402 inline double CPPUtils::toRadians(
double a)
404 return DEG_TO_RAD * a;
410 template <
typename T>
411 inline void CPPUtils::delete2DArray(T**& a)
424 template <
typename T>
425 inline void CPPUtils::delete3DArray(T***& a)
439 inline void CPPUtils::removeEOL(
string& s)
441 if (s.size() && (s[s.length() - 1] ==
'\n')) s.erase(s.length() - 1);
442 if (s.size() && (s[s.length() - 1] ==
'\r')) s.erase(s.length() - 1);
445 inline void CPPUtils::removePathSeparator(
string& s)
447 if (s.size() && (s[s.length() - 1] == CPPUtils::FILE_SEP)) s.erase(s.length() - 1);
450 inline void CPPUtils::addPathSeparator(
string& s)
452 if ( s.find_last_of(CPPUtils::FILE_SEP) != s.length() - 1 )
453 s += CPPUtils::FILE_SEP;
456 inline string CPPUtils::insertPathSeparator(
const string& dir,
const string& name)
461 while (path.size() && (path[path.length() - 1] == CPPUtils::FILE_SEP))
462 path.erase(path.length() - 1, 1);
464 if (path.length() > 0)
465 path = path+CPPUtils::FILE_SEP;
468 while (nm.size() && (nm[0] == CPPUtils::FILE_SEP))
469 nm.erase((
unsigned)0, 1);
477 template <
typename T>
478 void CPPUtils::minmax(
const vector<T>& v, T& mn, T& mx)
490 for (
int i = 1; i < v.size(); i++)
492 if (mn > v[i]) mn = v[i];
493 if (mx < v[i]) mx = v[i];
500 #endif // CPPUTILS_OBJECT_H
static const int SBYT
Definition: CPPUtils.h:353
static T ** new2DArray(int ni, int nj)
Returns a new intrinsic 2D array of size [ni][nj].
Definition: CPPUtils.h:260
static bool fileExists(const string &fileName)
Definition: CPPUtils.h:370
static void resetArray(int n, T *array, T val)
Resets all n entries in array to val.
Definition: CPPUtils.h:322
Definition: ArrayReuse.h:55
static T ** new2DArrayOfArrays(int ni, int nj)
Create a 2D array of arrays (Java style).
Definition: CPPUtils.h:244
virtual ~CPPUtils()
Protected destructor ...
Definition: CPPUtils.h:93
static string class_name()
Returns the class name.
Definition: CPPUtils.h:99
static const int SSHT
Definition: CPPUtils.h:354
Basic static utility functions and variables.
Definition: CPPUtils.h:69
static char const FILE_SEP
Path separator.
Definition: CPPUtils.h:363
static T *** new3DArray(int ni, int nj, int nk)
Returns a new intrinsic 3D array of size [ni][nj].
Definition: CPPUtils.h:277
CPPUtils()
Default constructor.
Definition: CPPUtils.h:88
static void delete2DArrayOfArrays(T **&a, int ni)
Deletes the input 2D array of arrays reference and sets it to null.
Definition: CPPUtils.h:302
static const int SBOL
Standard sizes of basic intrinsics.
Definition: CPPUtils.h:352
static T * copyArray(T *a, int n)
Return a deep copy of the specified array.
Definition: CPPUtils.h:331
static const int SDBL
Definition: CPPUtils.h:358
#define LONG_INT
Definition: CPPGlobals.h:111
static string const NEWLINE
End-of-line string.
Definition: CPPUtils.h:368
static const int SLNG
Definition: CPPUtils.h:356
static const int SINT
Definition: CPPUtils.h:355
#define GEOTESS_EXP_IMP
Definition: CPPGlobals.h:71
virtual int class_size() const
Returns the class size.
Definition: CPPUtils.h:104
static const int SFLT
Definition: CPPUtils.h:357