vsg 1.1.3
VulkanSceneGraph library
Loading...
Searching...
No Matches
stream.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2018 Robert Osfield
6
7Permission 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
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE 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
32namespace vsg
33{
34
37 {
38 int indent = 0;
39
40 indentation& operator+=(int delta)
41 {
42 indent += delta;
43 return *this;
44 }
45 indentation& operator-=(int delta)
46 {
47 indent -= delta;
48 return *this;
49 }
50 };
51
52 inline indentation operator+(const indentation& lhs, const int rhs) { return indentation{lhs.indent + rhs}; }
53 inline indentation operator-(const indentation& lhs, const int rhs) { return indentation{lhs.indent - rhs}; }
54
55 inline std::ostream& operator<<(std::ostream& output, const indentation& in)
56 {
57 for (int i = 0; i < in.indent; ++i) output.put(' ');
58 return output;
59 }
60
62 template<typename... Args>
63 std::string make_string(const Args&... args)
64 {
65 std::ostringstream stream;
66 (stream << ... << args);
67 return stream.str();
68 }
69
71 template<typename T>
72 std::ostream& operator<<(std::ostream& output, const vsg::t_vec2<T>& vec)
73 {
74 output << vec.x << " " << vec.y;
75 return output;
76 }
77
79 template<typename T>
80 std::istream& operator>>(std::istream& input, vsg::t_vec2<T>& vec)
81 {
82 input >> vec.x >> vec.y;
83 return input;
84 }
85
87 template<typename T>
88 std::ostream& operator<<(std::ostream& output, const vsg::t_vec3<T>& vec)
89 {
90 output << vec.x << " " << vec.y << " " << vec.z;
91 return output;
92 }
93
95 template<typename T>
96 std::istream& operator>>(std::istream& input, vsg::t_vec3<T>& vec)
97 {
98 input >> vec.x >> vec.y >> vec.z;
99 return input;
100 }
101
103 template<typename T>
104 std::ostream& operator<<(std::ostream& output, const vsg::t_vec4<T>& vec)
105 {
106 output << vec.x << " " << vec.y << " " << vec.z << " " << vec.w;
107 return output;
108 }
109
111 template<typename T>
112 std::istream& operator>>(std::istream& input, vsg::t_vec4<T>& vec)
113 {
114 input >> vec.x >> vec.y >> vec.z >> vec.w;
115 return input;
116 }
117
119 template<typename T>
120 std::ostream& operator<<(std::ostream& output, const vsg::t_quat<T>& q)
121 {
122 output << q.x << " " << q.y << " " << q.z << " " << q.w;
123 return output;
124 }
125
127 template<typename T>
128 std::istream& operator>>(std::istream& input, vsg::t_quat<T>& q)
129 {
130 input >> q.x >> q.y >> q.z >> q.w;
131 return input;
132 }
133
135 template<typename T>
136 std::ostream& operator<<(std::ostream& output, const vsg::t_plane<T>& vec)
137 {
138 output << vec.value[0] << " " << vec.value[1] << " " << vec.value[2] << " " << vec.value[3];
139 return output;
140 }
141
143 template<typename T>
144 std::istream& operator>>(std::istream& input, vsg::t_plane<T>& vec)
145 {
146 input >> vec.value[0] >> vec.value[1] >> vec.value[2] >> vec.value[3];
147 return input;
148 }
149
151 template<typename T>
152 std::ostream& operator<<(std::ostream& output, const vsg::t_mat3<T>& mat)
153 {
154 output << std::endl;
155 output << " " << mat(0, 0) << " " << mat(1, 0) << " " << mat(2, 0) << std::endl;
156 output << " " << mat(0, 1) << " " << mat(1, 1) << " " << mat(2, 1) << std::endl;
157 output << " " << mat(0, 2) << " " << mat(1, 2) << " " << mat(2, 2) << std::endl;
158 return output;
159 }
160
162 template<typename T>
163 std::istream& operator>>(std::istream& input, vsg::t_mat3<T>& mat)
164 {
165 input >> mat(0, 0) >> mat(1, 0) >> mat(2, 0);
166 input >> mat(0, 1) >> mat(1, 1) >> mat(2, 1);
167 input >> mat(0, 2) >> mat(1, 2) >> mat(2, 2);
168 return input;
169 }
170
172 template<typename T>
173 std::ostream& operator<<(std::ostream& output, const vsg::t_mat4<T>& mat)
174 {
175 output << std::endl;
176 output << " " << mat(0, 0) << " " << mat(1, 0) << " " << mat(2, 0) << " " << mat(3, 0) << std::endl;
177 output << " " << mat(0, 1) << " " << mat(1, 1) << " " << mat(2, 1) << " " << mat(3, 1) << std::endl;
178 output << " " << mat(0, 2) << " " << mat(1, 2) << " " << mat(2, 2) << " " << mat(3, 2) << std::endl;
179 output << " " << mat(0, 3) << " " << mat(1, 3) << " " << mat(2, 3) << " " << mat(3, 3) << std::endl;
180 return output;
181 }
182
184 template<typename T>
185 std::istream& operator>>(std::istream& input, vsg::t_mat4<T>& mat)
186 {
187 input >> mat(0, 0) >> mat(1, 0) >> mat(2, 0) >> mat(3, 0);
188 input >> mat(0, 1) >> mat(1, 1) >> mat(2, 1) >> mat(3, 1);
189 input >> mat(0, 2) >> mat(1, 2) >> mat(2, 2) >> mat(3, 2);
190 input >> mat(0, 3) >> mat(1, 3) >> mat(2, 3) >> mat(3, 3);
191 return input;
192 }
193
195 template<typename T>
196 std::ostream& operator<<(std::ostream& output, const vsg::t_sphere<T>& sp)
197 {
198 output << sp.vec;
199 return output;
200 }
201
203 template<typename T>
204 std::istream& operator>>(std::istream& input, vsg::t_sphere<T>& sp)
205 {
206 input >> sp.vec;
207 return input;
208 }
209
211 template<typename T>
212 std::ostream& operator<<(std::ostream& output, const vsg::t_box<T>& bx)
213 {
214 output << std::endl;
215 output << " " << bx.min << std::endl;
216 output << " " << bx.max << std::endl;
217 return output;
218 }
219
221 template<typename T>
222 std::istream& operator>>(std::istream& input, vsg::t_box<T>& bx)
223 {
224 input >> bx.min;
225 input >> bx.max;
226 return input;
227 }
228
230 template<typename T>
231 std::ostream& operator<<(std::ostream& output, const vsg::ref_ptr<T>& ptr)
232 {
233 if (ptr)
234 output << "ref_ptr<" << vsg::type_name<T>() << ">(" << ptr->className() << " " << ptr.get() << ")";
235 else
236 output << "ref_ptr<" << vsg::type_name<T>() << ">(nullptr)";
237 return output;
238 }
239
241 template<typename T, typename R>
242 std::ostream& operator<<(std::ostream& output, const std::pair<T, R>& wd)
243 {
244 output << wd.first << " " << wd.second;
245 return output;
246 }
247
249 template<typename T, typename R>
250 std::istream& operator>>(std::istream& input, std::pair<T, R>& wd)
251 {
252 input >> wd.first >> wd.second;
253 return input;
254 }
255
257 template<typename T>
258 std::ostream& operator<<(typename std::enable_if<std::is_enum<T>::value, std::ostream>::type& stream, const T& e)
259 {
260 return stream << static_cast<typename std::underlying_type<T>::type>(e);
261 }
262
264 inline std::ostream& operator<<(std::ostream& output, const vsg::Path& path)
265 {
266 output << path.string();
267 return output;
268 }
269
271 inline std::istream& operator>>(std::istream& input, vsg::Path& path)
272 {
273 std::string str;
274 input >> str;
275 path = str;
276 return input;
277 }
278} // namespace vsg
Definition Path.h:34
Definition ref_ptr.h:22
helper class for inserting indentation into streams useful for formatting output.
Definition stream.h:37
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