utils.h
Go to the documentation of this file.
1 
19 #ifndef __UTILS
20 
21 #define __UTILS
22 
23 #include <string>
24 #include <cstdlib>
25 #include <vector>
26 #include <list>
27 #include <utility>
28 
29 #include <vecmath.h>
30 
31 namespace robotLibPbD {
32 
33 int getDirectoryFiles(std::string dir, std::vector<std::string> &files, bool appendDir = false);
34 bool stringEndsWith(std::string text, std::string end, std::string sep = "_");
35 bool stringStartsWith(std::string text, std::string end, std::string sep = "_");
36 std::string strtrim(std::string& s,const std::string& drop = " ");
37 std::string strreplace(const std::string &stringSearchString, const std::string &stringReplaceString, std::string stringStringToReplace);
38 void strreplaceWithCondition(const std::string &stringSearchString, const std::string &stringReplaceString, std::string &stringStringToReplace, std::string condition = "");
39 void strreplace(char* text, char what = '.', char with = ',');
40 double strToDouble(const char* text, double value = 0.0);
41 void strToArray(std::string text, std::vector<double> &result, std::string delimiter = " ");
42 
43  std::string combineStrings(std::vector<std::string> &input, std::string delimiter = " ");
44 
45 void strtokenize(const std::string& str,
46  std::vector<std::string>& tokens,
47  const std::string& delimiters);
48 
49 void matrixToArray(const CMatrix &matrix, std::vector<double> &values);
50 void arrayToMatrix(CMatrix &matrix, std::vector<double> &values);
51 
52 void vectorToMatrix(CMatrix &matrix, const std::vector<double> &values);
53 void vectorToMatrix6(CMatrix &matrix, const double* values);
54 void matrixToVector(const CMatrix &matrix, std::vector<double> &values);
55 void matrixToVector6(const CMatrix &matrix, double *values);
56 
57 void getConvexHullXY(std::vector<CVec> &points, std::vector<CVec> &hull);
58 
59 std::string printToString(const char* format, ...);
60 
61 std::string boolToString(bool value);
62 
63 template< typename T >
64  bool inRange(std::vector<T> &array, T min, T max)
65 {
66  for (unsigned int i=0; i<array.size(); i++)
67  if ((array[i] < min) || (array[i] > max))
68  return false;
69 
70  return true;
71 };
72 
73 template< typename T >
74 bool isIncluded(std::vector<T> &array, T &value)
75 {
76  for (unsigned int i=0; i<array.size(); i++)
77  if (array[i] == value)
78  return true;
79 
80  return false;
81 };
82 
83 template< typename T >
84 std::string arrayToString(std::vector<T> &array)
85 {
86  std::string result;
87  for (unsigned int i=0; i<array.size(); i++)
88  result += printToString("%g ", (double)array[i]);
89  return result;
90 };
91 
92 
93 template< typename T, typename S >
94 bool comparePairs(const std::pair<T, S> &first, const std::pair<T, S> &second)
95 {
96  return first.first < second.first;
97 };
98 
99 template< typename T, typename S >
100 bool comparePairsVector(const std::pair<T, S> &first, const std::pair<T, S> &second)
101 {
102  for (unsigned int i=0; i<first.first.size(); i++)
103  if (first.first[i] < second.first[i])
104  return true;
105  else if (first.first[i] > second.first[i])
106  return false;
107 
108  return true;
109 };
110 
111 unsigned long getTickCount();
112 
113 
114 std::string waitForReturn(std::string msg = "Press any key.\n");
115 };
116 
117 
118 
119 #endif
void strtokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters)
Definition: utils.cpp:87
double strToDouble(const char *text, double value=0.0)
Definition: utils.cpp:317
bool comparePairsVector(const std::pair< T, S > &first, const std::pair< T, S > &second)
Definition: utils.h:100
std::string printToString(const char *format,...)
Definition: utils.cpp:149
std::string waitForReturn(std::string msg="Press any key.\n")
Definition: utils.cpp:37
bool inRange(std::vector< T > &array, T min, T max)
Definition: utils.h:64
std::string combineStrings(std::vector< std::string > &input, std::string delimiter=" ")
Definition: utils.cpp:46
std::string strtrim(std::string &s, const std::string &drop=" ")
Definition: utils.cpp:331
void vectorToMatrix6(CMatrix &matrix, const double *values)
Definition: utils.cpp:237
std::string strreplace(const std::string &stringSearchString, const std::string &stringReplaceString, std::string stringStringToReplace)
Definition: utils.cpp:110
int getDirectoryFiles(std::string dir, std::vector< std::string > &files, bool appendDir=false)
Definition: utils.cpp:60
std::string arrayToString(std::vector< T > &array)
Definition: utils.h:84
bool stringEndsWith(std::string text, std::string end, std::string sep="_")
Definition: utils.cpp:228
std::string boolToString(bool value)
Definition: utils.cpp:85
void matrixToVector6(const CMatrix &matrix, double *values)
Definition: utils.cpp:304
void vectorToMatrix(CMatrix &matrix, const std::vector< double > &values)
Definition: utils.cpp:255
bool comparePairs(const std::pair< T, S > &first, const std::pair< T, S > &second)
Definition: utils.h:94
bool isIncluded(std::vector< T > &array, T &value)
Definition: utils.h:74
void strToArray(std::string text, std::vector< double > &result, std::string delimiter=" ")
Definition: utils.cpp:161
bool stringStartsWith(std::string text, std::string end, std::string sep="_")
Definition: utils.cpp:218
void getConvexHullXY(std::vector< CVec > &points, std::vector< CVec > &hull)
Definition: utils.cpp:360
void matrixToArray(const CMatrix &matrix, std::vector< double > &values)
Definition: utils.cpp:176
void matrixToVector(const CMatrix &matrix, std::vector< double > &values)
Definition: utils.cpp:290
void arrayToMatrix(CMatrix &matrix, std::vector< double > &values)
Definition: utils.cpp:195
unsigned long getTickCount()
Definition: utils.cpp:351
void strreplaceWithCondition(const std::string &stringSearchString, const std::string &stringReplaceString, std::string &stringStringToReplace, std::string condition="")
Definition: utils.cpp:125


asr_kinematic_chain_optimizer
Author(s): Aumann Florian, Heller Florian, Jäkel Rainer, Wittenbeck Valerij
autogenerated on Mon Jun 10 2019 12:35:36