vsg  1.1.0
VulkanSceneGraph library
stream.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2018 Robert Osfield
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 
13 </editor-fold> */
14 
15 #include <vsg/core/ref_ptr.h>
16 #include <vsg/core/type_name.h>
17 #include <vsg/io/Path.h>
18 #include <vsg/maths/box.h>
19 #include <vsg/maths/mat3.h>
20 #include <vsg/maths/mat4.h>
21 #include <vsg/maths/plane.h>
22 #include <vsg/maths/quat.h>
23 #include <vsg/maths/sphere.h>
24 #include <vsg/maths/vec2.h>
25 #include <vsg/maths/vec3.h>
26 #include <vsg/maths/vec4.h>
27 
28 #include <istream>
29 #include <ostream>
30 #include <sstream>
31 
32 namespace vsg
33 {
34 
36  template<typename... Args>
37  std::string make_string(const Args&... args)
38  {
39  std::ostringstream stream;
40  (stream << ... << args);
41  return stream.str();
42  }
43 
45  template<typename T>
46  std::ostream& operator<<(std::ostream& output, const vsg::t_vec2<T>& vec)
47  {
48  output << vec.x << " " << vec.y;
49  return output;
50  }
51 
53  template<typename T>
54  std::istream& operator>>(std::istream& input, vsg::t_vec2<T>& vec)
55  {
56  input >> vec.x >> vec.y;
57  return input;
58  }
59 
61  template<typename T>
62  std::ostream& operator<<(std::ostream& output, const vsg::t_vec3<T>& vec)
63  {
64  output << vec.x << " " << vec.y << " " << vec.z;
65  return output;
66  }
67 
69  template<typename T>
70  std::istream& operator>>(std::istream& input, vsg::t_vec3<T>& vec)
71  {
72  input >> vec.x >> vec.y >> vec.z;
73  return input;
74  }
75 
77  template<typename T>
78  std::ostream& operator<<(std::ostream& output, const vsg::t_vec4<T>& vec)
79  {
80  output << vec.x << " " << vec.y << " " << vec.z << " " << vec.w;
81  return output;
82  }
83 
85  template<typename T>
86  std::istream& operator>>(std::istream& input, vsg::t_vec4<T>& vec)
87  {
88  input >> vec.x >> vec.y >> vec.z >> vec.w;
89  return input;
90  }
91 
93  template<typename T>
94  std::ostream& operator<<(std::ostream& output, const vsg::t_quat<T>& q)
95  {
96  output << q.x << " " << q.y << " " << q.z << " " << q.w;
97  return output;
98  }
99 
101  template<typename T>
102  std::istream& operator>>(std::istream& input, vsg::t_quat<T>& q)
103  {
104  input >> q.x >> q.y >> q.z >> q.w;
105  return input;
106  }
107 
109  template<typename T>
110  std::ostream& operator<<(std::ostream& output, const vsg::t_plane<T>& vec)
111  {
112  output << vec.value[0] << " " << vec.value[1] << " " << vec.value[2] << " " << vec.value[3];
113  return output;
114  }
115 
117  template<typename T>
118  std::istream& operator>>(std::istream& input, vsg::t_plane<T>& vec)
119  {
120  input >> vec.value[0] >> vec.value[1] >> vec.value[2] >> vec.value[3];
121  return input;
122  }
123 
125  template<typename T>
126  std::ostream& operator<<(std::ostream& output, const vsg::t_mat3<T>& mat)
127  {
128  output << std::endl;
129  output << " " << mat(0, 0) << " " << mat(1, 0) << " " << mat(2, 0) << std::endl;
130  output << " " << mat(0, 1) << " " << mat(1, 1) << " " << mat(2, 1) << std::endl;
131  output << " " << mat(0, 2) << " " << mat(1, 2) << " " << mat(2, 2) << std::endl;
132  return output;
133  }
134 
136  template<typename T>
137  std::istream& operator>>(std::istream& input, vsg::t_mat3<T>& mat)
138  {
139  input >> mat(0, 0) >> mat(1, 0) >> mat(2, 0);
140  input >> mat(0, 1) >> mat(1, 1) >> mat(2, 1);
141  input >> mat(0, 2) >> mat(1, 2) >> mat(2, 2);
142  return input;
143  }
144 
146  template<typename T>
147  std::ostream& operator<<(std::ostream& output, const vsg::t_mat4<T>& mat)
148  {
149  output << std::endl;
150  output << " " << mat(0, 0) << " " << mat(1, 0) << " " << mat(2, 0) << " " << mat(3, 0) << std::endl;
151  output << " " << mat(0, 1) << " " << mat(1, 1) << " " << mat(2, 1) << " " << mat(3, 1) << std::endl;
152  output << " " << mat(0, 2) << " " << mat(1, 2) << " " << mat(2, 2) << " " << mat(3, 2) << std::endl;
153  output << " " << mat(0, 3) << " " << mat(1, 3) << " " << mat(2, 3) << " " << mat(3, 3) << std::endl;
154  return output;
155  }
156 
158  template<typename T>
159  std::istream& operator>>(std::istream& input, vsg::t_mat4<T>& mat)
160  {
161  input >> mat(0, 0) >> mat(1, 0) >> mat(2, 0) >> mat(3, 0);
162  input >> mat(0, 1) >> mat(1, 1) >> mat(2, 1) >> mat(3, 1);
163  input >> mat(0, 2) >> mat(1, 2) >> mat(2, 2) >> mat(3, 2);
164  input >> mat(0, 3) >> mat(1, 3) >> mat(2, 3) >> mat(3, 3);
165  return input;
166  }
167 
169  template<typename T>
170  std::ostream& operator<<(std::ostream& output, const vsg::t_sphere<T>& sp)
171  {
172  output << sp.vec;
173  return output;
174  }
175 
177  template<typename T>
178  std::istream& operator>>(std::istream& input, vsg::t_sphere<T>& sp)
179  {
180  input >> sp.vec;
181  return input;
182  }
183 
185  template<typename T>
186  std::ostream& operator<<(std::ostream& output, const vsg::t_box<T>& bx)
187  {
188  output << std::endl;
189  output << " " << bx.min << std::endl;
190  output << " " << bx.max << std::endl;
191  return output;
192  }
193 
195  template<typename T>
196  std::istream& operator>>(std::istream& input, vsg::t_box<T>& bx)
197  {
198  input >> bx.min;
199  input >> bx.max;
200  return input;
201  }
202 
204  template<typename T>
205  std::ostream& operator<<(std::ostream& output, const vsg::ref_ptr<T>& ptr)
206  {
207  if (ptr)
208  output << "ref_ptr<" << vsg::type_name<T>() << ">(" << ptr->className() << " " << ptr.get() << ")";
209  else
210  output << "ref_ptr<" << vsg::type_name<T>() << ">(nullptr)";
211  return output;
212  }
213 
215  template<typename T, typename R>
216  std::ostream& operator<<(std::ostream& output, const std::pair<T, R>& wd)
217  {
218  output << wd.first << " " << wd.second;
219  return output;
220  }
221 
223  template<typename T, typename R>
224  std::istream& operator>>(std::istream& input, std::pair<T, R>& wd)
225  {
226  input >> wd.first >> wd.second;
227  return input;
228  }
229 
231  template<typename T>
232  std::ostream& operator<<(typename std::enable_if<std::is_enum<T>::value, std::ostream>::type& stream, const T& e)
233  {
234  return stream << static_cast<typename std::underlying_type<T>::type>(e);
235  }
236 
238  inline std::ostream& operator<<(std::ostream& output, const vsg::Path& path)
239  {
240  output << path.string();
241  return output;
242  }
243 
245  inline std::istream& operator>>(std::istream& input, vsg::Path& path)
246  {
247  std::string str;
248  input >> str;
249  path = str;
250  return input;
251  }
252 } // namespace vsg
Definition: Path.h:32
Definition: ref_ptr.h:22
t_box template class that represents an axis aligned bounding box
Definition: box.h:24
t_mat3 template class that represents a 3x3 matrix.
Definition: mat3.h:23
t_mat4 template class that represents a 4x4 matrix.
Definition: mat4.h:25
Definition: plane.h:33
t_quat template class that represents a quaternion
Definition: quat.h:35
template sphere class
Definition: sphere.h:34
t_vec2 template class that represents a 2D vector
Definition: vec2.h:38
t_vec3 template class that represents a 3D vector
Definition: vec3.h:34
t_vec4 template class that represents a 4D vector
Definition: vec4.h:35