Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54329 - in sandbox/monotonic: boost/object_model boost/object_model/generic boost/object_model/type libs/object_model/src/generic libs/object_model/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-25 00:55:31


Author: cschladetsch
Date: 2009-06-25 00:55:26 EDT (Thu, 25 Jun 2009)
New Revision: 54329
URL: http://svn.boost.org/trac/boost/changeset/54329

Log:
added object<T>

Text files modified:
   sandbox/monotonic/boost/object_model/dereference.hpp | 15 +++++++++++----
   sandbox/monotonic/boost/object_model/exceptions.hpp | 4 ++++
   sandbox/monotonic/boost/object_model/generic/registry.hpp | 2 ++
   sandbox/monotonic/boost/object_model/object.hpp | 7 ++++---
   sandbox/monotonic/boost/object_model/registry.hpp | 8 ++++++++
   sandbox/monotonic/boost/object_model/storage.hpp | 36 ++++++++++++++++++++++++++++++++++++
   sandbox/monotonic/boost/object_model/type/traits.hpp | 8 ++++----
   sandbox/monotonic/libs/object_model/src/generic/object.cpp | 17 +++++++++++++++++
   sandbox/monotonic/libs/object_model/test/basic_tests.cpp | 19 ++++---------------
   9 files changed, 90 insertions(+), 26 deletions(-)

Modified: sandbox/monotonic/boost/object_model/dereference.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/dereference.hpp (original)
+++ sandbox/monotonic/boost/object_model/dereference.hpp 2009-06-25 00:55:26 EDT (Thu, 25 Jun 2009)
@@ -11,19 +11,26 @@
 
 #include <boost/object_model/detail/prefix.hpp>
 #include <boost/object_model/generic/object.hpp>
+#include <boost/object_model/storage.hpp>
 
 BOOST_OM_BEGIN
 
 template <class T>
-typename type::traits<T>::reference deref(generic::object &object)
+typename type::traits<T>::reference_type deref(generic::object &object)
 {
- throw;
+ if (!object.is_type<T>())
+ throw type_mismatch();
+ if (object.is_const())
+ throw const_error();
+ return static_cast<storage<T> &>(object.get_storage()).get_reference();
 }
 
 template <class T>
-typename type::traits<T>::const_reference const_deref(generic::object const &object)
+typename type::traits<T>::const_reference_type const_deref(generic::object const &object)
 {
- throw;
+ if (!object.is_type<T>())
+ throw type_mismatch();
+ return static_cast<const const_storage<T> &>(object.get_storage()).get_const_reference();
 }
 
 BOOST_OM_END

Modified: sandbox/monotonic/boost/object_model/exceptions.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/exceptions.hpp (original)
+++ sandbox/monotonic/boost/object_model/exceptions.hpp 2009-06-25 00:55:26 EDT (Thu, 25 Jun 2009)
@@ -25,6 +25,10 @@
 {
 };
 
+struct unknown_handle
+{
+};
+
 struct type_mismatch
 {
 };

Modified: sandbox/monotonic/boost/object_model/generic/registry.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/generic/registry.hpp (original)
+++ sandbox/monotonic/boost/object_model/generic/registry.hpp 2009-06-25 00:55:26 EDT (Thu, 25 Jun 2009)
@@ -23,6 +23,8 @@
         public:
 
                 virtual bool exists(handle) const = 0;
+ virtual storage &get_storage(handle) const = 0;
+
         };
 }
 

Modified: sandbox/monotonic/boost/object_model/object.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/object.hpp (original)
+++ sandbox/monotonic/boost/object_model/object.hpp 2009-06-25 00:55:26 EDT (Thu, 25 Jun 2009)
@@ -22,16 +22,17 @@
         typedef type::traits<T> traits;
 
         object() {}
- object(const generic::object &obj)
+
+ object(const generic::object &obj) : generic::object(obj)
         {
         }
 
- typename traits::reference reference()
+ typename traits::reference_type reference()
         {
                 return deref<T>(*this);
         }
 
- typename traits::reference operator*()
+ typename traits::reference_type operator*()
         {
                 return reference();
         }

Modified: sandbox/monotonic/boost/object_model/registry.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/registry.hpp (original)
+++ sandbox/monotonic/boost/object_model/registry.hpp 2009-06-25 00:55:26 EDT (Thu, 25 Jun 2009)
@@ -62,6 +62,14 @@
                 instances.erase(val);
         }
 
