MultiAgentDecisionProcess  Release 0.2.1
PrintTools.h
Go to the documentation of this file.
1 
28 #ifndef _PRINTTOOLS_H_
29 #define _PRINTTOOLS_H_ 1
30 
31 #include <vector>
32 #include <set>
33 #include <sstream>
34 #include <iomanip>
35 
37 
39 namespace PrintTools {
40 
41 
42 template <class T>
43 static std::string SoftPrintVector(const T &v)
44 {
45  std::stringstream ss;
46  ss << v;
47  return(ss.str());
48 }
49 
50 template <class T>
51 static std::string SoftPrintVector(const std::vector<T> &v)
52 {
53  std::stringstream ss;
54  typename std::vector<T>::const_iterator it = v.begin();
55  typename std::vector<T>::const_iterator last = v.end();
56  ss << "< ";
57  while(it != last)
58  {
59  if(it != v.begin())
60  ss << ", ";
61 
62  ss << SoftPrintVector(*it);
63  it++;
64  }
65  ss << " >";
66  return(ss.str());
67 }
68 
71 template <class T>
72 static void PrintVectorCout(const T &v)
73 {
74  std::cout << v;
75 }
76 
77 template <class T>
78 static void PrintVectorCout(const std::vector<T> &v)
79 {
80  std::cout << SoftPrintVector(v) << std::endl;
81 }
82 
83 template <class T>
84 static void PrintCout(const T &v)
85 {
86  std::cout << v;
87 }
88 
89 template <class T>
90 static void PrintCout(const std::vector<T> &v)
91 {
92  PrintVectorCout(v);
93 }
94 
95 template <class T>
96 static void PrintCout(const std::set<T> &v)
97 {
98  std::cout << SoftPrint(v);
99 }
100 
101 template <class T>
102 static std::string SoftPrint(const T &v)
103 {
104  std::stringstream ss;
105  ss << v;
106  return(ss.str());
107 }
108 
109 template <class T>
110 static std::string SoftPrint(const std::vector<T> &v)
111 {
112  return(SoftPrintVector(v));
113 }
114 
115 template <class T>
116 static std::string SoftPrint(const std::set<T> &v)
117 {
118  std::stringstream ss;
119  typename std::set<T>::const_iterator it = v.begin();
120  typename std::set<T>::const_iterator last = v.end();
121  ss << "< ";
122  while(it != last)
123  {
124  if(it != v.begin())
125  ss << ", ";
126 
127  ss << SoftPrint(*it);
128  it++;
129  }
130  ss << " >";
131  return(ss.str());
132 }
133 
134 template <class T>
135 static void PrintProgress(T prefix, LIndex i,
136  LIndex nr, size_t interval)
137 {
138  if(i % interval == 0&& i > interval)
139  {
140  std::cout << prefix << " "<< i << " of " << nr << " - "
141  << std::setprecision(4)
142  << ((double) i / nr) * 100
143  << "%" << std::endl;
144  }
145 }
146 
147 }
148 
149 #endif /* !_PRINTTOOLS_H_ */