• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1///////////////////////////////////////////////////////////////////////////////////////////////////
2// OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
3///////////////////////////////////////////////////////////////////////////////////////////////////
4// Created : 2013-11-22
5// Updated : 2013-11-22
6// Licence : This source is under MIT License
7// File    : glm/gtx/inl.inl
8///////////////////////////////////////////////////////////////////////////////////////////////////
9
10#include "../matrix.hpp"
11// #include <boost/io/ios_state.hpp> // boost::io::ios_all_saver
12#include <iomanip>                // std::setfill<>, std::fixed, std::setprecision, std::right,
13                                  // std::setw
14#include <ostream>                // std::basic_ostream<>
15
16namespace glm{
17namespace io
18{
19
20    /* explicit */ GLM_FUNC_QUALIFIER
21    precision_guard::precision_guard()
22      : precision_  (precision()),
23        value_width_(value_width())
24    {}
25
26    GLM_FUNC_QUALIFIER
27    precision_guard::~precision_guard()
28    {
29      value_width() = value_width_;
30      precision()   = precision_;
31    }
32
33    /* explicit */ GLM_FUNC_QUALIFIER
34    format_guard::format_guard()
35      : order_(order()),
36        cr_   (cr())
37    {}
38
39    GLM_FUNC_QUALIFIER
40    format_guard::~format_guard()
41    {
42      cr()    = cr_;
43      order() = order_;
44    }
45
46    GLM_FUNC_QUALIFIER unsigned& precision()
47    {
48      static unsigned p(3);
49
50      return p;
51    }
52
53    GLM_FUNC_QUALIFIER unsigned& value_width()
54    {
55      static unsigned p(9);
56
57      return p;
58    }
59
60    GLM_FUNC_QUALIFIER format_guard::order_t& order()
61    {
62      static format_guard::order_t p(format_guard::row_major);
63
64      return p;
65    }
66
67    GLM_FUNC_QUALIFIER char&
68    cr()
69    {
70      static char p('\n'); return p;
71    }
72
73    GLM_FUNC_QUALIFIER std::ios_base& column_major(std::ios_base& os)
74    {
75      order() = format_guard::column_major;
76
77      return os;
78    }
79
80    GLM_FUNC_QUALIFIER std::ios_base& row_major(std::ios_base& os)
81    {
82      order() = format_guard::row_major;
83
84      return os;
85    }
86
87    GLM_FUNC_QUALIFIER std::ios_base& formatted(std::ios_base& os)
88    {
89      cr() = '\n';
90
91      return os;
92    }
93
94    GLM_FUNC_QUALIFIER std::ios_base& unformatted(std::ios_base& os)
95    {
96      cr() = ' ';
97
98      return os;
99    }
100
101} // namespace io
102namespace detail
103{
104    // functions, inlined (inline)
105
106    template <typename CTy, typename CTr, typename T, precision P>
107    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tquat<T,P> const& a)
108    {
109      typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
110
111      if (cerberus) {
112        // boost::io::ios_all_saver const ias(os);
113
114        os << std::fixed << std::setprecision(io::precision())
115           << '['
116           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.w << ','
117           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.x << ','
118           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.y << ','
119           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.z
120           << ']';
121      }
122
123      return os;
124    }
125
126    template <typename CTy, typename CTr, typename T, precision P>
127    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tvec2<T,P> const& a)
128    {
129      typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
130
131      if (cerberus) {
132        // boost::io::ios_all_saver const ias(os);
133
134        os << std::fixed << std::setprecision(io::precision())
135           << '['
136           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.x << ','
137           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.y
138           << ']';
139      }
140
141      return os;
142    }
143
144    template <typename CTy, typename CTr, typename T, precision P>
145    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tvec3<T,P> const& a)
146    {
147      typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
148
149      if (cerberus) {
150        // boost::io::ios_all_saver const ias(os);
151
152        os << std::fixed << std::setprecision(io::precision())
153           << '['
154           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.x << ','
155           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.y << ','
156           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.z
157           << ']';
158      }
159
160      return os;
161    }
162
163    template <typename CTy, typename CTr, typename T, precision P>
164    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tvec4<T,P> const& a)
165    {
166      typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
167
168      if (cerberus) {
169        // boost::io::ios_all_saver const ias(os);
170
171        os << std::fixed << std::setprecision(io::precision())
172           << '['
173           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.x << ','
174           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.y << ','
175           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.z << ','
176           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.w
177           << ']';
178      }
179
180      return os;
181    }
182
183    template <typename CTy, typename CTr, typename T, precision P>
184    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat2x2<T,P> const& m)
185    {
186      typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
187
188      if (cerberus) {
189
190        os << io::cr()
191           << '[' << m[0] << io::cr()
192           << ' ' << m[1] << ']';
193      }
194
195      return os;
196    }
197
198    template <typename CTy, typename CTr, typename T, precision P>
199    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat2x3<T,P> const& m)
200    {
201      typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
202
203      if (cerberus) {
204
205        os << io::cr()
206           << '[' << m[0] << io::cr()
207           << ' ' << m[1] << ']';
208      }
209
210      return os;
211    }
212
213    template <typename CTy, typename CTr, typename T, precision P>
214    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat2x4<T,P> const& m)
215    {
216      typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
217
218      if (cerberus) {
219
220        os << io::cr()
221           << '[' << m[0] << io::cr()
222           << ' ' << m[1] << ']';
223      }
224
225      return os;
226    }
227
228    template <typename CTy, typename CTr, typename T, precision P>
229    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat3x2<T,P> const& m)
230    {
231      typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
232
233      if (cerberus) {
234
235        os << io::cr()
236           << '[' << m[0] << io::cr()
237           << ' ' << m[1] << io::cr()
238           << ' ' << m[2] << ']';
239      }
240
241      return os;
242    }
243
244    template <typename CTy, typename CTr, typename T, precision P>
245    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat3x3<T,P> const& m)
246    {
247      typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
248
249      if (cerberus) {
250
251        os << io::cr()
252           << '[' << m[0] << io::cr()
253           << ' ' << m[1] << io::cr()
254           << ' ' << m[2] << ']';
255      }
256
257      return os;
258    }
259
260    template <typename CTy, typename CTr, typename T, precision P>
261    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat3x4<T,P> const& m)
262    {
263      typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
264
265      if (cerberus) {
266
267        os << io::cr()
268           << '[' << m[0] << io::cr()
269           << ' ' << m[1] << io::cr()
270           << ' ' << m[2] << ']';
271      }
272
273      return os;
274    }
275
276    template <typename CTy, typename CTr, typename T, precision P>
277    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat4x2<T,P> const& m)
278    {
279      typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
280
281      if (cerberus) {
282
283        os << io::cr()
284           << '[' << m[0] << io::cr()
285           << ' ' << m[1] << io::cr()
286           << ' ' << m[2] << io::cr()
287           << ' ' << m[3] << ']';
288      }
289
290      return os;
291    }
292
293    template <typename CTy, typename CTr, typename T, precision P>
294    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat4x3<T,P> const& m)
295    {
296      typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
297
298      if (cerberus) {
299
300        os << io::cr()
301           << '[' << m[0] << io::cr()
302           << ' ' << m[1] << io::cr()
303           << ' ' << m[2] << io::cr()
304           << ' ' << m[3] << ']';
305      }
306
307      return os;
308    }
309
310    template <typename CTy, typename CTr, typename T, precision P>
311    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat4x4<T,P> const& m)
312    {
313      typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
314
315      if (cerberus) {
316
317        os << io::cr()
318           << '[' << m[0] << io::cr()
319           << ' ' << m[1] << io::cr()
320           << ' ' << m[2] << io::cr()
321           << ' ' << m[3] << ']';
322      }
323
324      return os;
325    }
326
327}//namespace detail
328}//namespace glm
329