+ generic::storage &get_storage(handle h) const
+ {
+ instances_type::const_iterator iter = instances.find(h);
+ if (iter == instances.end())
+ throw unknown_handle();
+ return *iter->second;
+ }
+
         size_t num_classes() const
         {
                 return classes.size();

Modified: sandbox/monotonic/boost/object_model/storage.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/storage.hpp (original)
+++ sandbox/monotonic/boost/object_model/storage.hpp 2009-06-25 00:55:26 EDT (Thu, 25 Jun 2009)
@@ -15,10 +15,46 @@
 BOOST_OM_BEGIN
 
 template <class T>
+struct const_storage : generic::const_storage
+{
+ typedef type::traits<T> traits;
+ const typename traits::storage_type value;
+
+ const_storage() {}
+ const_storage(typename traits::const_reference_type init) : value(init) { }
+ typename traits::const_reference_type get_const_reference()
+ {
+ return value;
+ }
+};
+
+template <class T>
 struct storage : generic::storage
 {
         typedef type::traits<T> traits;
+ typename traits::storage_type value;
+ mutable bool dirty;
+
+ storage() : dirty(true) {}
+ storage(typename traits::const_reference_type init) : value(init), dirty(false) { }
 
+ typename traits::const_reference_type get_const_reference()
+ {
+ return value;
+ }
+ typename traits::reference_type get_reference()
+ {
+ dirty = true;
+ return value;
+ }
+ bool is_dirty() const
+ {
+ return dirty;
+ }
+ void set_clean() const
+ {
+ dirty = false;
+ }
 };
 
 BOOST_OM_END

Modified: sandbox/monotonic/boost/object_model/type/traits.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/type/traits.hpp (original)
+++ sandbox/monotonic/boost/object_model/type/traits.hpp 2009-06-25 00:55:26 EDT (Thu, 25 Jun 2009)
@@ -21,10 +21,10 @@
         struct traits_base
         {
                 typedef S Storage;
- typedef Storage type;
- typedef Storage *pointer;
- typedef Storage &reference;
- typedef Storage const &const_reference;
+ typedef Storage storage_type;
+ typedef Storage *pointer_type;
+ typedef Storage &reference_type;
+ typedef Storage const &const_reference_type;
         };
 
 }

Modified: sandbox/monotonic/libs/object_model/src/generic/object.cpp
==============================================================================
--- sandbox/monotonic/libs/object_model/src/generic/object.cpp (original)
+++ sandbox/monotonic/libs/object_model/src/generic/object.cpp 2009-06-25 00:55:26 EDT (Thu, 25 Jun 2009)
@@ -70,6 +70,11 @@
                 return get_registry().exists(number);
         }
 
+ const storage &object_base::get_storage() const
+ {
+ return get_registry().get_storage(get_handle());
+ }
+
         //---------------------------------------------------
         // const_object
         //---------------------------------------------------
@@ -99,6 +104,11 @@
         {
         }
 
+ storage &mutable_object::get_storage()
+ {
+ return get_registry().get_storage(get_handle());
+ }
+
         //---------------------------------------------------
         // object
         //---------------------------------------------------
@@ -124,6 +134,13 @@
                 konst = false;
                 return *this;
         }
+ storage &object::get_storage()
+ {
+ if (is_const())
+ throw const_error();
+ return get_registry().get_storage(get_handle());
+ }
+
 }
 
 const generic::object null_object;

Modified: sandbox/monotonic/libs/object_model/test/basic_tests.cpp
==============================================================================
--- sandbox/monotonic/libs/object_model/test/basic_tests.cpp (original)
+++ sandbox/monotonic/libs/object_model/test/basic_tests.cpp 2009-06-25 00:55:26 EDT (Thu, 25 Jun 2009)
@@ -18,25 +18,12 @@
 #include <boost/object_model/type/builtins.hpp>
 #include <boost/object_model/builder.hpp>
 #include <boost/object_model/type/traits.hpp>
+#include <boost/object_model/dereference.hpp>
 
 using namespace std;
 using namespace boost;
 namespace om = boost::object_model;
 
-//BOOST_OM_BEGIN
-//namespace type
-//{
-// template <>
-// struct traits<void>// : traits_base<void,number::Void,int>
-// {
-// BOOST_STATIC_CONSTANT(short, type_number = 42);//static int type_number = 42;
-// static const char *name;
-// };
-// //int traits<void>::type_number = 42;//number::Void;
-// const char * traits<void>::name = "Void";
-//}
-//BOOST_OM_END
-
 BOOST_AUTO_TEST_CASE(test_type_traits)
 {
         BOOST_STATIC_ASSERT(om::type::traits<int>::type_number == om::type::number::Int);
@@ -69,11 +56,13 @@
 BOOST_AUTO_TEST_CASE(test_object)
 {
         om::registry<> reg;
+ reg.register_class<int>();
+ BOOST_ASSERT(reg.has_class<int>());
         om::object<int> num = reg.create<int>();
         BOOST_ASSERT(num.exists());
         BOOST_ASSERT(num.is_type<int>());
         *num = 42;
-// BOOST_ASSERT(deref<int>(num) == 42);
+ BOOST_ASSERT(om::deref<int>(num) == 42);
 }
 
 struct Foo


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk