|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r54384 - in sandbox/monotonic: boost/object_model boost/object_model/containers boost/object_model/detail libs/object_model/src libs/object_model/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-26 18:12:20
Author: cschladetsch
Date: 2009-06-26 18:12:18 EDT (Fri, 26 Jun 2009)
New Revision: 54384
URL: http://svn.boost.org/trac/boost/changeset/54384
Log:
added detail/base_type, arity-1 methods
Added:
sandbox/monotonic/boost/object_model/detail/base_type.hpp (contents, props changed)
Text files modified:
sandbox/monotonic/boost/object_model/builder.hpp | 5
sandbox/monotonic/boost/object_model/class.hpp | 10 +-
sandbox/monotonic/boost/object_model/containers/vector.hpp | 6 +
sandbox/monotonic/boost/object_model/detail/class_base.hpp | 13 +-
sandbox/monotonic/boost/object_model/detail/make_method.hpp | 63 +++++++-----
sandbox/monotonic/boost/object_model/detail/method_pointer.hpp | 190 +++++++++++++++++++++------------------
sandbox/monotonic/boost/object_model/registry.hpp | 51 ++++++++--
sandbox/monotonic/libs/object_model/src/object_model.vcproj | 4
sandbox/monotonic/libs/object_model/test/basic_tests.cpp | 22 ++++
9 files changed, 226 insertions(+), 138 deletions(-)
Modified: sandbox/monotonic/boost/object_model/builder.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/builder.hpp (original)
+++ sandbox/monotonic/boost/object_model/builder.hpp 2009-06-26 18:12:18 EDT (Fri, 26 Jun 2009)
@@ -30,6 +30,7 @@
builder(registry_type ®)
{
methods.my_klass = methods.fields.my_klass = my_klass = reg.register_class<T>();
+ methods.factory = methods.fields.factory = ®
}
struct methods_type
{
@@ -40,15 +41,17 @@
{
return *this;
}
+ registry_type *factory;
class_type *my_klass;
} fields;
template <class Method>
methods_type &operator()(const char *name, Method method)
{
- my_klass->add_method(name, detail::make_method(method, (registry_type *)(0)));
+ my_klass->add_method(name, detail::make_method(method, *factory));
return *this;
}
+ registry_type *factory;
class_type *my_klass;
} methods;
};
Modified: sandbox/monotonic/boost/object_model/class.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/class.hpp (original)
+++ sandbox/monotonic/boost/object_model/class.hpp 2009-06-26 18:12:18 EDT (Fri, 26 Jun 2009)
@@ -27,19 +27,19 @@
typedef type::traits<T> traits;
private:
- Registry ®
+ Registry &factory;
mutable allocator_type allocator;
public:
- klass(Registry &factory)
- : klass_base_type(traits::name, traits::type_number), reg(factory), allocator(reg.get_allocator()) { }
+ klass(Registry ®)
+ : klass_base_type(reg, traits::name, traits::type_number), factory(reg), allocator(reg.get_allocator()) { }
generic::object &create() const
{
storage_type *store = allocator.allocate(1);
//allocator.construct(store);
new (store) storage_type();
- store->construct(reg, *this, reg.get_next_handle());
+ store->construct(factory, *this, factory.get_next_handle());
return *store;
}
@@ -48,7 +48,7 @@
storage_type *store = allocator.allocate(1);
//allocator.construct(store);
new (store) storage_type(init);
- store->construct(reg, *this, reg.get_next_handle());
+ store->construct(factory, *this, factory.get_next_handle());
return *store;
}
Modified: sandbox/monotonic/boost/object_model/containers/vector.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/containers/vector.hpp (original)
+++ sandbox/monotonic/boost/object_model/containers/vector.hpp 2009-06-26 18:12:18 EDT (Fri, 26 Jun 2009)
@@ -76,6 +76,12 @@
{
impl.pop_back();
}
+ generic::object pop()
+ {
+ generic::object top = back();
+ impl.pop_back();
+ return top;
+ }
reference at(size_t index)
{
return impl.at(index);
Added: sandbox/monotonic/boost/object_model/detail/base_type.hpp
==============================================================================
--- (empty file)
+++ sandbox/monotonic/boost/object_model/detail/base_type.hpp 2009-06-26 18:12:18 EDT (Fri, 26 Jun 2009)
@@ -0,0 +1,58 @@
+// (C) 2009 Christian Schladetsch
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// documentation at https://svn.boost.org/svn/boost/sandbox/monotonic/libs/object_model/doc/index.html
+// sandbox at https://svn.boost.org/svn/boost/sandbox/monotonic/object_model/
+
+#ifndef BOOST_OBJECT_MODEL_DETAIL_BASE_TYPE_HPP
+#define BOOST_OBJECT_MODEL_DETAIL_BASE_TYPE_HPP
+
+#include <boost/type_traits/remove_reference.hpp>
+#include <boost/type_traits/remove_const.hpp>
+
+#include <boost/object_model/detail/prefix.hpp>
+#include <boost/object_model/forward_declarations.hpp>
+
+BOOST_OM_BEGIN
+
+namespace detail
+{
+ template <class T>
+ struct remove_const_and_reference
+ {
+ typedef typename boost::remove_reference<T>::type T0;
+ typedef typename boost::remove_const<T0>::type type;
+ };
+
+ template <class T>
+ struct remove_object_wrap
+ {
+ typedef T type;
+ };
+
+ template <class T>
+ struct remove_object_wrap<object<T> >
+ {
+ typedef T type;
+ };
+
+ /// remove any reference-ness or const-ness from a C++ type, and also strip object<> from it
+ template <class T>
+ struct base_type
+ {
+ typedef typename remove_const_and_reference<T>::type T0;
+ typedef typename remove_object_wrap<T0>::type type;
+ };
+
+} // namespace detail
+
+
+BOOST_OM_END
+
+#include <boost/object_model/detail/postfix.hpp>
+
+#endif // BOOST_OBJECT_MODEL_DETAIL_BASE_TYPE_HPP
+
+//EOF
Modified: sandbox/monotonic/boost/object_model/detail/class_base.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/detail/class_base.hpp (original)
+++ sandbox/monotonic/boost/object_model/detail/class_base.hpp 2009-06-26 18:12:18 EDT (Fri, 26 Jun 2009)
@@ -21,24 +21,27 @@
struct klass_base : generic::klass
{
typedef typename Registry::identifier_type Label;
+ typedef typename Registry::allocator_type allocator_type;
- typedef std::map<Label, generic::property const *> properties_type;
- typedef std::map<Label, generic::method<Registry> const *> methods_type;
+ // TODO: use unordered_map
+ typedef std::map<Label, generic::property const *, std::less<Label>, allocator_type> properties_type;
+ typedef std::map<Label, generic::method<Registry> const *, std::less<Label>, allocator_type> methods_type;
private:
properties_type properties;
methods_type methods;
+ Registry &factory;
public:
- klass_base(const char *ident, type::number num)
- : generic::klass(ident, num)
+ klass_base(Registry ®, generic::class_name ident, type::number num)
+ : generic::klass(ident, num), factory(reg)
{
}
~klass_base()
{
BOOST_FOREACH(methods_type::value_type &val, methods)
{
- delete val.second;
+ factory.allocator_destroy_deallocate(const_cast<generic::method<Registry> *>(val.second));
}
}
Modified: sandbox/monotonic/boost/object_model/detail/make_method.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/detail/make_method.hpp (original)
+++ sandbox/monotonic/boost/object_model/detail/make_method.hpp 2009-06-26 18:12:18 EDT (Fri, 26 Jun 2009)
@@ -10,66 +10,77 @@
#define BOOST_OBJECT_MODEL_DETAIL_MAKE_METHOD_HPP
#include <boost/object_model/detail/prefix.hpp>
-//#include <boost/object_model/generic/method.hpp>
#include <boost/object_model/detail/method_pointer.hpp>
+#include <boost/object_model/detail/base_type.hpp>
BOOST_OM_BEGIN
namespace detail
{
+ // TODO: move these to be methods of detail::class_base<Reg>
+
template <class Klass, class Reg>
- generic::method<Reg> *make_method(void (Klass::*M)(), Reg *)
+ generic::method<Reg> *make_method(void (Klass::*M)(), Reg ®)
{
- return new method<Reg, void, Klass, boost::mpl::vector<>, false>(M);
+ return reg.allocator_create<method<Reg, void, Klass, boost::mpl::vector<>, false> >(M);
}
+
template <class Ret, class Klass, class Reg>
- generic::method<Reg> *make_method(Ret (Klass::*M)(), Reg *)
+ generic::method<Reg> *make_method(Ret (Klass::*M)(), Reg ®)
{
- return new method<Reg, Ret, Klass, boost::mpl::vector<>, false>(M);
+ return reg.allocator_create<method<Reg, Ret, Klass, boost::mpl::vector<>, false> >(M);
}
-/*
- template <class R, class Klass>
- MethodBase *MakeMethod(R (Klass::*M)())
+
+ template <class Klass, class Reg>
+ generic::method<Reg> *make_method(void (Klass::*M)() const, Reg ®)
{
- return new Method<R, Klass, boost::mpl::vector<>, false>(M);
+ return reg.allocator_create<method<Reg, void, Klass, boost::mpl::vector<>, true> >(M);
}
- template <class Klass>
- MethodBase *MakeMethod(void (Klass::*M)() const)
+ template <class Ret, class Klass, class Reg>
+ generic::method<Reg> *make_method(Ret (Klass::*M)() const, Reg ®)
{
- return new Method<void, Klass, boost::mpl::vector<>, true>(M);
+ return reg.allocator_create<method<Reg, Ret, Klass, boost::mpl::vector<>, true> >(M);
}
- template <class R, class Klass>
- MethodBase *MakeMethod(R (Klass::*M)() const)
+ // ---------------------------------- arity = 1
+
+ template <class Klass, class Reg, class A0>
+ generic::method<Reg> *make_method(void (Klass::*M)(A0), Reg ®)
{
- return new Method<R, Klass, boost::mpl::vector<>, true>(M);
+ return reg.allocator_create<method<Reg, void, Klass, boost::mpl::vector<A0>, false> >(M);
}
- // ---------------------------------- arity = 1
+ template <class Ret, class Klass, class Reg, class A0>
+ generic::method<Reg> *make_method(Ret (Klass::*M)(A0), Reg ®)
+ {
+ return reg.allocator_create<method<Reg, Ret, Klass, boost::mpl::vector<A0>, false> >(M);
+ }
- template <class Klass, class R, class A0>
- MethodBase *MakeMethod(R (Klass::*M)(A0))
+ template <class Klass, class Reg, class A0>
+ generic::method<Reg> *make_method(void (Klass::*M)(A0) const, Reg ®)
{
- return new Method<R, Klass, boost::mpl::vector<A0>, false>(M);
+ return reg.allocator_create<method<Reg, void, Klass, boost::mpl::vector<A0>, true> >(M);
}
- template <class Klass, class R, class A0>
- MethodBase *MakeMethod(R (Klass::*M)(A0) const)
+ template <class Ret, class Klass, class Reg, class A0>
+ generic::method<Reg> *make_method(Ret (Klass::*M)(A0) const, Reg ®)
{
- return new Method<R, Klass, boost::mpl::vector<A0>, true>(M);
+ return reg.allocator_create<method<Reg, Ret, Klass, boost::mpl::vector<A0>, true> >(M);
}
+ /*
+
// ---------------------------------- arity = 2
template <class Klass, class R, class A0, class A1>
- MethodBase *MakeMethod(R (Klass::*M)(A0,A1))
+ generic::method<Reg> *MakeMethod(R (Klass::*M)(A0,A1))
{
return new Method<R, Klass, boost::mpl::vector<A0,A1>, false>(M);
}
template <class Klass, class R, class A0, class A1>
- MethodBase *MakeMethod(R (Klass::*M)(A0,A1) const)
+ generic::method<Reg> *MakeMethod(R (Klass::*M)(A0,A1) const)
{
return new Method<R, Klass, boost::mpl::vector<A0,A1>, true>(M);
}
@@ -77,13 +88,13 @@
// ---------------------------------- arity = 3
template <class Klass, class R, class A0, class A1, class A2>
- MethodBase *MakeMethod(R (Klass::*M)(A0,A1,A2))
+ generic::method<Reg> *MakeMethod(R (Klass::*M)(A0,A1,A2))
{
return new Method<R, Klass, boost::mpl::vector<A0,A1,A2>, false>(M);
}
template <class Klass, class R, class A0, class A1, class A2>
- MethodBase *MakeMethod(R (Klass::*M)(A0,A1,A2) const)
+ generic::method<Reg> *MakeMethod(R (Klass::*M)(A0,A1,A2) const)
{
return new Method<R, Klass, boost::mpl::vector<A0,A1,A2>, true>(M);
}
Modified: sandbox/monotonic/boost/object_model/detail/method_pointer.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/detail/method_pointer.hpp (original)
+++ sandbox/monotonic/boost/object_model/detail/method_pointer.hpp 2009-06-26 18:12:18 EDT (Fri, 26 Jun 2009)
@@ -11,8 +11,12 @@
#include <boost/mpl/vector.hpp>
#include <boost/mpl/size.hpp>
+#include <boost/mpl/at.hpp>
#include <boost/object_model/detail/prefix.hpp>
#include <boost/object_model/generic/object.hpp>
+#include <boost/object_model/type/specifier.hpp>
+#include <boost/object_model/object.hpp>
+#include <boost/object_model/detail/base_type.hpp>
BOOST_OM_BEGIN
@@ -36,111 +40,119 @@
typedef Return (Klass::*method_type)();
method_type method;
method_pointer(method_type M) : method(M) { }
- void operator()(generic::object &object, typename Registry::vector_type &stack) const
+ void operator()(generic::object object, typename Registry::vector_type &stack) const
{
Registry ® = static_cast<Registry &>(object.get_registry());
stack.push_back(reg.create((reg.deref<Klass>(object).*method)()));
}
};
- /*
+
template <class Registry, class Return, class Klass, class Args>
struct method_pointer<Registry, true, false, 0, Return, Klass, Args> : method_pointerBase0
{
- typedef Return (Klass::*Method)() const;
- Method method;
- method_pointer(Method M) : method(M) { }
- void operator()(generic::object const &object, containers::vector<allocator_type> &stack) const
+ typedef Return (Klass::*method_type)() const;
+ method_type method;
+ method_pointer(method_type M) : method(M) { }
+ void operator()(generic::const_object object, typename Registry::vector_type &stack) const
{
- stack.push_back(object.New((Deref<Klass>(object).*method)()));
+ Registry ® = static_cast<Registry &>(object.get_registry());
+ stack.push_back(reg.create((reg.const_deref<Klass>(object).*method)()));
}
};
- template <class Return, class Klass, class Args>
- struct method_pointer<false, true, 0, Return, Klass, Args> : method_pointerBase0
+ template <class Registry, class Return, class Klass, class Args>
+ struct method_pointer<Registry, false, true, 0, Return, Klass, Args> : method_pointerBase0
{
- typedef Return (Klass::*Method)();
- Method method;
- method_pointer(Method M) : method(M) { }
- void operator()(generic::object &object, containers::vector<allocator_type> &stack) const
+ typedef Return (Klass::*method_type)();
+ method_type method;
+ method_pointer(method_type M) : method(M) { }
+ void operator()(generic::mutable_object object, typename Registry::vector_type &stack) const
{
- (Deref<Klass>(object).*method)();
+ Registry ® = static_cast<Registry &>(object.get_registry());
+ (reg.const_deref<Klass>(object).*method)();
}
};
- template <class Return, class Klass, class Args>
- struct method_pointer<true, true, 0, Return, Klass, Args> : method_pointerBase0
+
+ template <class Registry, class Return, class Klass, class Args>
+ struct method_pointer<Registry, true, true, 0, Return, Klass, Args> : method_pointerBase0
{
- typedef Return (Klass::*Method)() const;
- Method method;
- method_pointer(Method M) : method(M) { }
- void operator()(generic::object const &object, containers::vector<allocator_type> &stack) const
+ typedef Return (Klass::*method_type)() const;
+ method_type method;
+ method_pointer(method_type M) : method(M) { }
+ void operator()(generic::const_object object, typename Registry::vector_type &stack) const
{
- (Deref<Klass>(object).*method)();
+ Registry ® = static_cast<Registry &>(object.get_registry());
+ (reg.const_deref<Klass>(object).*method)();
}
};
- /*
//----------------------------------------------------------- arity = 1
template <class Args>
struct method_pointerBase1 : method_pointerBase0
{
typedef typename boost::mpl::at_c<Args, 0>::type A0;
- typedef typename BaseType<A0>::Type B0;
- typedef Pointer<B0> P0;
+ typedef typename detail::base_type<A0>::type P0;
+ //typedef Pointer<B0> P0;
template <class OI>
void AddArgs(OI P)
{
method_pointerBase0::AddArgs(P);
- *P++ = Type::MakeType<A0>::Create();
+ *P++ = type::make_specifier<A0>();
}
};
- template <class Return, class Klass, class Args>
- struct method_pointer<false, false, 1, Return, Klass, Args> : method_pointerBase1<Args>
+ template <class Registry, class Return, class Klass, class Args>
+ struct method_pointer<Registry, false, false, 1, Return, Klass, Args> : method_pointerBase1<Args>
{
- typedef Return (Klass::*Method)(A0);
- Method method;
- method_pointer(Method M) : method(M) { }
- void operator()(generic::object &object, containers::vector<allocator_type> &stack) const
+ typedef Return (Klass::*method_type)(A0);
+ method_type method;
+ method_pointer(method_type M) : method(M) { }
+ void operator()(generic::mutable_object object, typename Registry::vector_type &stack) const
{
- P0 a0 = stack.pop();
- stack.push_back(object.New((Deref<Klass>(object).*method)(*a0)));
+ Registry ® = static_cast<Registry &>(object.get_registry());
+ generic::object a0 = stack.pop();
+ stack.push_back(reg.create((reg.deref<Klass>(object).*method)(reg.deref<P0>(a0))));
}
};
- template <class Return, class Klass, class Args>
- struct method_pointer<true, false, 1, Return, Klass, Args> : method_pointerBase1<Args>
+ template <class Registry, class Return, class Klass, class Args>
+ struct method_pointer<Registry, true, false, 1, Return, Klass, Args> : method_pointerBase1<Args>
{
- typedef Return (Klass::*Method)(A0) const;
- Method method;
- method_pointer(Method M) : method(M) { }
- void operator()(generic::object const &object, containers::vector<allocator_type> &stack) const
+ typedef Return (Klass::*method_type)(A0) const;
+ method_type method;
+ method_pointer(method_type M) : method(M) { }
+ void operator()(generic::const_object const object, typename Registry::vector_type &stack) const
{
- P0 a0 = stack.pop();
- stack.push_back(object.New((Deref<Klass>(object).*method)(*a0)));
+ Registry ® = static_cast<Registry &>(object.get_registry());
+ generic::object a0 = stack.pop();
+ stack.push_back(reg.create((reg.const_deref<Klass>(object).*method)(reg.deref<P0>(a0))));
}
};
- template <class Return, class Klass, class Args>
- struct method_pointer<false, true, 1, Return, Klass, Args> : method_pointerBase1<Args>
+ template <class Registry, class Return, class Klass, class Args>
+ struct method_pointer<Registry, false, true, 1, Return, Klass, Args> : method_pointerBase1<Args>
{
- typedef Return (Klass::*Method)(A0);
- Method method;
- method_pointer(Method M) : method(M) { }
- void operator()(generic::object &object, containers::vector<allocator_type> &stack) const
+ typedef Return (Klass::*method_type)(A0);
+ method_type method;
+ method_pointer(method_type M) : method(M) { }
+ void operator()(generic::object object, typename Registry::vector_type &stack) const
{
- P0 a0 = stack.pop();
- (Deref<Klass>(object).*method)(*a0);
+ Registry ® = static_cast<Registry &>(object.get_registry());
+ generic::object a0 = stack.pop();
+ (reg.const_deref<Klass>(object).*method)(reg.deref<P0>(a0))
}
};
- template <class Return, class Klass, class Args>
- struct method_pointer<true, true, 1, Return, Klass, Args> : method_pointerBase1<Args>
+ template <class Registry, class Return, class Klass, class Args>
+ struct method_pointer<Registry, true, true, 1, Return, Klass, Args> : method_pointerBase1<Args>
{
- typedef Return (Klass::*Method)(A0) const;
- Method method;
- method_pointer(Method M) : method(M) { }
- void operator()(generic::object const &object, containers::vector<allocator_type> &stack) const
+ typedef Return (Klass::*method_type)(A0) const;
+ method_type method;
+ method_pointer(method_type M) : method(M) { }
+ void operator()(generic::const_object const object, typename Registry::vector_type &stack) const
{
- P0 a0 = stack.pop();
- (Deref<Klass>(object).*method)(*a0);
+ Registry ® = static_cast<Registry &>(object.get_registry());
+ generic::object a0 = stack.pop();
+ (reg.const_deref<Klass>(object).*method)(reg.deref<P0>(a0))
}
};
+ /*
//----------------------------------------------------------- arity = 2
template <class Args>
struct method_pointerBase2 : method_pointerBase1<Args>
@@ -158,10 +170,10 @@
template <class Return, class Klass, class Args>
struct method_pointer<false, false, 2, Return, Klass, Args> : method_pointerBase2<Args>
{
- typedef Return (Klass::*Method)(A0,A1);
- Method method;
- method_pointer(Method M) : method(M) { }
- void operator()(generic::object &object, containers::vector<allocator_type> &stack) const
+ typedef Return (Klass::*method_type)(A0,A1);
+ method_type method;
+ method_pointer(method_type M) : method(M) { }
+ void operator()(generic::object &object, typename Registry::vector_type &stack) const
{
P1 a1 = stack.pop();
P0 a0 = stack.pop();
@@ -171,10 +183,10 @@
template <class Return, class Klass, class Args>
struct method_pointer<true, false, 2, Return, Klass, Args> : method_pointerBase2<Args>
{
- typedef Return (Klass::*Method)(A0,A1) const;
- Method method;
- method_pointer(Method M) : method(M) { }
- void operator()(generic::object const &object, containers::vector<allocator_type> &stack) const
+ typedef Return (Klass::*method_type)(A0,A1) const;
+ method_type method;
+ method_pointer(method_type M) : method(M) { }
+ void operator()(generic::object const &object, typename Registry::vector_type &stack) const
{
P1 a1 = stack.pop();
P0 a0 = stack.pop();
@@ -184,10 +196,10 @@
template <class Return, class Klass, class Args>
struct method_pointer<false, true, 2, Return, Klass, Args> : method_pointerBase2<Args>
{
- typedef Return (Klass::*Method)(A0,A1);
- Method method;
- method_pointer(Method M) : method(M) { }
- void operator()(generic::object &object, containers::vector<allocator_type> &stack) const
+ typedef Return (Klass::*method_type)(A0,A1);
+ method_type method;
+ method_pointer(method_type M) : method(M) { }
+ void operator()(generic::object &object, typename Registry::vector_type &stack) const
{
P1 a1 = stack.pop();
P0 a0 = stack.pop();
@@ -197,10 +209,10 @@
template <class Return, class Klass, class Args>
struct method_pointer<true, true, 2, Return, Klass, Args> : method_pointerBase2<Args>
{
- typedef Return (Klass::*Method)(A0, A1) const;
- Method method;
- method_pointer(Method M) : method(M) { }
- void operator()(generic::object const &object, containers::vector<allocator_type> &stack) const
+ typedef Return (Klass::*method_type)(A0, A1) const;
+ method_type method;
+ method_pointer(method_type M) : method(M) { }
+ void operator()(generic::object const &object, typename Registry::vector_type &stack) const
{
P1 a1 = stack.pop();
P0 a0 = stack.pop();
@@ -224,10 +236,10 @@
template <class Return, class Klass, class Args>
struct method_pointer<false, false, 3, Return, Klass, Args> : method_pointerBase3<Args>
{
- typedef Return (Klass::*Method)(A0,A1,A2);
- Method method;
- method_pointer(Method M) : method(M) { }
- void operator()(generic::object &object, containers::vector<allocator_type> &stack) const
+ typedef Return (Klass::*method_type)(A0,A1,A2);
+ method_type method;
+ method_pointer(method_type M) : method(M) { }
+ void operator()(generic::object &object, typename Registry::vector_type &stack) const
{
P2 a2 = stack.pop();
P1 a1 = stack.pop();
@@ -238,10 +250,10 @@
template <class Return, class Klass, class Args>
struct method_pointer<true, false, 3, Return, Klass, Args> : method_pointerBase3<Args>
{
- typedef Return (Klass::*Method)(A0,A1,A2) const;
- Method method;
- method_pointer(Method M) : method(M) { }
- void operator()(generic::object const &object, containers::vector<allocator_type> &stack) const
+ typedef Return (Klass::*method_type)(A0,A1,A2) const;
+ method_type method;
+ method_pointer(method_type M) : method(M) { }
+ void operator()(generic::object const &object, typename Registry::vector_type &stack) const
{
P2 a2 = stack.pop();
P1 a1 = stack.pop();
@@ -252,10 +264,10 @@
template <class Return, class Klass, class Args>
struct method_pointer<false, true, 3, Return, Klass, Args> : method_pointerBase3<Args>
{
- typedef Return (Klass::*Method)(A0,A1,A2);
- Method method;
- method_pointer(Method M) : method(M) { }
- void operator()(generic::object &object, containers::vector<allocator_type> &stack) const
+ typedef Return (Klass::*method_type)(A0,A1,A2);
+ method_type method;
+ method_pointer(method_type M) : method(M) { }
+ void operator()(generic::object &object, typename Registry::vector_type &stack) const
{
P2 a2 = stack.pop();
P1 a1 = stack.pop();
@@ -266,10 +278,10 @@
template <class Return, class Klass, class Args>
struct method_pointer<true, true, 3, Return, Klass, Args> : method_pointerBase3<Args>
{
- typedef Return (Klass::*Method)(A0, A1,A2) const;
- Method method;
- method_pointer(Method M) : method(M) { }
- void operator()(generic::object const &object, containers::vector<allocator_type> &stack) const
+ typedef Return (Klass::*method_type)(A0, A1,A2) const;
+ method_type method;
+ method_pointer(method_type M) : method(M) { }
+ void operator()(generic::object const &object, typename Registry::vector_type &stack) const
{
P2 a2 = stack.pop();
P1 a1 = stack.pop();
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-26 18:12:18 EDT (Fri, 26 Jun 2009)
@@ -96,6 +96,14 @@
}
template <class T>
+ static typename type::traits<T>::reference_type deref(generic::mutable_object &object)
+ {
+ if (!object.is_type<T>())
+ throw type_mismatch();
+ return static_cast<typename rebind_storage<T>::type &>(object.get_storage()).get_reference();
+ }
+
+ template <class T>
static typename type::traits<T>::const_reference_type const_deref(generic::object const &object)
{
if (!object.is_type<T>())
@@ -240,7 +248,7 @@
clear();
BOOST_FOREACH(typename classes_type::value_type &val, classes)
{
- allocator_destroy(const_cast<detail::klass_base<this_type> *>(val.second));
+ allocator_destroy_deallocate(const_cast<detail::klass_base<this_type> *>(val.second));
}
classes.clear();
}
@@ -353,24 +361,23 @@
return static_cast<typename rebind_klass<T>::type const *>(iter->second);
}
-private:
+ ///
template <class T>
- T *allocator_create()
+ T *allocator_allocate()
{
typename allocator_type::template rebind<T>::other alloc(allocator);
- T *ptr = alloc.allocate(1);
- //alloc.construct(ptr);
- new (ptr) T();
- return ptr;
+ return alloc.allocate(1);
}
+
template <class T>
- void allocator_destroy(T *ptr)
+ T *allocator_create()
{
- typename allocator_type::template rebind<T>::other alloc(allocator);
- alloc.destroy(ptr);
- alloc.deallocate(ptr,1);
+ T *ptr = allocator_allocate<T>();
+ new (ptr) T();
+ return ptr;
}
+
template <class T, class U>
T *allocator_create(U &init)
{
@@ -380,6 +387,28 @@
new (ptr) T(init);
return ptr;
}
+
+ template <class T>
+ void allocator_destroy(T *ptr)
+ {
+ typename allocator_type::template rebind<T>::other alloc(allocator);
+ alloc.destroy(ptr);
+ }
+
+ template <class T>
+ void allocator_deallocate(T *ptr)
+ {
+ typename allocator_type::template rebind<T>::other alloc(allocator);
+ alloc.deallocate(ptr);
+ }
+
+ template <class T>
+ void allocator_destroy_deallocate(T *ptr)
+ {
+ typename allocator_type::template rebind<T>::other alloc(allocator);
+ alloc.destroy(ptr);
+ alloc.deallocate(ptr,1);
+ }
};
BOOST_OM_END
Modified: sandbox/monotonic/libs/object_model/src/object_model.vcproj
==============================================================================
--- sandbox/monotonic/libs/object_model/src/object_model.vcproj (original)
+++ sandbox/monotonic/libs/object_model/src/object_model.vcproj 2009-06-26 18:12:18 EDT (Fri, 26 Jun 2009)
@@ -325,6 +325,10 @@
>
</File>
<File
+ RelativePath="..\..\..\boost\object_model\detail\base_type.hpp"
+ >
+ </File>
+ <File
RelativePath="..\..\..\boost\object_model\detail\class_base.hpp"
>
</File>
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-26 18:12:18 EDT (Fri, 26 Jun 2009)
@@ -24,10 +24,26 @@
#include <boost/object_model/string.hpp>
#include <boost/object_model/registry.hpp>
+#include <boost/monotonic/allocator.hpp>
+
using namespace std;
using namespace boost;
namespace om = boost::object_model;
+struct mono_reg : om::system_traits<monotonic::allocator<char> > { };
+
+BOOST_AUTO_TEST_CASE(test_monotonic)
+{
+ {
+ om::registry<mono_reg> reg;
+ reg.add_builtins();
+ om::object<int> n = reg.create<int>(42);
+ size_t used = monotonic::static_storage<>::used();
+ BOOST_ASSERT(used > 0);
+ }
+ monotonic::static_storage<>::reset();
+}
+
BOOST_AUTO_TEST_CASE(test_vector)
{
om::registry<> reg;
@@ -154,7 +170,7 @@
om::class_builder<Foo>(reg)
.methods
//("bar", &Foo::bar)
- //("spam", &Foo::spam)
+ ("spam", &Foo::spam)
("grok", &Foo::grok)
.fields
("num", &Foo::num)
@@ -172,6 +188,10 @@
BOOST_ASSERT(stack->at(0).is_type<int>());
BOOST_ASSERT(reg.deref<int>(stack->at(0)) == 42);
+ reg.get_method(foo, "spam").invoke(foo, *stack);
+ BOOST_ASSERT(stack->size() == 1);
+ BOOST_ASSERT(stack->at(0).is_type<int>());
+ BOOST_ASSERT(reg.deref<int>(stack->at(0)) == 42*2);
//BOOST_ASSERT(foo.get_class().has_method("bar"));
//BOOST_ASSERT(foo.get_class().has_method("spam"));
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