1 //
2 // Description: given a collection generates a string representation
3 //
4 //
5 // Author: Lorenzo Bettini, 1999-2007 <http://www.lorenzobettini.it>
6 //
7 // Copyright: See COPYING file that comes with this distribution
8 //
9 //
10
11 #ifndef TOSTRINGCOLLECTION_H
12 #define TOSTRINGCOLLECTION_H
13
14 #include <string>
15 #include <sstream>
16
18
26 template <class T>
28 {
29 std::ostringstream buf;
30
31 for (typename T::const_iterator it = collection->begin();
32 it != collection->end(); )
33 {
34 buf << (*it)->toString();
35 if (++it != collection->end())
36 buf << sep;
37 }
38
39 return buf.str();
40 }
41
49 template <class T>
51 {
52 std::ostringstream buf;
53
54 for (typename T::const_iterator it = collection.begin();
55 it != collection.end(); )
56 {
57 buf << (*it);
58 if (++it != collection.end())
59 buf << sep;
60 }
61
62 return buf.str();
63 }
64
72 template <class T>
74 {
75 std::ostringstream buf;
76
77 for (typename T::const_iterator it = collection->begin();
78 it != collection->end(); )
79 {
80 buf << (*it)->toStringOriginal();
81 if (++it != collection->end())
82 buf << sep;
83 }
84
85 return buf.str();
86 }
87
95 template <class T>
97 {
98 std::ostringstream buf;
99
100 for (typename T::const_iterator it = collection->begin();
101 it != collection->end(); )
102 {
103 buf << (*it);
104 if (++it != collection->end() && sep)
105 buf << sep;
106 }
107
108 return buf.str();
109 }
110
118 template <class T>
120 {
121 std::ostringstream buf;
122
123 for (typename T::const_iterator it = collection.begin();
124 it != collection.end(); )
125 {
126 buf << (*it);
127 if (++it != collection.end() && sep)
128 buf << sep;
129 }
130
131 return buf.str();
132 }
133
134 }
135
136 #endif // TOSTRINGCOLLECTION_H
C++ class: doctemplate.h.
Definition: bufferedoutput.cpp:13
const std::string collectionToString(const T *collection, char sep= ' ')
Converts a collection of objects into a string, using the passed separator to separate the elements...
Definition: tostringcollection.h:96
const std::string toStringCollection(const T *collection, char sep= ' ')
Converts a collection of objects with method toString into a string, using the passed separator to se...
Definition: tostringcollection.h:27
const std::string collectionRefToString(const T &collection, char sep= ' ')
Converts a collection of objects into a string, using the passed separator to separate the elements...
Definition: tostringcollection.h:119
const std::string toStringOriginalCollection(const T *collection, char sep= ' ')
Converts a collection of objects with method toStringOriginal into a string, using the passed separat...
Definition: tostringcollection.h:73