Go to the documentation of this file.00001
00019 #ifndef __UTILS
00020
00021 #define __UTILS
00022
00023 #include <string>
00024 #include <cstdlib>
00025 #include <vector>
00026 #include <list>
00027 #include <utility>
00028
00029 #include <vecmath.h>
00030
00031 namespace robotLibPbD {
00032
00033 int getDirectoryFiles(std::string dir, std::vector<std::string> &files, bool appendDir = false);
00034 bool stringEndsWith(std::string text, std::string end, std::string sep = "_");
00035 bool stringStartsWith(std::string text, std::string end, std::string sep = "_");
00036 std::string strtrim(std::string& s,const std::string& drop = " ");
00037 std::string strreplace(const std::string &stringSearchString, const std::string &stringReplaceString, std::string stringStringToReplace);
00038 void strreplaceWithCondition(const std::string &stringSearchString, const std::string &stringReplaceString, std::string &stringStringToReplace, std::string condition = "");
00039 void strreplace(char* text, char what = '.', char with = ',');
00040 double strToDouble(const char* text, double value = 0.0);
00041 void strToArray(std::string text, std::vector<double> &result, std::string delimiter = " ");
00042
00043 std::string combineStrings(std::vector<std::string> &input, std::string delimiter = " ");
00044
00045 void strtokenize(const std::string& str,
00046 std::vector<std::string>& tokens,
00047 const std::string& delimiters);
00048
00049 void matrixToArray(const CMatrix &matrix, std::vector<double> &values);
00050 void arrayToMatrix(CMatrix &matrix, std::vector<double> &values);
00051
00052 void vectorToMatrix(CMatrix &matrix, const std::vector<double> &values);
00053 void vectorToMatrix6(CMatrix &matrix, const double* values);
00054 void matrixToVector(const CMatrix &matrix, std::vector<double> &values);
00055 void matrixToVector6(const CMatrix &matrix, double *values);
00056
00057 void getConvexHullXY(std::vector<CVec> &points, std::vector<CVec> &hull);
00058
00059 std::string printToString(const char* format, ...);
00060
00061 std::string boolToString(bool value);
00062
00063 template< typename T >
00064 bool inRange(std::vector<T> &array, T min, T max)
00065 {
00066 for (unsigned int i=0; i<array.size(); i++)
00067 if ((array[i] < min) || (array[i] > max))
00068 return false;
00069
00070 return true;
00071 };
00072
00073 template< typename T >
00074 bool isIncluded(std::vector<T> &array, T &value)
00075 {
00076 for (unsigned int i=0; i<array.size(); i++)
00077 if (array[i] == value)
00078 return true;
00079
00080 return false;
00081 };
00082
00083 template< typename T >
00084 std::string arrayToString(std::vector<T> &array)
00085 {
00086 std::string result;
00087 for (unsigned int i=0; i<array.size(); i++)
00088 result += printToString("%g ", (double)array[i]);
00089 return result;
00090 };
00091
00092
00093 template< typename T, typename S >
00094 bool comparePairs(const std::pair<T, S> &first, const std::pair<T, S> &second)
00095 {
00096 return first.first < second.first;
00097 };
00098
00099 template< typename T, typename S >
00100 bool comparePairsVector(const std::pair<T, S> &first, const std::pair<T, S> &second)
00101 {
00102 for (unsigned int i=0; i<first.first.size(); i++)
00103 if (first.first[i] < second.first[i])
00104 return true;
00105 else if (first.first[i] > second.first[i])
00106 return false;
00107
00108 return true;
00109 };
00110
00111 unsigned long getTickCount();
00112
00113
00114 std::string waitForReturn(std::string msg = "Press any key.\n");
00115 };
00116
00117
00118
00119 #endif