#ifndef __UTILS_H #define __UTILS_H #include #include #include #include #define HOUR (60*60) #define DAY (24*HOUR) #define ROUND(x) (int)((x) + 0.5) using std::string; time_t usec_diff(struct timeval &tv1, struct timeval &tv2); class ImmsRandom { public: ImmsRandom() { urandom = open("/dev/urandom", O_RDONLY); if (urandom == -1) throw std::runtime_error("could not open /dev/urandom"); } ~ImmsRandom() { (void)close(urandom); } int imms_random(int max) { unsigned long rand_num; (void)read(urandom, &rand_num, sizeof(rand_num)); double cof = rand_num / (ULONG_MAX + 1.0); return (int)(max * cof); } private: int urandom; }; class StackTimer { public: StackTimer(); ~StackTimer(); private: struct timeval start; }; class StackLockFile { public: class AlreadyLocked {}; StackLockFile(const string &_name); ~StackLockFile(); bool isok() { return name != ""; } private: string name; }; string get_imms_root(const string &file = ""); string path_normalize(const string &path); float rms_string_distance(const string &s1, const string &s2, int max = INT_MAX); string rescale_bpmgraph(const string &graph); #endif