diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-10-19 10:47:40 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-10-21 19:02:01 +0200 |
commit | 19c89827d68440780c918d32cae26eaa2241861d (patch) | |
tree | aefe16779c349b520fb77ca0086a93c456fe5ede | |
parent | cc569c1834e191eda45a328cfe34d15181d2d396 (diff) |
Add support for const data members
Const data members are automatically treated as readonly. New test:
const-member.
-rw-r--r-- | odb/tr1/wrapper-traits.hxx | 12 | ||||
-rw-r--r-- | odb/wrapper-traits.hxx | 44 |
2 files changed, 43 insertions, 13 deletions
diff --git a/odb/tr1/wrapper-traits.hxx b/odb/tr1/wrapper-traits.hxx index e65e2d7..f8a9f6c 100644 --- a/odb/tr1/wrapper-traits.hxx +++ b/odb/tr1/wrapper-traits.hxx @@ -26,6 +26,12 @@ namespace odb typedef T wrapped_type; typedef std::tr1::shared_ptr<T> wrapper_type; + // T can be const. + // + typedef + typename details::meta::remove_const<T>::result + unrestricted_wrapped_type; + static const bool null_handler = true; static const bool null_default = false; @@ -47,13 +53,13 @@ namespace odb return *p; } - static wrapped_type& + static unrestricted_wrapped_type& set_ref (wrapper_type& p) { if (!p) - p.reset (new wrapped_type); + p.reset (new unrestricted_wrapped_type); - return *p; + return const_cast<unrestricted_wrapped_type&> (*p); } }; } diff --git a/odb/wrapper-traits.hxx b/odb/wrapper-traits.hxx index fdfb872..f0686e7 100644 --- a/odb/wrapper-traits.hxx +++ b/odb/wrapper-traits.hxx @@ -12,6 +12,8 @@ #include <odb/nullable.hxx> +#include <odb/details/meta/remove-const.hxx> + namespace odb { template <typename T> @@ -34,6 +36,12 @@ namespace odb typedef T wrapped_type; typedef T* wrapper_type; + // T can be const. + // + typedef + typename details::meta::remove_const<T>::result + unrestricted_wrapped_type; + static const bool null_handler = true; static const bool null_default = false; @@ -50,19 +58,19 @@ namespace odb p = 0; } - static const type& + static const wrapped_type& get_ref (const wrapper_type& p) { return *p; } - static type& + static unrestricted_wrapped_type& set_ref (wrapper_type& p) { if (p == 0) - p = new type; + p = new unrestricted_wrapped_type; - return *p; + return const_cast<unrestricted_wrapped_type&> (*p); } }; #endif @@ -73,9 +81,17 @@ namespace odb class wrapper_traits< std::auto_ptr<T> > { public: + // T can be const. + // typedef T wrapped_type; typedef std::auto_ptr<T> wrapper_type; + // T can be const. + // + typedef + typename details::meta::remove_const<T>::result + unrestricted_wrapped_type; + static const bool null_handler = true; static const bool null_default = false; @@ -97,13 +113,13 @@ namespace odb return *p; } - static wrapped_type& + static unrestricted_wrapped_type& set_ref (wrapper_type& p) { if (p.get () == 0) - p.reset (new wrapped_type); + p.reset (new unrestricted_wrapped_type ()); - return *p; + return const_cast<unrestricted_wrapped_type&> (*p); } }; @@ -113,9 +129,17 @@ namespace odb class wrapper_traits< nullable<T> > { public: + // T can be const. + // typedef T wrapped_type; typedef nullable<T> wrapper_type; + // T can be const. + // + typedef + typename details::meta::remove_const<T>::result + unrestricted_wrapped_type; + static const bool null_handler = true; static const bool null_default = true; @@ -137,13 +161,13 @@ namespace odb return *n; } - static wrapped_type& + static unrestricted_wrapped_type& set_ref (wrapper_type& n) { if (n.null ()) - n = T (); + n = unrestricted_wrapped_type (); - return *n; + return const_cast<unrestricted_wrapped_type&> (*n); } }; } |