io.hpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /// @ref gtx_io
  2. /// @file glm/gtx/io.hpp
  3. /// @author Jan P Springer ([email protected])
  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. #ifndef GLM_ENABLE_EXPERIMENTAL
  24. # error "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."
  25. #endif
  26. #if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
  27. # pragma message("GLM: GLM_GTX_io extension included")
  28. #endif
  29. #include <iosfwd> // std::basic_ostream<> (fwd)
  30. #include <locale> // std::locale, std::locale::facet, std::locale::id
  31. #include <utility> // std::pair<>
  32. namespace glm
  33. {
  34. /// @addtogroup gtx_io
  35. /// @{
  36. namespace io
  37. {
  38. enum order_type { column_major, row_major};
  39. template<typename CTy>
  40. class format_punct : public std::locale::facet
  41. {
  42. typedef CTy char_type;
  43. public:
  44. static std::locale::id id;
  45. bool formatted;
  46. unsigned precision;
  47. unsigned width;
  48. char_type separator;
  49. char_type delim_left;
  50. char_type delim_right;
  51. char_type space;
  52. char_type newline;
  53. order_type order;
  54. GLM_FUNC_DECL explicit format_punct(size_t a = 0);
  55. GLM_FUNC_DECL explicit format_punct(format_punct const&);
  56. };
  57. template<typename CTy, typename CTr = std::char_traits<CTy> >
  58. class basic_state_saver {
  59. public:
  60. GLM_FUNC_DECL explicit basic_state_saver(std::basic_ios<CTy,CTr>&);
  61. GLM_FUNC_DECL ~basic_state_saver();
  62. private:
  63. typedef ::std::basic_ios<CTy,CTr> state_type;
  64. typedef typename state_type::char_type char_type;
  65. typedef ::std::ios_base::fmtflags flags_type;
  66. typedef ::std::streamsize streamsize_type;
  67. typedef ::std::locale const locale_type;
  68. state_type& state_;
  69. flags_type flags_;
  70. streamsize_type precision_;
  71. streamsize_type width_;
  72. char_type fill_;
  73. locale_type locale_;
  74. GLM_FUNC_DECL basic_state_saver& operator=(basic_state_saver const&);
  75. };
  76. typedef basic_state_saver<char> state_saver;
  77. typedef basic_state_saver<wchar_t> wstate_saver;
  78. template<typename CTy, typename CTr = std::char_traits<CTy> >
  79. class basic_format_saver
  80. {
  81. public:
  82. GLM_FUNC_DECL explicit basic_format_saver(std::basic_ios<CTy,CTr>&);
  83. GLM_FUNC_DECL ~basic_format_saver();
  84. private:
  85. basic_state_saver<CTy> const bss_;
  86. GLM_FUNC_DECL basic_format_saver& operator=(basic_format_saver const&);
  87. };
  88. typedef basic_format_saver<char> format_saver;
  89. typedef basic_format_saver<wchar_t> wformat_saver;
  90. struct precision
  91. {
  92. unsigned value;
  93. GLM_FUNC_DECL explicit precision(unsigned);
  94. };
  95. struct width
  96. {
  97. unsigned value;
  98. GLM_FUNC_DECL explicit width(unsigned);
  99. };
  100. template<typename CTy>
  101. struct delimeter
  102. {
  103. CTy value[3];
  104. GLM_FUNC_DECL explicit delimeter(CTy /* left */, CTy /* right */, CTy /* separator */ = ',');
  105. };
  106. struct order
  107. {
  108. order_type value;
  109. GLM_FUNC_DECL explicit order(order_type);
  110. };
  111. // functions, inlined (inline)
  112. template<typename FTy, typename CTy, typename CTr>
  113. FTy const& get_facet(std::basic_ios<CTy,CTr>&);
  114. template<typename FTy, typename CTy, typename CTr>
  115. std::basic_ios<CTy,CTr>& formatted(std::basic_ios<CTy,CTr>&);
  116. template<typename FTy, typename CTy, typename CTr>
  117. std::basic_ios<CTy,CTr>& unformattet(std::basic_ios<CTy,CTr>&);
  118. template<typename CTy, typename CTr>
  119. std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, precision const&);
  120. template<typename CTy, typename CTr>
  121. std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, width const&);
  122. template<typename CTy, typename CTr>
  123. std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, delimeter<CTy> const&);
  124. template<typename CTy, typename CTr>
  125. std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, order const&);
  126. }//namespace io
  127. template<typename CTy, typename CTr, typename T, qualifier Q>
  128. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, qua<T, Q> const&);
  129. template<typename CTy, typename CTr, typename T, qualifier Q>
  130. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, vec<1, T, Q> const&);
  131. template<typename CTy, typename CTr, typename T, qualifier Q>
  132. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, vec<2, T, Q> const&);
  133. template<typename CTy, typename CTr, typename T, qualifier Q>
  134. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, vec<3, T, Q> const&);
  135. template<typename CTy, typename CTr, typename T, qualifier Q>
  136. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, vec<4, T, Q> const&);
  137. template<typename CTy, typename CTr, typename T, qualifier Q>
  138. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<2, 2, T, Q> const&);
  139. template<typename CTy, typename CTr, typename T, qualifier Q>
  140. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<2, 3, T, Q> const&);
  141. template<typename CTy, typename CTr, typename T, qualifier Q>
  142. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<2, 4, T, Q> const&);
  143. template<typename CTy, typename CTr, typename T, qualifier Q>
  144. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<3, 2, T, Q> const&);
  145. template<typename CTy, typename CTr, typename T, qualifier Q>
  146. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<3, 3, T, Q> const&);
  147. template<typename CTy, typename CTr, typename T, qualifier Q>
  148. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<3, 4, T, Q> const&);
  149. template<typename CTy, typename CTr, typename T, qualifier Q>
  150. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<4, 2, T, Q> const&);
  151. template<typename CTy, typename CTr, typename T, qualifier Q>
  152. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<4, 3, T, Q> const&);
  153. template<typename CTy, typename CTr, typename T, qualifier Q>
  154. GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<4, 4, T, Q> const&);
  155. template<typename CTy, typename CTr, typename T, qualifier Q>
  156. GLM_FUNC_DECL std::basic_ostream<CTy,CTr> & operator<<(std::basic_ostream<CTy,CTr> &,
  157. std::pair<mat<4, 4, T, Q> const, mat<4, 4, T, Q> const> const&);
  158. /// @}
  159. }//namespace glm
  160. #include "io.inl"