Browse Source

removed boost dependencies

jan p springer 12 years ago
parent
commit
0e3cebf23a
3 changed files with 103 additions and 27 deletions
  1. 38 8
      glm/gtx/io.hpp
  2. 30 11
      glm/gtx/io.inl
  3. 35 8
      test/gtx/gtx_io.cpp

+ 38 - 8
glm/gtx/io.hpp

@@ -26,7 +26,7 @@
 /// @author Jan P Springer ([email protected])
 ///
 /// @see core (dependence)
-/// @see gtx_quaternion (dependence)
+/// @see gtc_quaternion (dependence)
 ///
 /// @defgroup gtx_io GLM_GTX_io
 /// @ingroup gtx
@@ -51,11 +51,9 @@
 #	pragma message("GLM: GLM_GTX_io extension included")
 #endif
 
-#include <boost/io_fwd.hpp>      // basic_ios_all_saver<> (fwd)
-#include <boost/noncopyable.hpp> // boost::noncopyable
-#include <iosfwd>                // std::basic_ostream<> (fwd)
-#include <locale>                // std::locale, std::locale::facet, std::locale::id
-#include <utility>               // std::pair<>
+#include <iosfwd>  // std::basic_ostream<> (fwd)
+#include <locale>  // std::locale, std::locale::facet, std::locale::id
+#include <utility> // std::pair<>
 
 namespace glm
 {
@@ -92,7 +90,37 @@ namespace glm
     };
 
     template <typename CTy, typename CTr = std::char_traits<CTy> >
