00001
00006 #ifndef FUNCTIONS_H_
00007 #define FUNCTIONS_H_
00008
00009 #include <ctime>
00010 #include <cstdlib>
00011 #include <string>
00012 #include <iostream>
00013 #include <map>
00014
00015 #include "exceptions.h"
00016
00017 using namespace std;
00018
00019 #ifdef HAVE_CONFIG_H
00020 #include "config.h"
00021 #endif
00022
00023 #ifndef PACKAGE
00024
00027 # define PACKAGE "dreamcache"
00028 #endif
00029
00030 #ifndef PREFIX
00031
00034 # define PREFIX "/"
00035 #endif
00036
00037 #ifndef CONFDIR
00038
00041 # define CONFDIR PREFIX "/etc/" PACKAGE
00042 #endif
00043
00044 #ifndef VERSION
00045
00048 # define VERSION "0.0"
00049 #endif
00050
00051
00052
00058 double diffTimes(timeval * t1, timeval * t2);
00059
00070 int extractValue(const string& s, unsigned offset, const string& confFilename, int line)
00071 throw (ConfigSemanticException);
00072
00080 std::string removeBlanks(string s);
00081
00094 int extractValue(const string& s, unsigned offset, const string& confFilename, int line)
00095 throw (ConfigSemanticException);
00096
00103 bool safe_strtoull(const char *str, uint64_t *out);
00104
00108 std::string pend_spaces_2_numb(unsigned long long val, unsigned count, bool append);
00109
00116 template<typename T, typename L>
00117 ostream & operator<<(ostream & out, pair<T, L> & p);
00118
00125 ostream & operator<<(ostream & out, map<int, char> & mymap);
00126
00133 string configurationDirectory(char * directory = NULL);
00134
00138 string getPackageName();
00139
00143 #define NUM_LENGTH(n) (n ? (int) log10((float) n) + 1: 1)
00144
00148 #define MUTEX_LOCK(m) if (pthread_mutex_lock(&m)) { \
00149 perror("WARNING !!!: pthread_mutex_lock"); \
00150 }
00151
00155 #define MUTEX_UNLOCK(m) if (pthread_mutex_unlock(&m)) { \
00156 perror("WARNING !!!: pthread_mutex_unlock"); \
00157 }
00158
00159 #endif