Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
stream_util.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file utility/stream_util.hh
11 /// @brief Implemention of ostream operator << for various common types
12 /// @author Sergey Lyskov
13 
14 #ifndef INCLUDED_utility_stream_util_hh
15 #define INCLUDED_utility_stream_util_hh
16 
17 #include <map>
18 #include <list>
19 #include <ostream>
20 
21 //Auto Headers
22 #include <utility/vector1.fwd.hh>
23 #include <utility/vectorL.fwd.hh>
24 #include <vector>
25 
26 namespace utility {
27 
28 /// -------------------------------------------------------------------
29 /// Predefined functions for Tracer IO
30 /// We originally moved them out of name spaces so we can use them right away - without specifying it.
31 /// Returned to utility namespace, as some compilers did not find the operator otherwise! -- rhiju
32 
33 template <typename T1, typename T2>
34 std::ostream & operator <<(std::ostream & os, std::pair<T1, T2> const & v); // declare here to allow output of vector1< std::pair >.
35 
36 /// @brief Output function for std::pair object.
37 template <typename T1, typename T2>
38 std::ostream & operator <<(std::ostream & os, std::pair<T1, T2> const & v) {
39  os << "[";
40  os << v.first;
41  os << ", ";
42  os << v.second;
43  os << "]";
44  return os;
45 }
46 
47 
48 /// @brief Output function for std::map object.
49 template <typename T1, typename T2>
50 std::ostream & operator <<(std::ostream & os, std::map<T1, T2> const & m) {
52  ConstIterator p;
53 
54  os << "{";
55 
56  for ( p=m.begin(); p!=m.end(); p++ ) {
57  os << p->first << ":" << p->second << ", ";
58  }
59 
60  os << "}";
61  return os;
62 }
63 
64 
65 /// @brief Output function for std::list object.
66 template <typename T>
67 std::ostream & operator <<(std::ostream & os, std::list<T> const & l) {
69  ConstIterator p;
70 
71  os << "[[";
72 
73  for ( p=l.begin(); p!=l.end(); p++ ) {
74  os << *p << ", ";
75  }
76 
77  os << "]]";
78  return os;
79 }
80 
81 /// @brief Output function for utility::vector1 object.
82 template <platform::SSize L, class T>
83 std::ostream & operator <<(std::ostream & os, utility::vectorL<L, T> const & v) {
84  os << "[";
85  if ( v.size() ) {
86  for ( size_t i=v.l(); i<=v.u(); ++i ) {
87  os << v[i];
88  if ( i < v.u() ) os << ", ";
89  }
90  }
91  os << "]";
92  return os;
93 }
94 
95 } // namespace utility
96 
97 
98 namespace std { // inserting operator for ::std types in to std namespace
99 
100 /// @brief Output function for std::vector object.
101 template <class T>
102 std::ostream & operator <<( std::ostream & os, std::vector<T> const & v)
103 {
104  os << "[";
105  for ( size_t i = 0; i < v.size(); i++ ) {
106  os << v[i];
107  if ( i < v.size()-1 ) os << ", ";
108  }
109  os << "]";
110  return os;
111 }
112 
113 } // namespace std
114 
115 #endif // INCLUDED_utility_stream_util_hh
utility::vectorL forward declarations
utility::keys::KeyLookup< KeyType >::const_iterator const_iterator
Key collection iterators.
tuple p
Definition: docking.py:9
utility::keys::KeyLookup< KeyType >::const_iterator ConstIterator
utility::vector1 forward declarations