9
3

io.hpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /// @ref gtx_io
  2. /// @file glm/gtx/io.hpp
  3. /// @author Jan P Springer (regnirpsj@gmail.com)
  4. ///
  5. /// @see core (dependence)
  6. /// @see gtc_matrix_access (dependence)
  7. /// @see gtc_quaternion (dependence)
  8. ///
  9. /// @defgroup gtx_io GLM_GTX_io
  10. /// @ingroup gtx
  11. ///
  12. /// Include <glm/gtx/io.hpp> to use the features of this extension.
  13. ///
  14. /// std::[w]ostream support for glm types
  15. ///
  16. /// std::[w]ostream support for glm types + qualifier/width/etc. manipulators
  17. /// based on howard hinnant's std::chrono io proposal
  18. /// [http://home.roadrunner.com/~hinnant/bloomington/chrono_io.html]
  19. #pragma once
  20. // Dependency:
  21. #include "../glm.hpp"
  22. #include "../gtx/quaternion.hpp"
  23. #if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
  24. # ifndef GLM_ENABLE_EXPERIMENTAL
  25. # pragma message("GLM: GLM_GTX_io is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it.")
  26. # else
  27. # pragma message("GLM: GLM_GTX_io extension included")
  28. # endif
  29. #endif
  30. #include <iosfwd> // std::basic_ostream<> (fwd)
  31. #include <locale> // std::locale, std::locale::facet, std::locale::id
  32. #include <utility> // std::pair<>
  33. namespace glm
  34. {
  35. /// @addtogroup gtx_io
  36. /// @{
  37. namespace io
  38. {
  39. enum order_type { column_major, row_major};
  40. template<typename CTy>
  41. class format_punct : public std::locale::facet
  42. {
  43. typedef CTy char_type;
  44. public:
  45. static std::locale::id id;
  46. bool formatted;
  47. unsigned precision;
  48. unsigned width;
  49. char_type separator;
  50. char_type delim_left;
  51. char_type delim_right;
  52. char_type space;
  53. char_type newline;
  54. order_type order;
  55. GLM_FUNC_DECL explicit format_punct(size_t a = 0);
  56. GLM_FUNC_DECL explicit format_punct(format_punct const&);
  57. };
  58. template<typename CTy, typename CTr = std::char_traits<CTy> >
  59. class basic_state_saver {
  60. public:
  61. GLM_FUNC_DECL explicit basic_state_saver(std::basic_ios<CTy,CTr>&);
  62. GLM_FUNC_DECL ~basic_state_saver();
  63. private:
  64. typedef ::std::basic_ios<CTy,CTr> state_type;
  65. typedef typename state_type::char_type char_type;
  66. typedef ::std::ios_base::fmtflags flags_type;
  67. typedef ::std::streamsize streamsize_type;
  68. typedef ::std::locale const locale_type;
  69. state_type& state_;
  70. flags_type flags_;
  71. streamsize_type precision_;
  72. streamsize_type width_;
  73. char_type fill_;
  74. locale_type locale_;
  75. GLM_FUNC_DECL basic_state_saver& operator=(basic_state_saver const&);
  76. };
  77. typedef basic_state_saver<char> state_saver;
  78. typedef basic_state_saver<wchar_t> wstate_saver;
  79. template<typename CTy, typename CTr = std::char_traits<CTy> >
  80. class basic_format_saver
  81. {
  82. public:
  83. GLM_FUNC_DECL explicit basic_format_saver(std::basic_ios<CTy,CTr>&);
  84. GLM_FUNC_DECL ~basic_format_saver();
  85. private:
  86. basic_state_saver<CTy> const bss_;
  87. GLM_FUNC_DECL basic_format_saver& operator=(basic_format_saver const&);
  88. };
  89. typedef basic_format_saver<char> format_saver;
  90. typedef basic_format_saver<wchar_t> wformat_saver;
  91. struct precision
  92. {
  93. unsigned value;
  94. GLM_FUNC_DECL explicit precision(unsigned);
  95. };
  96. struct width
  97. {
  98. unsigned value;
  99. GLM_FUNC_DECL explicit width(unsigned);
  100. };
  101. template<typename CTy>
  102. struct delimeter
  103. {
  104. CTy value[3];
  105. GLM_FUNC_DECL explicit delimeter(CTy /* left */, CTy /* right */, CTy /* separator */ = ',');
  106. };
  107. struct order
  108. {
  109. order_type value;
  110. GLM_FUNC_DECL explicit order(order_type);
  111. };
  112. // functions, inlined (inline)
  113. template<typename FTy, typename CTy, typename CTr>
  114. FTy const& get_facet(std::basic_ios<CTy,CTr>&);
  115. template<typename FTy, typename CTy, typename CTr>
  116. std::basic_ios<CTy,CTr>& formatted(std::basic_ios<CTy,CTr>&);
  117. template<typename FTy, typename CTy, typename CTr>
  118. std::basic_ios<CTy,CTr>& unformattet(std::basic_ios<CTy,CTr>&);
  119. template<typename CTy, typename CTr>
  120. std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, precision const&);
  121. template<typename CTy, typename CTr>
  122. std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, width const&);
  123. template<typename CTy, typename CTr>
  124. std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, delimeter<CTy> const&);
  125. template<typename CTy, typename CTr>
  126. std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, order const&);
  127. }//namespace io
  128. template<typename CTy, typename CTr, typename T, qualifier Q>
  129. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, qua<T, Q> const&);
  130. template<typename CTy, typename CTr, typename T, qualifier Q>
  131. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, vec<1, T, Q> const&);
  132. template<typename CTy, typename CTr, typename T, qualifier Q>
  133. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, vec<2, T, Q> const&);
  134. template<typename CTy, typename CTr, typename T, qualifier Q>
  135. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, vec<3, T, Q> const&);
  136. template<typename CTy, typename CTr, typename T, qualifier Q>
  137. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, vec<4, T, Q> const&);
  138. template<typename CTy, typename CTr, typename T, qualifier Q>
  139. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<2, 2, T, Q> const&);
  140. template<typename CTy, typename CTr, typename T, qualifier Q>
  141. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<2, 3, T, Q> const&);
  142. template<typename CTy, typename CTr, typename T, qualifier Q>
  143. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<2, 4, T, Q> const&);
  144. template<typename CTy, typename CTr, typename T, qualifier Q>
  145. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<3, 2, T, Q> const&);
  146. template<typename CTy, typename CTr, typename T, qualifier Q>
  147. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<3, 3, T, Q> const&);
  148. template<typename CTy, typename CTr, typename T, qualifier Q>
  149. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<3, 4, T, Q> const&);
  150. template<typename CTy, typename CTr, typename T, qualifier Q>
  151. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<4, 2, T, Q> const&);
  152. template<typename CTy, typename CTr, typename T, qualifier Q>
  153. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<4, 3, T, Q> const&);
  154. template<typename CTy, typename CTr, typename T, qualifier Q>
  155. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<4, 4, T, Q> const&);
  156. template<typename CTy, typename CTr, typename T, qualifier Q>
  157. GLM_FUNC_DECL std::basic_ostream<CTy,CTr> & operator<<(std::basic_ostream<CTy,CTr> &,
  158. std::pair<mat<4, 4, T, Q> const, mat<4, 4, T, Q> const> const&);
  159. /// @}
  160. }//namespace glm
  161. #include "io.inl"