21 #ifndef _cvc3__debug_h
25 #ifndef _cvc3__cvc_util_h
26 #define _cvc3__cvc_util_h
30 inline std::string
to_upper(
const std::string & src){
32 for(std::string::const_iterator i=src.begin(), iend = src.end(); i!=iend ; i++){
33 nameup.push_back(toupper(*i));
38 inline std::string
to_lower(
const std::string & src){
40 for(std::string::const_iterator i=src.begin(), iend = src.end(); i!=iend ; i++){
41 nameup.push_back(tolower(*i));
47 std::ostringstream ss;
53 T
abs(T t) {
return t < 0 ? -t : t; }
56 T
max(T a, T b) {
return a > b ? a : b; }
59 bool operator()(
const std::string& s1,
const std::string& s2)
const{
60 return s1.compare(s2) < 0;
68 const std::pair<std::string,T>& p2)
const {
69 return p1.first < p2.first;
74 std::pair<std::string,T>
strPair(
const std::string& f,
const T& t) {
75 return std::pair<std::string,T>(f, t);
78 typedef std::pair<std::string,std::string>
StrPair;
82 void sort2(std::vector<std::string>& keys, std::vector<T>& vals) {
85 std::vector<std::pair<std::string,T> > pairs;
86 for(
size_t i=0, iend=keys.size(); i<iend; ++i)
87 pairs.push_back(
strPair(keys[i], vals[i]));
90 sort(pairs.begin(), pairs.end(), comp);
91 DebugAssert(pairs.size() == keys.size(),
"sort2()");
93 for(
size_t i=0, iend=pairs.size(); i<iend; ++i) {
94 keys[i] = pairs[i].first;
95 vals[i] = pairs[i].second;
120 static void print(std::string name,
int verbosity,
121 unsigned long memSelf,
unsigned long mem)
124 std::cout << name <<
": " << memSelf <<
std::endl;
125 std::cout <<
" Children: " << mem <<
std::endl;
126 std::cout <<
" Total: " << mem+memSelf <<
std::endl;
130 template <
typename T>
131 static unsigned long getVec(
int verbosity,
const std::vector<T>& v)
133 unsigned long memSelf =
sizeof(std::vector<T>);
134 unsigned long mem = 0;
135 print(
"vector", verbosity, memSelf, mem);
136 return memSelf + mem;
139 template <
typename T>
142 unsigned long memSelf =
sizeof(std::vector<T>);
143 unsigned long mem = 0;
144 for (
unsigned i = 0; i < v.size(); ++i) {
145 mem += v[i].getMemory(verbosity - 1);
147 print(
"vector+data", verbosity, memSelf, mem);
148 return memSelf + mem;
151 template <
typename T>
154 unsigned long memSelf =
sizeof(std::vector<T>);
155 unsigned long mem = 0;
156 for (
unsigned i = 0; i < v.size(); ++i) {
157 mem += v[i]->getMemory(verbosity - 1);
159 print(
"vector+data(p)", verbosity, memSelf, mem);
160 return memSelf + mem;
163 static unsigned long getString(
int verbosity,
const std::string& s)
165 unsigned long memSelf =
sizeof(std::string);
166 unsigned long mem = s.capacity() *
sizeof(char);
167 print(
"string", verbosity, memSelf, mem);
168 return memSelf + mem;