-    class basic_format_saver : private boost::noncopyable {
+    class basic_state_saver {
+
+    public:
+
+      explicit basic_state_saver(std::basic_ios<CTy,CTr>&);
+              ~basic_state_saver();
+
+    private:
+
+      typedef ::std::basic_ios<CTy,CTr>      state_type;
+      typedef typename state_type::char_type char_type;
+      typedef ::std::ios_base::fmtflags      flags_type;
+      typedef ::std::streamsize              streamsize_type;
+      typedef ::std::locale const            locale_type;
+      
+      state_type&     state_;
+      flags_type      flags_;
+      streamsize_type precision_;
+      streamsize_type width_;
+      char_type       fill_;
+      locale_type     locale_;
+      
+      basic_state_saver& operator=(basic_state_saver const&);
+      
+    };
+
+    typedef basic_state_saver<char>     state_saver;
+    typedef basic_state_saver<wchar_t> wstate_saver;
+    
+    template <typename CTy, typename CTr = std::char_traits<CTy> >
+    class basic_format_saver {
 
     public:
 
@@ -101,7 +129,9 @@ namespace glm
 
     private:
 
-      boost::io::basic_ios_all_saver<CTy> const ias_;
+      basic_state_saver<CTy> const bss_;
+
+      basic_format_saver& operator=(basic_format_saver const&);
       
     };
 

+ 30 - 11
glm/gtx/io.inl

@@ -2,15 +2,13 @@
 // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Created : 2013-11-22
-// Updated : 2013-12-17
+// Updated : 2013-12-18
 // Licence : This source is under MIT License
 // File    : glm/gtx/inl.inl
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-#include <boost/io/ios_state.hpp> // boost::io::ios_all_saver
-#include <iomanip>                // std::setfill<>, std::fixed, std::setprecision, std::right,
-                                  // std::setw
-#include <ostream>                // std::basic_ostream<>
+#include <iomanip> // std::setfill<>, std::fixed, std::setprecision, std::right, std::setw
+#include <ostream> // std::basic_ostream<>
 
 namespace glm
 {
@@ -49,11 +47,32 @@ namespace glm
     
     template <typename CTy> std::locale::id format_punct<CTy>::id;
 
+    template <typename CTy, typename CTr>
+    /* explicit */ GLM_FUNC_QUALIFIER
+    basic_state_saver<CTy,CTr>::basic_state_saver(std::basic_ios<CTy,CTr>& a)
+      : state_    (a),
+        flags_    (a.flags()),
+        precision_(a.precision()),
+        width_    (a.width()),
+        fill_     (a.fill()),
+        locale_   (a.getloc())
+    {}
+    
+    template <typename CTy, typename CTr>
+    GLM_FUNC_QUALIFIER
+    basic_state_saver<CTy,CTr>::~basic_state_saver()
+    {
+      state_.imbue(locale_);
+      state_.fill(fill_);
+      state_.width(width_);
+      state_.precision(precision_);
+      state_.flags(flags_);
+    }
+    
     template <typename CTy, typename CTr>
     /* explicit */ GLM_FUNC_QUALIFIER
     basic_format_saver<CTy,CTr>::basic_format_saver(std::basic_ios<CTy,CTr>& a)
-      : boost::noncopyable(),
-        ias_              (a)
+      : bss_(a)
     {
       a.imbue(std::locale(a.getloc(), new format_punct<CTy>(get_facet<format_punct<CTy>>(a))));
     }
@@ -171,7 +190,7 @@ namespace glm
         io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy>>(os));
 
         if (fmt.formatted) {
-          boost::io::basic_ios_all_saver<CTy> const ias(os);
+          io::basic_state_saver<CTy> const bss(os);
         
           os << std::fixed
              << std::right
@@ -201,7 +220,7 @@ namespace glm
         io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy>>(os));
 
         if (fmt.formatted) {
-          boost::io::basic_ios_all_saver<CTy> const ias(os);
+          io::basic_state_saver<CTy> const bss(os);
           
           os << std::fixed
              << std::right
@@ -229,7 +248,7 @@ namespace glm
         io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy>>(os));
 
         if (fmt.formatted) {
-          boost::io::basic_ios_all_saver<CTy> const ias(os);
+          io::basic_state_saver<CTy> const bss(os);
           
           os << std::fixed
              << std::right
@@ -258,7 +277,7 @@ namespace glm
         io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy>>(os));
 
         if (fmt.formatted) {
-          boost::io::basic_ios_all_saver<CTy> const ias(os);
+          io::basic_state_saver<CTy> const bss(os);
         
           os << std::fixed
              << std::right

+ 35 - 8
test/gtx/gtx_io.cpp

@@ -11,6 +11,7 @@
 #include <glm/gtc/type_precision.hpp>
 #include <glm/gtx/io.hpp>
 #include <iostream>
+#include <sstream>
 #include <typeinfo>
 
 namespace {
@@ -32,6 +33,32 @@ namespace {
     return os;
   }
 
+  template <typename U, glm::precision P, typename T, typename CTy, typename CTr>
+  std::basic_string<CTy>
+  type_name(std::basic_ostream<CTy,CTr>& os, T const&)
+  {
+    std::basic_ostringstream<CTy,CTr> ostr;
+    
+    if      (typeid(T) == typeid(glm::detail::tquat<U,P>))   { ostr << "quat"; }
+    else if (typeid(T) == typeid(glm::detail::tvec2<U,P>))   { ostr << "vec2"; }
+    else if (typeid(T) == typeid(glm::detail::tvec3<U,P>))   { ostr << "vec3"; }
+    else if (typeid(T) == typeid(glm::detail::tvec4<U,P>))   { ostr << "vec4"; }
+    else if (typeid(T) == typeid(glm::detail::tmat2x2<U,P>)) { ostr << "mat2x2"; }
+    else if (typeid(T) == typeid(glm::detail::tmat2x3<U,P>)) { ostr << "mat2x3"; }
+    else if (typeid(T) == typeid(glm::detail::tmat2x4<U,P>)) { ostr << "mat2x4"; }
+    else if (typeid(T) == typeid(glm::detail::tmat3x2<U,P>)) { ostr << "mat3x2"; }
+    else if (typeid(T) == typeid(glm::detail::tmat3x3<U,P>)) { ostr << "mat3x3"; }
+    else if (typeid(T) == typeid(glm::detail::tmat3x4<U,P>)) { ostr << "mat3x4"; }
+    else if (typeid(T) == typeid(glm::detail::tmat4x2<U,P>)) { ostr << "mat4x2"; }
+    else if (typeid(T) == typeid(glm::detail::tmat4x3<U,P>)) { ostr << "mat4x3"; }
+    else if (typeid(T) == typeid(glm::detail::tmat4x4<U,P>)) { ostr << "mat4x4"; }
+    else                                                     { ostr << "unknown"; }
+
+    ostr << '<' << typeid(U).name() << ',' << P << '>';
+
+    return ostr.str();
+  }
+  
 } // namespace {
 
 template <typename T, glm::precision P, typename OS>
@@ -47,14 +74,14 @@ int test_io_quat(OS& os)
     glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
     
     os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2)
-       << "quat<" << typeid(T).name() << ',' << P << ">: " << q << '\n';
+       << type_name<T,P>(os, q) << ": " << q << '\n';
   }
   
   {
     glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
   
     os << glm::io::unformatted()
-       << "quat<" << typeid(T).name() << ',' << P << ">: " << q << '\n';
+       << type_name<T,P>(os, q) << ": " << q << '\n';
   }  
 
   return 0;
@@ -71,16 +98,16 @@ int test_io_vec(OS& os)
   glm::detail::tvec3<T,P> const v3(2, 3, 4);
   glm::detail::tvec4<T,P> const v4(5, 6, 7, 8);
 
-  os << "vec2<" << typeid(T).name() << ',' << P << ">: " << v2 << '\n'
-     << "vec3<" << typeid(T).name() << ',' << P << ">: " << v3 << '\n'
-     << "vec4<" << typeid(T).name() << ',' << P << ">: " << v4 << '\n';
+  os << type_name<T,P>(os, v2) << ": " << v2 << '\n'
+     << type_name<T,P>(os, v3) << ": " << v3 << '\n'
+     << type_name<T,P>(os, v4) << ": " << v4 << '\n';
 
   glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
   
   os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2)
-     << "vec2<" << typeid(T).name() << ',' << P << ">: " << v2 << '\n'
-     << "vec3<" << typeid(T).name() << ',' << P << ">: " << v3 << '\n'
-     << "vec4<" << typeid(T).name() << ',' << P << ">: " << v4 << '\n';
+     << type_name<T,P>(os, v2) << ": " << v2 << '\n'
+     << type_name<T,P>(os, v3) << ": " << v3 << '\n'
+     << type_name<T,P>(os, v4) << ": " << v4 << '\n';
 
   return 0;
 }