gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
stream_overloads.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
21 
22 
23 #ifndef __stream_overloads_hpp__
24 #define __stream_overloads_hpp__
25 
26 #include <map>
27 #include <set>
28 #include <string>
29 #include <vector>
30 #include <ostream>
31 
32 namespace Gambit
33 {
34 
36  std::string spacing(int, int);
37 
39  template <class Type1, class Type2>
40  inline std::ostream& operator << (std::ostream& os, const std::pair<Type1, Type2>& p)
41  {
42  os << "( " << p.first << ", " << p.second << ")";
43  return os;
44  }
45 
47  template <class Type>
48  inline std::ostream& operator << (std::ostream& os, const std::set<Type>& set)
49  {
50  os << "{";
51  int length = set.size();
52  if (length != 0)
53  {
54  typename std::set<Type>::const_iterator it, start, finish;
55  start = set.begin();
56  finish = set.end();
57  os << *start;
58  if (length != 1)
59  {
60  for (it = ++start; it != finish; it++) { os << ", " << *it; }
61  }
62  }
63  os << "}";
64  return os;
65  }
66 
68  template <class Type>
69  inline std::ostream& operator << (std::ostream& os, const std::vector<Type>& v)
70  {
71  os << "[";
72  int length = v.size();
73  if (length != 0)
74  {
75  typename std::vector<Type>::const_iterator it, start, finish;
76  start = v.begin();
77  finish = v.end();
78  os << *start;
79  if (length != 1)
80  {
81  for (it = ++start; it != finish; it++) { os << ", " << *it; }
82  }
83  }
84  os << " ]";
85  return os;
86  }
87 
89  template<class Type>
90  std::ostream& operator << (std::ostream& os, const std::map<std::string,Type>& map)
91  {
92  unsigned int maxlen = 0;
93 
94  for (auto it = map.begin(); it != map.end(); it++)
95  {
96  if ((*it).first.length() > maxlen) maxlen = (*it).first.length();
97  }
98 
99  for (auto it = map.begin(); it != map.end(); it++)
100  {
101  if (it != map.begin()) {os << std::endl;}
102  os << " " << (*it).first << spacing((*it).first.length(), maxlen) << "(" << (*it).second << ")";
103  }
104 
105  return os;
106  }
107 
108 }
109 
110 #endif /* defined(__stream_overloads_hpp__) */
111 
TODO: see if we can use this one:
Definition: Analysis.hpp:33
std::string spacing(int, int)
Spacing utility for stream overloads.