1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
39/** Convinience class for building std::string using stringstream.
42 * std::string s = str<<"Mix strings with numbers "<<0" ;
43 * std::string s2 = str.clear()<<"and other classes such as ("<<osg::Vec3(0.0,1.0,3.0)<<)" ; */
49 std::stringstream sstream;
52 MakeString& operator << (const T& t)
58 MakeString& operator << (std::ostream& (*fun)(std::ostream&))
64 inline MakeString& clear() { sstream.str("") ; return *this; }
66 inline operator std::string () const { return sstream.str(); }
68 inline std::string str() const { return sstream.str(); }
73inline std::ostream& operator << (std::ostream& output, const MakeString& str) { output << str.str(); return output; }
75//////////////////////////////////////////////////////////////////////////
76// Vec2f streaming operators
77inline std::ostream& operator << (std::ostream& output, const Vec2f& vec)
79 output << vec._v[0] << " " << vec._v[1];
80 return output; // to enable cascading
83inline std::istream& operator >> (std::istream& input, Vec2f& vec)
85 input >> vec._v[0] >> std::ws >> vec._v[1];
89//////////////////////////////////////////////////////////////////////////
90// Vec2d steaming operators.
91inline std::ostream& operator << (std::ostream& output, const Vec2d& vec)
93 output << vec._v[0] << " " << vec._v[1];
94 return output; // to enable cascading
97inline std::istream& operator >> (std::istream& input, Vec2d& vec)
99 input >> vec._v[0] >> std::ws >> vec._v[1];
103//////////////////////////////////////////////////////////////////////////
104// Vec3f steaming operators.
105inline std::ostream& operator << (std::ostream& output, const Vec3f& vec)
107 output << vec._v[0] << " "
110 return output; // to enable cascading
113inline std::istream& operator >> (std::istream& input, Vec3f& vec)
115 input >> vec._v[0] >> std::ws >> vec._v[1] >> std::ws >> vec._v[2];
120//////////////////////////////////////////////////////////////////////////
121// Vec3d steaming operators.
122inline std::ostream& operator << (std::ostream& output, const Vec3d& vec)
124 output << vec._v[0] << " "
127 return output; // to enable cascading
130inline std::istream& operator >> (std::istream& input, Vec3d& vec)
132 input >> vec._v[0] >> std::ws >> vec._v[1] >> std::ws >> vec._v[2];
137//////////////////////////////////////////////////////////////////////////
138// Vec3f steaming operators.
139inline std::ostream& operator << (std::ostream& output, const Vec4f& vec)
141 output << vec._v[0] << " "
145 return output; // to enable cascading
148inline std::istream& operator >> (std::istream& input, Vec4f& vec)
150 input >> vec._v[0] >> std::ws
151 >> vec._v[1] >> std::ws
152 >> vec._v[2] >> std::ws
159//////////////////////////////////////////////////////////////////////////
160// Vec4d steaming operators.
161inline std::ostream& operator << (std::ostream& output, const Vec4d& vec)
163 output << vec._v[0] << " "
167 return output; // to enable cascading
169inline std::istream& operator >> (std::istream& input, Vec4d& vec)
171 input >> vec._v[0] >> std::ws
172 >> vec._v[1] >> std::ws
173 >> vec._v[2] >> std::ws
179//////////////////////////////////////////////////////////////////////////
180// Vec2b steaming operators.
181inline std::ostream& operator << (std::ostream& output, const Vec2b& vec)
183 output << (int)vec._v[0] << " "
185 return output; // to enable cascading
188inline std::istream& operator >> (std::istream& input, Vec2b& vec)
190 input >> vec._v[0] >> std::ws >> vec._v[1];
194//////////////////////////////////////////////////////////////////////////
195// Vec3b steaming operators.
196inline std::ostream& operator << (std::ostream& output, const Vec3b& vec)
198 output << (int)vec._v[0] << " "
199 << (int)vec._v[1] << " "
201 return output; // to enable cascading
204inline std::istream& operator >> (std::istream& input, Vec3b& vec)
206 input >> vec._v[0] >> std::ws >> vec._v[1] >> std::ws >> vec._v[2];
210//////////////////////////////////////////////////////////////////////////
211// Vec4b steaming operators.
212inline std::ostream& operator << (std::ostream& output, const Vec4b& vec)
214 output << (int)vec._v[0] << " "
215 << (int)vec._v[1] << " "
216 << (int)vec._v[2] << " "
218 return output; // to enable cascading
221inline std::istream& operator >> (std::istream& input, Vec4b& vec)
223 input >> vec._v[0] >> std::ws
224 >> vec._v[1] >> std::ws
225 >> vec._v[2] >> std::ws
231//////////////////////////////////////////////////////////////////////////
232// Vec2s steaming operators.
233inline std::ostream& operator << (std::ostream& output, const Vec2s& vec)
235 output << (int)vec._v[0] << " "
237 return output; // to enable cascading
240inline std::istream& operator >> (std::istream& input, Vec2s& vec)
242 input >> vec._v[0] >> std::ws >> vec._v[1];
246//////////////////////////////////////////////////////////////////////////
247// Vec3s steaming operators.
248inline std::ostream& operator << (std::ostream& output, const Vec3s& vec)
250 output << (int)vec._v[0] << " "
251 << (int)vec._v[1] << " "
253 return output; // to enable cascading
256inline std::istream& operator >> (std::istream& input, Vec3s& vec)
258 input >> vec._v[0] >> std::ws >> vec._v[1] >> std::ws >> vec._v[2];
262//////////////////////////////////////////////////////////////////////////
263// Vec4s steaming operators.
264inline std::ostream& operator << (std::ostream& output, const Vec4s& vec)
266 output << (int)vec._v[0] << " "
267 << (int)vec._v[1] << " "
268 << (int)vec._v[2] << " "
270 return output; // to enable cascading
273inline std::istream& operator >> (std::istream& input, Vec4s& vec)
275 input >> vec._v[0] >> std::ws
276 >> vec._v[1] >> std::ws
277 >> vec._v[2] >> std::ws
284//////////////////////////////////////////////////////////////////////////
285// Vec2i steaming operators.
286inline std::ostream& operator << (std::ostream& output, const Vec2i& vec)
288 output << vec._v[0] << " "
290 return output; // to enable cascading
293inline std::istream& operator >> (std::istream& input, Vec2i& vec)
295 input >> vec._v[0] >> std::ws >> vec._v[1];
299//////////////////////////////////////////////////////////////////////////
300// Vec3i steaming operators.
301inline std::ostream& operator << (std::ostream& output, const Vec3i& vec)
303 output << vec._v[0] << " "
306 return output; // to enable cascading
309inline std::istream& operator >> (std::istream& input, Vec3i& vec)
311 input >> vec._v[0] >> std::ws >> vec._v[1] >> std::ws >> vec._v[2];
315//////////////////////////////////////////////////////////////////////////
316// Vec4i steaming operators.
317inline std::ostream& operator << (std::ostream& output, const Vec4i& vec)
319 output << vec._v[0] << " "
323 return output; // to enable cascading
326inline std::istream& operator >> (std::istream& input, Vec4i& vec)
328 input >> vec._v[0] >> std::ws
329 >> vec._v[1] >> std::ws
330 >> vec._v[2] >> std::ws
336//////////////////////////////////////////////////////////////////////////
337// Matrixf steaming operators.
338inline std::ostream& operator<< (std::ostream& os, const Matrixf& m )
340 os << "{"<<std::endl;
341 for(int row=0; row<4; ++row) {
343 for(int col=0; col<4; ++col)
344 os << m(row,col) << " ";
347 os << "}" << std::endl;
352//////////////////////////////////////////////////////////////////////////
353// Matrixd steaming operators.
354inline std::ostream& operator<< (std::ostream& os, const Matrixd& m )
356 os << "{"<<std::endl;
357 for(int row=0; row<4; ++row) {
359 for(int col=0; col<4; ++col)
360 os << m(row,col) << " ";
363 os << "}" << std::endl;
367//////////////////////////////////////////////////////////////////////////
368// Vec4ub steaming operators.
369inline std::ostream& operator << (std::ostream& output, const Vec4ub& vec)
371 output << (int)vec._v[0] << " "
372 << (int)vec._v[1] << " "
373 << (int)vec._v[2] << " "
375 return output; // to enable cascading
378inline std::istream& operator >> (std::istream& input, Vec4ub& vec)
380 input >> vec._v[0] >> std::ws
381 >> vec._v[1] >> std::ws
382 >> vec._v[2] >> std::ws
388//////////////////////////////////////////////////////////////////////////
389// Quat steaming operators.
390inline std::ostream& operator << (std::ostream& output, const Quat& vec)
392 output << vec._v[0] << " "
396 return output; // to enable cascading
399inline std::istream& operator >> (std::istream& input, Quat& vec)
401 input >> vec._v[0] >> std::ws
402 >> vec._v[1] >> std::ws
403 >> vec._v[2] >> std::ws
410//////////////////////////////////////////////////////////////////////////
411// Plane steaming operators.
412inline std::ostream& operator << (std::ostream& output, const Plane& pl)
414 output << pl[0] << " "
418 return output; // to enable cascading
421inline std::istream& operator >> (std::istream& input, Plane& vec)
423 input >> vec[0] >> std::ws
430} // end of namespace osg