root/OpenSceneGraph/trunk/include/osg/io_utils @ 13041

Revision 13041, 9.2 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
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.
7 *
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.
12*/
13
14#ifndef OSG_IO_UTILS
15#define OSG_IO_UTILS 1
16
17#include <ostream>
18#include <istream>
19
20#include <osg/Vec4d>
21#include <osg/Vec4ub>
22#include <osg/Vec2b>
23#include <osg/Vec3b>
24#include <osg/Vec4b>
25#include <osg/Vec2s>
26#include <osg/Vec3s>
27#include <osg/Vec4s>
28#include <osg/Matrixf>
29#include <osg/Matrixd>
30#include <osg/Plane>
31
32namespace osg {
33
34
35//////////////////////////////////////////////////////////////////////////
36// Vec2f streaming operators
37inline std::ostream& operator << (std::ostream& output, const Vec2f& vec)
38{
39    output << vec._v[0] << " " << vec._v[1];
40    return output;     // to enable cascading
41}
42
43inline std::istream& operator >> (std::istream& input, Vec2f& vec)
44{
45    input >> vec._v[0] >> std::ws >> vec._v[1];
46    return input;
47}
48
49//////////////////////////////////////////////////////////////////////////
50// Vec2d steaming operators.
51inline std::ostream& operator << (std::ostream& output, const Vec2d& vec)
52{
53    output << vec._v[0] << " " << vec._v[1];
54    return output;     // to enable cascading
55}
56
57inline std::istream& operator >> (std::istream& input, Vec2d& vec)
58{
59    input >> vec._v[0] >> std::ws >> vec._v[1];
60    return input;
61}
62
63//////////////////////////////////////////////////////////////////////////
64// Vec3f steaming operators.
65inline std::ostream& operator << (std::ostream& output, const Vec3f& vec)
66{
67    output << vec._v[0] << " "
68           << vec._v[1] << " "
69           << vec._v[2];
70    return output;     // to enable cascading
71}
72
73inline std::istream& operator >> (std::istream& input, Vec3f& vec)
74{
75    input >> vec._v[0] >> std::ws >> vec._v[1] >> std::ws >> vec._v[2];
76    return input;
77}
78
79
80//////////////////////////////////////////////////////////////////////////
81// Vec3d steaming operators.
82inline std::ostream& operator << (std::ostream& output, const Vec3d& vec)
83{
84    output << vec._v[0] << " "
85           << vec._v[1] << " "
86           << vec._v[2];
87    return output;     // to enable cascading
88}
89
90inline std::istream& operator >> (std::istream& input, Vec3d& vec)
91{
92    input >> vec._v[0] >> std::ws >> vec._v[1] >> std::ws >> vec._v[2];
93    return input;
94}
95
96
97//////////////////////////////////////////////////////////////////////////
98// Vec3f steaming operators.
99inline std::ostream& operator << (std::ostream& output, const Vec4f& vec)
100{
101    output  << vec._v[0] << " "
102            << vec._v[1] << " "
103            << vec._v[2] << " "
104            << vec._v[3];
105    return output;     // to enable cascading
106}
107
108inline std::istream& operator >> (std::istream& input, Vec4f& vec)
109{
110    input >> vec._v[0] >> std::ws
111          >> vec._v[1] >> std::ws
112          >> vec._v[2] >> std::ws
113          >> vec._v[3];
114    return input;
115}
116
117
118
119//////////////////////////////////////////////////////////////////////////
120// Vec4d steaming operators.
121inline std::ostream& operator << (std::ostream& output, const Vec4d& vec)
122{
123    output << vec._v[0] << " "
124           << vec._v[1] << " "
125           << vec._v[2] << " "
126           << vec._v[3];
127    return output;     // to enable cascading
128}
129inline std::istream& operator >> (std::istream& input, Vec4d& vec)
130{
131    input >> vec._v[0] >> std::ws
132          >> vec._v[1] >> std::ws
133          >> vec._v[2] >> std::ws
134          >> vec._v[3];
135    return input;
136}
137
138
139//////////////////////////////////////////////////////////////////////////
140// Vec2b steaming operators.
141inline std::ostream& operator << (std::ostream& output, const Vec2b& vec)
142{
143    output << (int)vec._v[0] << " "
144           << (int)vec._v[1];
145    return output; // to enable cascading
146}
147
148inline std::istream& operator >> (std::istream& input, Vec2b& vec)
149{
150    input >> vec._v[0] >> std::ws >> vec._v[1];
151    return input;
152}
153
154//////////////////////////////////////////////////////////////////////////
155// Vec3b steaming operators.
156inline std::ostream& operator << (std::ostream& output, const Vec3b& vec)
157{
158    output << (int)vec._v[0] << " "
159           << (int)vec._v[1] << " "
160           << (int)vec._v[2];
161    return output; // to enable cascading
162}
163
164inline std::istream& operator >> (std::istream& input, Vec3b& vec)
165{
166    input >> vec._v[0] >> std::ws >> vec._v[1] >> std::ws >> vec._v[2];
167    return input;
168}
169
170//////////////////////////////////////////////////////////////////////////
171// Vec4b steaming operators.
172inline std::ostream& operator << (std::ostream& output, const Vec4b& vec)
173{
174    output << (int)vec._v[0] << " "
175           << (int)vec._v[1] << " "
176           << (int)vec._v[2] << " "
177           << (int)vec._v[3];
178    return output; // to enable cascading
179}
180
181inline std::istream& operator >> (std::istream& input, Vec4b& vec)
182{
183    input >> vec._v[0] >> std::ws
184          >> vec._v[1] >> std::ws
185          >> vec._v[2] >> std::ws
186          >> vec._v[3];
187    return input;
188}
189
190
191//////////////////////////////////////////////////////////////////////////
192// Vec2s steaming operators.
193inline std::ostream& operator << (std::ostream& output, const Vec2s& vec)
194{
195    output << (int)vec._v[0] << " "
196           << (int)vec._v[1];
197    return output; // to enable cascading
198}
199
200inline std::istream& operator >> (std::istream& input, Vec2s& vec)
201{
202    input >> vec._v[0] >> std::ws >> vec._v[1];
203    return input;
204}
205
206//////////////////////////////////////////////////////////////////////////
207// Vec3s steaming operators.
208inline std::ostream& operator << (std::ostream& output, const Vec3s& vec)
209{
210    output << (int)vec._v[0] << " "
211           << (int)vec._v[1] << " "
212           << (int)vec._v[2];
213    return output; // to enable cascading
214}
215
216inline std::istream& operator >> (std::istream& input, Vec3s& vec)
217{
218    input >> vec._v[0] >> std::ws >> vec._v[1] >> std::ws >> vec._v[2];
219    return input;
220}
221
222//////////////////////////////////////////////////////////////////////////
223// Vec4s steaming operators.
224inline std::ostream& operator << (std::ostream& output, const Vec4s& vec)
225{
226    output << (int)vec._v[0] << " "
227           << (int)vec._v[1] << " "
228           << (int)vec._v[2] << " "
229           << (int)vec._v[3];
230    return output; // to enable cascading
231}
232
233inline std::istream& operator >> (std::istream& input, Vec4s& vec)
234{
235    input >> vec._v[0] >> std::ws
236          >> vec._v[1] >> std::ws
237          >> vec._v[2] >> std::ws
238          >> vec._v[3];
239    return input;
240}
241
242
243//////////////////////////////////////////////////////////////////////////
244// Matrixf steaming operators.
245inline std::ostream& operator<< (std::ostream& os, const Matrixf& m )
246{
247    os << "{"<<std::endl;
248    for(int row=0; row<4; ++row) {
249        os << "\t";
250        for(int col=0; col<4; ++col)
251            os << m(row,col) << " ";
252        os << std::endl;
253    }
254    os << "}" << std::endl;
255    return os;
256}
257
258
259//////////////////////////////////////////////////////////////////////////
260// Matrixd steaming operators.
261inline std::ostream& operator<< (std::ostream& os, const Matrixd& m )
262{
263    os << "{"<<std::endl;
264    for(int row=0; row<4; ++row) {
265        os << "\t";
266        for(int col=0; col<4; ++col)
267            os << m(row,col) << " ";
268        os << std::endl;
269    }
270    os << "}" << std::endl;
271    return os;
272}
273
274//////////////////////////////////////////////////////////////////////////
275// Vec4ub steaming operators.
276inline std::ostream& operator << (std::ostream& output, const Vec4ub& vec)
277{
278    output << (int)vec._v[0] << " "
279           << (int)vec._v[1] << " "
280           << (int)vec._v[2] << " "
281           << (int)vec._v[3];
282    return output;         // to enable cascading
283}
284
285inline std::istream& operator >> (std::istream& input, Vec4ub& vec)
286{
287    input >> vec._v[0] >> std::ws
288          >> vec._v[1] >> std::ws
289          >> vec._v[2] >> std::ws
290          >> vec._v[3];
291    return input;
292}
293
294
295//////////////////////////////////////////////////////////////////////////
296// Quat steaming operators.
297inline std::ostream& operator << (std::ostream& output, const Quat& vec)
298{
299    output << vec._v[0] << " "
300       << vec._v[1] << " "
301       << vec._v[2] << " "
302       << vec._v[3];
303    return output;     // to enable cascading
304}
305
306inline std::istream& operator >> (std::istream& input, Quat& vec)
307{
308    input >> vec._v[0] >> std::ws
309          >> vec._v[1] >> std::ws
310          >> vec._v[2] >> std::ws
311          >> vec._v[3];
312    return input;
313}
314
315
316
317//////////////////////////////////////////////////////////////////////////
318// Plane steaming operators.
319inline std::ostream& operator << (std::ostream& output, const Plane& pl)
320{
321    output << pl[0] << " "
322           << pl[1] << " "
323           << pl[2] << " "
324           << pl[3];
325    return output;         // to enable cascading
326}
327
328inline std::istream& operator >> (std::istream& input, Plane& vec)
329{
330    input >> vec[0] >> std::ws
331          >> vec[1] >> std::ws
332          >> vec[2] >> std::ws
333          >> vec[3];
334    return input;
335}
336
337}    // end of namespace osg
338#endif
Note: See TracBrowser for help on using the browser.