00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __COMMON_H__
00009 #define __COMMON_H__
00010
00011 #include <iostream>
00012 #include <cstdio>
00013 #include <iomanip>
00014 #include <map>
00015 #include <set>
00016 #include <vector>
00017
00018
00019 typedef std::set<std::string> StringSet;
00020 typedef std::vector<size_t> IntVector;
00021
00030 template <class InputIterator, class T>
00031 T valueMerge(InputIterator first, InputIterator last, T delim)
00032 {
00033 T value;
00034
00035 while (first != last) {
00036 value += *first++;
00037 if (first != last) value += delim;
00038 }
00039
00040 return value;
00041 }
00042
00047 template <typename T>
00048 struct deletePtr : public std::unary_function<bool, T>
00049 {
00050 bool operator()(T *pT) const {
00051 delete pT;
00052 return true;
00053 }
00054 };
00055
00069 template <class T> class Singleton
00070 {
00071 private:
00072 Singleton(const Singleton &);
00073 Singleton & operator=(const Singleton &);
00074 T & operator=(const T &);
00075
00076 protected:
00077 Singleton() {}
00078 virtual ~Singleton() {}
00079
00080 public:
00081 static T & instance() {
00082 static T theInstance;
00083 return theInstance;
00084 }
00085 };
00086
00087 extern int debugLevel;
00088
00089 #define CLEAR_SCREEN_CMD "clear"
00090 #define LOG(L, ...) if (L <= debugLevel) { \
00091 printf("[%s:%d] [%s] ", __FILE__, \
00092 __LINE__, __func__); \
00093 printf(__VA_ARGS__); \
00094 }
00095 #define LOG_CTOR() LOG(3, "ctor called\n")
00096 #define LOG_DTOR() LOG(3, "dtor called\n")
00097
00098 #endif