23 #ifndef OPENRAVE_UTILS_H
24 #define OPENRAVE_UTILS_H
32 #include <boost/shared_ptr.hpp>
33 #include <boost/weak_ptr.hpp>
34 #include <boost/function.hpp>
35 #include <boost/assert.hpp>
40 #if !(defined(CLOCK_GETTIME_FOUND) && (POSIX_TIMERS > 0 || _POSIX_TIMERS > 0))
44 #define WIN32_LEAN_AND_MEAN
46 #include <sys/timeb.h>
47 inline void usleep(
unsigned long microseconds) {
48 Sleep((microseconds+999)/1000);
60 LARGE_INTEGER count, freq;
61 QueryPerformanceCounter(&count);
62 QueryPerformanceFrequency(&freq);
63 return (uint32_t)((count.QuadPart * 1000) / freq.QuadPart);
68 LARGE_INTEGER count, freq;
69 QueryPerformanceCounter(&count);
70 QueryPerformanceFrequency(&freq);
71 return (count.QuadPart * 1000000) / freq.QuadPart;
76 LARGE_INTEGER count, freq;
77 QueryPerformanceCounter(&count);
78 QueryPerformanceFrequency(&freq);
79 return (count.QuadPart * 1000000000) / freq.QuadPart;
90 #if defined(CLOCK_GETTIME_FOUND) && (POSIX_TIMERS > 0 || _POSIX_TIMERS > 0)
91 struct timespec start;
92 clock_gettime(CLOCK_REALTIME, &start);
96 struct timeval timeofday;
97 gettimeofday(&timeofday,NULL);
98 sec = timeofday.tv_sec;
99 nsec = timeofday.tv_usec * 1000;
107 return (uint64_t)sec*1000000000 + (uint64_t)nsec;
114 return (uint64_t)sec*1000000 + (uint64_t)nsec/1000;
121 return (uint64_t)sec*1000 + (uint64_t)nsec/1000000;
126 #if defined(CLOCK_GETTIME_FOUND) && (POSIX_TIMERS > 0 || _POSIX_TIMERS > 0) && defined(_POSIX_MONOTONIC_CLOCK)
127 struct timespec start;
129 clock_gettime(CLOCK_MONOTONIC, &start);
131 nsec = start.tv_nsec;
132 return (uint64_t)sec*1000000000 + (uint64_t)nsec;
146 template <
class T> boost::shared_ptr<T>
sptr_from(boost::weak_ptr<T>
const& wpt)
148 return boost::shared_ptr<T>(wpt);
171 boost::function<void(void const*)> _deleterfn;
172 boost::function<void()> _postdeleterfn;
174 smart_pointer_deleter(P
const & p,
const boost::function<
void(
void const*)>& deleterfn,
const boost::function<
void()>& postdeleterfn = boost::function<
void()>()) : p_(p), _deleterfn(deleterfn), _postdeleterfn(postdeleterfn)
184 if( !!_postdeleterfn ) {
189 P
const &
get()
const
199 std::transform(d.begin(), d.end(), d.begin(), ::tolower);
223 std::bitset<255> delims;
225 unsigned char code = *d++;
228 std::string::const_iterator beg;
229 bool in_token =
false;
230 for( std::string::const_iterator it = s.begin(), end = s.end(); it != end; ++it ) {
233 output.push_back(
typename C::value_type(beg, it));
237 else if( !in_token ) {
243 output.push_back(
typename C::value_type(beg, s.end()));
256 OPENRAVE_API std::string&
SearchAndReplace(std::string& out,
const std::string& in,
const std::vector< std::pair<std::string, std::string> >& pairs);
275 template <
typename T>
280 BOOST_ASSERT(range>0);
282 while (theta < min) {
286 else if (theta > max) {
288 BOOST_ASSERT(range>0);
290 while (theta > max) {
297 template <
typename T>
300 const T
PI = T(3.14159265358979323846);
304 template <
typename T>
310 template <
typename T>
317 return c < 0 || c >= 33;
322 if( s.size() == 0 ) {
334 std::string newname = name;
335 for(
size_t i = 0; i < newname.size(); ++i) {