Gaia
streamutil.h
1 /*
2  * Copyright (C) 2006-2013 Music Technology Group - Universitat Pompeu Fabra
3  *
4  * This file is part of Gaia
5  *
6  * Gaia is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License as published by the Free
8  * Software Foundation (FSF), either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the Affero GNU General Public License
17  * version 3 along with this program. If not, see http://www.gnu.org/licenses/
18  */
19 
20 #ifndef GAIA_STREAMUTIL_H
21 #define GAIA_STREAMUTIL_H
22 
23 #include <ostream>
24 #include <fstream>
25 #include <vector>
26 
27 namespace gaia2std {
28 
29 // printing and debugging utilities
30 #define PR(x) std::cout << #x << ": " << x << std::endl
31 
35 template <typename T, template<typename> class C>
36 std::ostream& operator<<(std::ostream& out, const C<T>& c) {
37  out << '{'; if (!c.empty()) {
38  out << *c.begin(); typename C<T>::const_iterator it = c.begin(); ++it;
39  for (; it != c.end(); ++it) out << ", " << *it;
40  }
41  return out << '}';
42 }
43 
48 template <class T>
49 std::ostream& operator<<(std::ostream& out, const std::vector<T>& v) {
50  out << '['; if (!v.empty()) {
51  out << *v.begin(); typename std::vector<T>::const_iterator it = v.begin();
52  for (++it; it != v.end(); ++it) out << ", " << *it;
53  }
54  return out << ']';
55 }
56 
60 template <typename T, typename U>
61 std::ostream& operator<<(std::ostream& out, const std::pair<T, U>& p) {
62  return out << '<' << p.first << ',' << p.second << '>';
63 }
64 
68 inline std::ostream& operator<<(std::ostream& out, const std::string& str) {
69  return out << str.c_str();
70 }
71 
72 
73 
74 } // namespace gaia2std
75 
76 #endif // GAIA_STREAMUTIL_H
Definition: baseexception.h:26