21 #ifndef MARS_UTILS_MISC_H 22 #define MARS_UTILS_MISC_H 25 #include <sys/timeb.h> 46 {
return r * 57.295779513082320876798154814105; }
48 {
return r * 57.295779513082320876798154814105f; }
56 {
return d * 0.017453292519943295769236907685; }
58 {
return d * 0.017453292519943295769236907685f; }
63 std::ostringstream ss;
75 return (
long long)(timer.time*1000LL + timer.millitm);
78 gettimeofday(&timer, NULL);
79 return ((
long long)(timer.tv_sec))*1000LL + ((long)(timer.tv_usec))/1000;
96 inline void msleep(
unsigned int milliseconds) {
98 ::Sleep(milliseconds);
100 static const unsigned int milliToMicro = 1000;
101 ::usleep(milliseconds * milliToMicro);
114 return (_access(path.c_str(), 0) == 0);
116 return (access(path.c_str(), F_OK) == 0);
138 bool matchPattern(
const std::string &pattern,
const std::string &str);
143 std::string
trim(
const std::string& str);
146 std::string
pathJoin(
const std::string &path1,
const std::string &path2);
177 std::vector<std::string>
explodeString(
const char c,
const std::string &s);
179 std::string
replaceString(
const std::string &source,
const std::string &s1,
180 const std::string &s2);
182 std::string
toupper(
const std::string &s);
183 std::string
tolower(
const std::string &s);
std::string getFilenameSuffix(const std::string &file)
given a filename "foobar.baz" this will return ".baz"
std::string pathJoin(const std::string &path1, const std::string &path2)
double degToRad(const double &d)
converts an angle given in degrees to radians.
std::string getCurrentWorkingDir()
void msleep(unsigned int milliseconds)
sleeps for at least the specified time.
std::string numToStr(T Number)
std::string trim(const std::string &str)
remove leading and trailing whitespaces
double radToDeg(const double &r)
converts an angle given in radians to degrees.
void removeFilenamePrefix(std::string *file)
given a filepath "bla/da/fnord/foobar.baz" this will remove everything before and including the last ...
std::string getPathOfFile(const std::string &filename)
Copyright 2012, DFKI GmbH Robotics Innovation Center.
bool matchPattern(const std::string &pattern, const std::string &str)
basic pattern matching function
void removeFilenameSuffix(std::string *file)
given a filename "foobar.baz" this will remove the extension (including the dot ".") resulting in "foobar".
bool pathExists(const std::string &path)
check whether a file or directory exists.
std::string tolower(const std::string &s)
std::string toupper(const std::string &s)
std::string replaceString(const std::string &source, const std::string &s1, const std::string &s2)
long long getTimeDiff(long long start)
returns the time difference between now and a given reference.
std::vector< std::string > explodeString(const char c, const std::string &s)
void handleFilenamePrefix(std::string *file, const std::string &prefix)
unsigned int createDirectory(const std::string &dir, int mode)
creates a directory at the given path.