SST/macro
output.h
Go to the documentation of this file.
1 #ifndef OUTPUT_H
2 #define OUTPUT_H
3 
4 #include <vector>
5 #include <map>
6 #include <ostream>
7 
8 //Default string output for unit tests
9 template <class T> class ClassOutput
10 {
11 
12  public:
13  static void
14  print(const T& t, std::ostream& os) {
15  os << t;
16  }
17 
18 };
19 
20 template <class T>
21 class ClassOutput< std::vector<T> >
22 {
23 
24  public:
25  static void
26  print(const std::vector<T>& test, std::ostream& os) {
27  os << "{ ";
28  typename std::vector<T>::const_iterator
29  it, begin = test.begin(), end = test.end();
30  for (it=begin; it != end; ++it) {
31  if (it != begin) {
32  os << ",";
33  }
34  ClassOutput<T>::print(*it, os);
35  }
36  os << " }";
37  }
38 };
39 
40 template <class T, class U>
41 class ClassOutput< std::map<T, U> >
42 {
43 
44  public:
45  static void
46  print(const std::map<T, U>& test, std::ostream& os) {
47  os << "map {\n";
48  typename std::map<T,U>::const_iterator
49  it, begin = test.begin(), end = test.end();
50  for (it=begin; it != end; ++it) {
51  if (it != begin) {
52  os << ",";
53  }
54  ClassOutput<T>::print(it->first);
55  os << "->";
56  ClassOutput<T>::print(it->second);
57  }
58  os << " }";
59  }
60 
61 };
62 
63 #endif // OUTPUT_H
64 
static void print(const std::map< T, U > &test, std::ostream &os)
Definition: output.h:46
static void print(const T &t, std::ostream &os)
Definition: output.h:14
static void print(const std::vector< T > &test, std::ostream &os)
Definition: output.h:26