Essentia  2.1-beta5-dev
streamutil.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2016 Music Technology Group - Universitat Pompeu Fabra
3  *
4  * This file is part of Essentia
5  *
6  * Essentia 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 ESSENTIA_STREAMUTIL_H
21 #define ESSENTIA_STREAMUTIL_H
22 
23 #include <vector>
24 #include <set>
25 #include <complex>
26 
27 //
28 // This file contains helper functions and macros to make debugging and working
29 // with streams easier.
30 //
31 
35 #define PR(x) std::cout << #x << ": " << x << std::endl
36 
37 
38 namespace essentia {
39 
40 
44 /*
45 std::ostream& operator<<(std::ostream& out, const std::complex<float>& c) {
46  return out << c.real() << '+' << c.imag() << 'i';
47 }
48 */
52 template <typename T, typename U>
53 std::ostream& operator<<(std::ostream& out, const std::pair<T, U>& p) {
54  return out << '<' << p.first << ',' << p.second << '>';
55 }
56 
60 template <typename T>
61 std::ostream& operator<<(std::ostream& out, const std::vector<T>& v) {
62  out << '['; if (!v.empty()) {
63  out << *v.begin(); typename std::vector<T>::const_iterator it = v.begin();
64  for (++it; it != v.end(); ++it) out << ", " << *it;
65  }
66  return out << ']';
67 }
68 
72 template <typename T>
73 std::ostream& operator<<(std::ostream& out, const std::set<T>& v) {
74  out << '{'; if (!v.empty()) {
75  out << *v.begin(); typename std::set<T>::const_iterator it = v.begin();
76  for (++it; it != v.end(); ++it) out << ", " << *it;
77  }
78  return out << '}';
79 }
80 
81 
82 } // namespace essentia
83 
84 #endif // ESSENTIA_STREAMUTIL_H
Definition: algorithm.h:28