36 #ifndef CPPUTILS_OBJECT_H
37 #define CPPUTILS_OBJECT_H
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");
148 static string ftos(
float f,
const string& frmt =
"%.6f");
149 static string dtos(
double d,
const string& frmt =
"%.14f");
156 static int stoi(
const string& i,
const string& frmt =
"%d");
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");
170 const string& delim =
" \t");
172 const string& delim =
" \t");
190 map<string, string>& props);
205 const string& tag,
string& value);
215 vector<string>& tokens);
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)
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];
Basic static utility functions and variables.
static const string getOpSys()
static string lowercase_string(const string &str)
static string dtos(double d, const string &frmt="%.14f")
static bool isint(const string &i)
static LONG_INT stol(const string &i64, const string &frmt="%llu")
static bool stob(const string &b)
virtual int class_size() const
static float stof(const string &f, const string &frmt="%f")
static string const NEWLINE
static string trim(const string &str, const string &delim=" \t")
static T ** new2DArray(int ni, int nj)
static string stringReplaceAll(const string &sf, const string &sr, const string &s)
static double stod(const string &d, const string &frmt="%lf")
static bool getProperty(const map< string, string > &props, const string &tag, string &value)
static bool fileExists(const string &fileName)
static char const FILE_SEP
static T * copyArray(T *a, int n)
static string itos(int i, const string &frmt="%d")
static string class_name()
static T ** new2DArrayOfArrays(int ni, int nj)
static string trimRight(const string &str, const string &delim=" \t")
static T *** new3DArray(int ni, int nj, int nk)
static string ltos(LONG_INT l, const string &frmt="%llu")
static void tokenizeString(const string &str, const string &delim, vector< string > &tokens)
static string btos(bool b)
static void resetArray(int n, T *array, T val)
static string uppercase_string(const string &str)
static void getProperties(const string &str, map< string, string > &props)
static void delete2DArrayOfArrays(T **&a, int ni)
static bool isBigEndian()
static string trimLeft(const string &str, const string &delim=" \t")
static int stoi(const string &i, const string &frmt="%d")
static string ftos(float f, const string &frmt="%.6f")