|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r54383 - in sandbox/monotonic: boost/object_model boost/object_model/containers boost/object_model/detail boost/object_model/generic boost/object_model/type libs/object_model/src libs/object_model/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-26 17:07:31
Author: cschladetsch
Date: 2009-06-26 17:07:28 EDT (Fri, 26 Jun 2009)
New Revision: 54383
URL: http://svn.boost.org/trac/boost/changeset/54383
Log:
added calling methods
Added:
sandbox/monotonic/boost/object_model/detail/method_pointer.hpp (contents, props changed)
Text files modified:
sandbox/monotonic/boost/object_model/builder.hpp | 12 +++--
sandbox/monotonic/boost/object_model/class.hpp | 13 +++++-
sandbox/monotonic/boost/object_model/containers/vector.hpp | 80 +++++++++++++++++++++++++++++++++++++++-
sandbox/monotonic/boost/object_model/detail/class_base.hpp | 24 ++++++++++-
sandbox/monotonic/boost/object_model/detail/make_method.hpp | 79 ++++++++++++++++++++++++++++++++++++++-
sandbox/monotonic/boost/object_model/forward_declarations.hpp | 3 +
sandbox/monotonic/boost/object_model/generic/class.hpp | 2 +
sandbox/monotonic/boost/object_model/generic/method.hpp | 16 ++++---
sandbox/monotonic/boost/object_model/method.hpp | 26 +++++++++++++
sandbox/monotonic/boost/object_model/object.hpp | 5 ++
sandbox/monotonic/boost/object_model/registry.hpp | 48 ++++++++++++++++++++++--
sandbox/monotonic/boost/object_model/type/number.hpp | 1
sandbox/monotonic/libs/object_model/src/object_model.vcproj | 4 ++
sandbox/monotonic/libs/object_model/test/basic_tests.cpp | 33 +++++++++++++++-
14 files changed, 317 insertions(+), 29 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 17:07:28 EDT (Fri, 26 Jun 2009)
@@ -11,7 +11,7 @@
#include <boost/object_model/detail/prefix.hpp>
#include <boost/object_model/class.hpp>
-#include <boost/object_model/detail/make_method.hpp>
+#include <boost/object_model/method.hpp>
BOOST_OM_BEGIN
@@ -21,14 +21,15 @@
typedef Reg registry_type;
typedef type::traits<T> type_traits;
typedef typename Reg::traits_type system_traits;
+ typedef typename registry_type::template rebind_klass<T>::type class_type;
private:
- typename registry_type::template rebind_klass<T>::type *my_klass;
+ class_type *my_klass;
public:
builder(registry_type ®)
{
- my_klass = reg.register_class<T>();
+ methods.my_klass = methods.fields.my_klass = my_klass = reg.register_class<T>();
}
struct methods_type
{
@@ -39,15 +40,16 @@
{
return *this;
}
+ 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));
+ my_klass->add_method(name, detail::make_method(method, (registry_type *)(0)));
return *this;
}
-
+ 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 17:07:28 EDT (Fri, 26 Jun 2009)
@@ -17,10 +17,10 @@
BOOST_OM_BEGIN
template <class T, class Registry>
-struct klass : detail::klass_base<typename Registry::traits_type>
+struct klass : detail::klass_base<typename Registry>
{
typedef typename Registry::traits_type system_traits;
- typedef detail::klass_base<system_traits> klass_base_type;
+ typedef detail::klass_base<Registry> klass_base_type;
typedef typename system_traits::label_type label_type;
typedef typename Registry::rebind_storage<T>::type storage_type;
typedef typename system_traits::allocator_type::template rebind<storage_type>::other allocator_type;
@@ -43,6 +43,15 @@
return *store;
}
+ storage_type &create(typename traits::const_reference_type init) const
+ {
+ storage_type *store = allocator.allocate(1);
+ //allocator.construct(store);
+ new (store) storage_type(init);
+ store->construct(reg, *this, reg.get_next_handle());
+ return *store;
+ }
+
void destroy(generic::object &obj) const
{
storage_type *store = &static_cast<storage_type &>(obj);
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 17:07:28 EDT (Fri, 26 Jun 2009)
@@ -19,18 +19,94 @@
template <class Alloc>
struct vector
{
- //typedef boost::containers::vector<object, Alloc> implementation;
- typedef std::vector<object, Alloc> implementation;
+ //typedef boost::containers::vector<generic::object, Alloc> implementation;
+ typedef std::vector<generic::object, Alloc> implementation;
typedef typename implementation::value_type value_type;
typedef typename implementation::iterator iterator;
typedef typename implementation::const_iterator const_iterator;
+ typedef typename implementation::reference reference;
+ typedef typename implementation::const_reference const_reference;
private:
implementation impl;
public:
+ size_t size() const
+ {
+ return impl.size();
+ }
+
+ const_iterator begin() const
+ {
+ return impl.begin();
+ }
+ iterator begin()
+ {
+ return impl.begin();
+ }
+ const_iterator end() const
+ {
+ return impl.end();
+ }
+ iterator end()
+ {
+ return impl.end();
+ }
+ const_reference front() const
+ {
+ return impl.front();
+ }
+ reference front()
+ {
+ return impl.front();
+ }
+ const_reference back() const
+ {
+ return impl.back();
+ }
+ reference back()
+ {
+ return impl.back();
+ }
+ void push_back(generic::object obj)
+ {
+ impl.push_back(obj);
+ }
+ void pop_back()
+ {
+ impl.pop_back();
+ }
+ reference at(size_t index)
+ {
+ return impl.at(index);
+ }
+ const_reference at(size_t index) const
+ {
+ return impl.at(index);
+ }
+ reference operator[](size_t index)
+ {
+ return impl[index];
+ }
+ const_reference operator[](size_t index) const
+ {
+ return impl[index];
+ }
};
+} // namespace containers
+
+namespace type
+{
+ /// the type-traits for a vector with any allocator are the same
+ template <class Al>
+ struct traits<containers::vector<Al> > : traits_base<containers::vector<Al>, number::Vector >
+ {
+ BOOST_STATIC_CONSTANT(number::value_type, type_number = number::Vector );
+ static const char *name;
+ };
+ template <class Al>
+ const char *traits<containers::vector<Al> >::name = "vector";
}
BOOST_OM_END
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 17:07:28 EDT (Fri, 26 Jun 2009)
@@ -17,13 +17,13 @@
namespace detail
{
- template <class Traits>
+ template <class Registry>
struct klass_base : generic::klass
{
- typedef typename Traits::label_type Label;
+ typedef typename Registry::identifier_type Label;
typedef std::map<Label, generic::property const *> properties_type;
- typedef std::map<Label, generic::method const *> methods_type;
+ typedef std::map<Label, generic::method<Registry> const *> methods_type;
private:
properties_type properties;
@@ -34,6 +34,24 @@
: generic::klass(ident, num)
{
}
+ ~klass_base()
+ {
+ BOOST_FOREACH(methods_type::value_type &val, methods)
+ {
+ delete val.second;
+ }
+ }
+
+ void add_method(Label const &name, generic::method<Registry> const *meth)
+ {
+ methods[name] = meth;
+ }
+
+ generic::method<Registry> const *get_method(Label const &name) const
+ {
+ methods_type::const_iterator iter = methods.find(name);
+ return iter == methods.end() ? 0 : iter->second;
+ }
bool has_method(Label const &name) const
{
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 17:07:28 EDT (Fri, 26 Jun 2009)
@@ -10,13 +10,86 @@
#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/method.hpp>
+//#include <boost/object_model/generic/method.hpp>
+#include <boost/object_model/detail/method_pointer.hpp>
BOOST_OM_BEGIN
-template
+namespace detail
+{
+ template <class Klass, class Reg>
+ generic::method<Reg> *make_method(void (Klass::*M)(), Reg *)
+ {
+ return new 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 *)
+ {
+ return new method<Reg, Ret, Klass, boost::mpl::vector<>, false>(M);
+ }
+/*
+ template <class R, class Klass>
+ MethodBase *MakeMethod(R (Klass::*M)())
+ {
+ return new Method<R, Klass, boost::mpl::vector<>, false>(M);
+ }
+
+ template <class Klass>
+ MethodBase *MakeMethod(void (Klass::*M)() const)
+ {
+ return new Method<void, Klass, boost::mpl::vector<>, true>(M);
+ }
+
+ template <class R, class Klass>
+ MethodBase *MakeMethod(R (Klass::*M)() const)
+ {
+ return new Method<R, Klass, boost::mpl::vector<>, true>(M);
+ }
+
+ // ---------------------------------- arity = 1
+
+ template <class Klass, class R, class A0>
+ MethodBase *MakeMethod(R (Klass::*M)(A0))
+ {
+ return new Method<R, Klass, boost::mpl::vector<A0>, false>(M);
+ }
+
+ template <class Klass, class R, class A0>
+ MethodBase *MakeMethod(R (Klass::*M)(A0) const)
+ {
+ return new Method<R, 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))
+ {
+ 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)
+ {
+ return new Method<R, Klass, boost::mpl::vector<A0,A1>, true>(M);
+ }
+
+ // ---------------------------------- arity = 3
+
+ template <class Klass, class R, class A0, class A1, class A2>
+ MethodBase *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)
+ {
+ return new Method<R, Klass, boost::mpl::vector<A0,A1,A2>, true>(M);
+ }
+*/
+}
BOOST_OM_END
#include <boost/object_model/detail/postfix.hpp>
Added: sandbox/monotonic/boost/object_model/detail/method_pointer.hpp
==============================================================================
--- (empty file)
+++ sandbox/monotonic/boost/object_model/detail/method_pointer.hpp 2009-06-26 17:07:28 EDT (Fri, 26 Jun 2009)
@@ -0,0 +1,295 @@
+// (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_METHOD_POINTER_HPP
+#define BOOST_OBJECT_MODEL_DETAIL_METHOD_POINTER_HPP
+
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/size.hpp>
+#include <boost/object_model/detail/prefix.hpp>
+#include <boost/object_model/generic/object.hpp>
+
+BOOST_OM_BEGIN
+
+namespace detail
+{
+ template <class Reg, bool IsKonst, bool IsVoid, int Arity, class Return, class Klass, class Args>
+ struct method_pointer;
+
+
+ //----------------------------------------------------------- arity = 0
+ struct method_pointerBase0
+ {
+ template <class OI>
+ void AddArgs(OI)
+ {
+ }
+ };
+ template <class Registry, class Return, class Klass, class Args>
+ struct method_pointer<Registry, false, false, 0, Return, Klass, Args> : method_pointerBase0
+ {
+ 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
+ {
+ 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
+ {
+ stack.push_back(object.New((Deref<Klass>(object).*method)()));
+ }
+ };
+ template <class Return, class Klass, class Args>
+ struct method_pointer<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
+ {
+ (Deref<Klass>(object).*method)();
+ }
+ };
+ template <class Return, class Klass, class Args>
+ struct method_pointer<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
+ {
+ (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;
+ template <class OI>
+ void AddArgs(OI P)
+ {
+ method_pointerBase0::AddArgs(P);
+ *P++ = Type::MakeType<A0>::Create();
+ }
+ };
+ template <class Return, class Klass, class Args>
+ struct method_pointer<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
+ {
+ P0 a0 = stack.pop();
+ stack.push_back(object.New((Deref<Klass>(object).*method)(*a0)));
+ }
+ };
+ template <class Return, class Klass, class Args>
+ struct method_pointer<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
+ {
+ P0 a0 = stack.pop();
+ stack.push_back(object.New((Deref<Klass>(object).*method)(*a0)));
+ }
+ };
+ template <class Return, class Klass, class Args>
+ struct method_pointer<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
+ {
+ P0 a0 = stack.pop();
+ (Deref<Klass>(object).*method)(*a0);
+ }
+ };
+ template <class Return, class Klass, class Args>
+ struct method_pointer<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
+ {
+ P0 a0 = stack.pop();
+ (Deref<Klass>(object).*method)(*a0);
+ }
+ };
+
+ //----------------------------------------------------------- arity = 2
+ template <class Args>
+ struct method_pointerBase2 : method_pointerBase1<Args>
+ {
+ typedef typename boost::mpl::at_c<Args, 1>::type A1;
+ typedef typename BaseType<A1>::Type B1;
+ typedef Pointer<B1> P1;
+ template <class OI>
+ void AddArgs(OI P)
+ {
+ method_pointerBase1<Args>::AddArgs(P);
+ *P++ = Type::MakeType<A1>::Create();
+ }
+ };
+ 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
+ {
+ P1 a1 = stack.pop();
+ P0 a0 = stack.pop();
+ stack.push_back(object.New((Deref<Klass>(object).*method)(*a0, *a1)));
+ }
+ };
+ 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
+ {
+ P1 a1 = stack.pop();
+ P0 a0 = stack.pop();
+ stack.push_back(object.New((Deref<Klass>(object).*method)(*a0, *a1)));
+ }
+ };
+ 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
+ {
+ P1 a1 = stack.pop();
+ P0 a0 = stack.pop();
+ (Deref<Klass>(object).*method)(*a0, *a1);
+ }
+ };
+ 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
+ {
+ P1 a1 = stack.pop();
+ P0 a0 = stack.pop();
+ (Deref<Klass>(object).*method)(*a0, *a1);
+ }
+ };
+ //----------------------------------------------------------- arity = 3
+ template <class Args>
+ struct method_pointerBase3 : method_pointerBase2<Args>
+ {
+ typedef typename boost::mpl::at_c<Args, 2>::type A2;
+ typedef typename BaseType<A2>::Type B2;
+ typedef Pointer<B2> P2;
+ template <class OI>
+ void AddArgs(OI P)
+ {
+ method_pointerBase2<Args>::AddArgs(P);
+ *P++ = Type::MakeType<A2>::Create();
+ }
+ };
+ 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
+ {
+ P2 a2 = stack.pop();
+ P1 a1 = stack.pop();
+ P0 a0 = stack.pop();
+ stack.push_back(object.New((Deref<Klass>(object).*method)(*a0, *a1, *a2)));
+ }
+ };
+ 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
+ {
+ P2 a2 = stack.pop();
+ P1 a1 = stack.pop();
+ P0 a0 = stack.pop();
+ stack.push_back(object.New((Deref<Klass>(object).*method)(*a0, *a1, *a2)));
+ }
+ };
+ 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
+ {
+ P2 a2 = stack.pop();
+ P1 a1 = stack.pop();
+ P0 a0 = stack.pop();
+ (Deref<Klass>(object).*method)(*a0, *a1, *a2);
+ }
+ };
+ 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
+ {
+ P2 a2 = stack.pop();
+ P1 a1 = stack.pop();
+ P0 a0 = stack.pop();
+ (Deref<Klass>(object).*method)(*a0, *a1, *a2);
+ }
+ };
+
+ */
+ template <class Reg, class Rty, class Klass, class Args, bool Konst>
+ struct make_method_pointer
+ {
+ typedef method_pointer<Reg, Konst, boost::is_same<void, Rty>::value, boost::mpl::size<Args>::value, Rty, Klass, Args> type;
+ };
+}
+
+BOOST_OM_END
+
+#include <boost/object_model/detail/postfix.hpp>
+
+#endif // BOOST_OBJECT_MODEL_DETAIL_METHOD_POINTER_HPP
+
+//EOF
Modified: sandbox/monotonic/boost/object_model/forward_declarations.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/forward_declarations.hpp (original)
+++ sandbox/monotonic/boost/object_model/forward_declarations.hpp 2009-06-26 17:07:28 EDT (Fri, 26 Jun 2009)
@@ -60,6 +60,7 @@
struct reflected;
/// common for a all methods
+ template <class Traits>
struct method;
/// common for all class properties
@@ -118,7 +119,7 @@
struct label;
/// a specific method of class type, with given signature
-template <class T, class Signature>
+template <class Reg, class Rty, class Klass, class Args, bool Konst>
struct method;
/// a specific property
Modified: sandbox/monotonic/boost/object_model/generic/class.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/generic/class.hpp (original)
+++ sandbox/monotonic/boost/object_model/generic/class.hpp 2009-06-26 17:07:28 EDT (Fri, 26 Jun 2009)
@@ -38,6 +38,8 @@
virtual object &create() const = 0;
virtual void destroy(object &) const = 0;
+ //virtual bool has_method(object &) const = 0;
+
//virtual const_object get_property(const label&, const_object &owner) const = 0;
//virtual object get_property(const label&, object &owner) const = 0;
};
Modified: sandbox/monotonic/boost/object_model/generic/method.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/generic/method.hpp (original)
+++ sandbox/monotonic/boost/object_model/generic/method.hpp 2009-06-26 17:07:28 EDT (Fri, 26 Jun 2009)
@@ -6,8 +6,8 @@
// 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_(X)_HPP
-#define BOOST_OBJECT_MODEL_(X)_HPP
+#ifndef BOOST_OBJECT_MODEL_GENERIC_METHOD_HPP
+#define BOOST_OBJECT_MODEL_GENERIC_METHOD_HPP
#include <boost/object_model/detail/prefix.hpp>
#include <boost/object_model/label.hpp>
@@ -19,17 +19,19 @@
namespace generic
{
/// common base for all specific methods
+ template <class Registry>
struct method
{
private:
- label name;
- signature sig;
+ typename Registry::label_type name;
+ type::signature sig;
+
public:
- virtual void invoke(object &servant, vector &args) const = 0;
+ virtual void invoke(object &servant, typename Registry::vector_type &args) const = 0;
template <class Traits>
- typename Traits::string_type to_string(const object_model::registry<Traits> ®) const
+ typename Traits::string_type to_string(const Registry ®) const
{
typename Traits::string_type s;
return s;
@@ -41,6 +43,6 @@
#include <boost/object_model/detail/postfix.hpp>
-#endif // BOOST_OBJECT_MODEL_(X)_HPP
+#endif // BOOST_OBJECT_MODEL_GENERIC_METHOD_HPP
//EOF
Modified: sandbox/monotonic/boost/object_model/method.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/method.hpp (original)
+++ sandbox/monotonic/boost/object_model/method.hpp 2009-06-26 17:07:28 EDT (Fri, 26 Jun 2009)
@@ -10,9 +10,35 @@
#define BOOST_OBJECT_MODEL_METHOD_HPP
#include <boost/object_model/detail/prefix.hpp>
+#include <boost/object_model/generic/method.hpp>
+#include <boost/object_model/detail/make_method.hpp>
BOOST_OM_BEGIN
+template <
+ class Reg // the registry type
+ , class Rty // return type
+ , class Klass // servant type
+ , class Args // argument list
+ , bool Konst // constness
+>
+struct method : generic::method<Reg>, detail::make_method_pointer<Reg, Rty, Klass, Args, Konst>::type
+{
+ typedef typename detail::make_method_pointer<Reg, Rty, Klass, Args, Konst>::type Parent;
+ method(typename Parent::method_type M) : Parent(M)
+ {
+ //signature.return_type = Type::MakeType<Rty>::Create();//Type::Traits<typename BaseType<Rty>::Type>::TypeNumber;
+ //signature.class_type = Type::Traits<Klass>::TypeNumber;
+ //signature.konst = Konst;
+ //Parent::AddArgs(std::back_inserter(signature.arguments));
+
+ }
+ void invoke(generic::object &servant, typename Reg::vector_type &stack) const
+ {
+ (*this)(servant, stack);
+ }
+};
+
BOOST_OM_END
#include <boost/object_model/detail/postfix.hpp>
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-26 17:07:28 EDT (Fri, 26 Jun 2009)
@@ -46,6 +46,11 @@
{
return get_reference();
}
+ typename traits::pointer_type operator->()
+ {
+ return &get_reference();
+ }
+
};
BOOST_OM_END
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 17:07:28 EDT (Fri, 26 Jun 2009)
@@ -30,12 +30,13 @@
template <class Tr>
struct registry : generic::registry
{
- typedef Tr traits, traits_type;
+ typedef Tr traits, traits_type, system_traits;
typedef typename traits::allocator_type allocator_type;
typedef typename traits::char_traits char_traits;
typedef typename traits::char_type char_type;
typedef typename traits::string_type string_type;
typedef typename traits::label_type label_type;
+ typedef typename traits::identifier_type identifier_type;
typedef containers::vector<allocator_type> vector_type;
@@ -62,7 +63,7 @@
typedef std::map<
type::number
- , detail::klass_base<traits_type> const *
+ , detail::klass_base<this_type> const *
, std::less<type::number>
, allocator_type
> classes_type;
@@ -77,7 +78,7 @@
typedef boost::unordered_map<
type::number
- , detail::klass_base<traits_type> const *
+ , detail::klass_base<this_type> const *
, boost::hash<type::number>
, std::less<type::number>
, allocator_type
@@ -179,6 +180,25 @@
return p.has(label);
}
+ bool has_method(const generic::object &obj, typename traits::identifier_type const &ident) const
+ {
+ return get_method_ptr(obj, ident) != 0;
+ }
+
+ const generic::method<this_type> &get_method(const generic::object &obj, typename traits::identifier_type const &ident) const
+ {
+ const generic::method<this_type> *ptr = get_method_ptr(obj, ident);
+ if (ptr == 0)
+ throw;
+ return *ptr;
+ }
+ const generic::method<this_type> *get_method_ptr(const generic::object &obj, typename traits::identifier_type const &ident) const
+ {
+ classes_type::const_iterator iter = classes.find(obj.get_type_number());
+ if (iter == classes.end())
+ return 0;
+ return iter->second->get_method(ident);
+ }
protected:
template <class, class> friend struct klass;
handle get_next_handle()
@@ -200,6 +220,12 @@
{
clear_classes();
}
+ void add_builtins()
+ {
+ register_class<void>();
+ register_class<int>();
+ register_class<vector_type>();
+ }
void clear()
{
BOOST_FOREACH(typename instances_type::value_type &val, instances)
@@ -214,7 +240,7 @@
clear();
BOOST_FOREACH(typename classes_type::value_type &val, classes)
{
- allocator_destroy(const_cast<detail::klass_base<traits_type> *>(val.second));
+ allocator_destroy(const_cast<detail::klass_base<this_type> *>(val.second));
}
classes.clear();
}
@@ -272,6 +298,9 @@
template <class T>
typename rebind_klass<T>::type *register_class()
{
+ if (has_class<T>())
+ return const_cast<klass<T, this_type> * >(get_class<T>());
+
BOOST_ASSERT(!has_class<T>());
typedef typename rebind_klass<T>::type class_type;
class_type *new_class = allocator_create<class_type >(*this);
@@ -297,6 +326,17 @@
instances[obj.get_handle()] = &obj;
return object<T>(obj, &this_type::deref<T>, &this_type::const_deref<T>);
}
+ template <class T>
+ object<T> create(T const &init)
+ {
+ typename rebind_klass<T>::type const *k = get_class<T>();
+ if (k == 0)
+ throw unknown_type();
+ typedef typename rebind_storage<T>::type storage_type;
+ storage_type &obj = static_cast<storage_type &>(k->create(init));
+ instances[obj.get_handle()] = &obj;
+ return object<T>(obj, &this_type::deref<T>, &this_type::const_deref<T>);
+ }
template <class T>
bool has_class() const
Modified: sandbox/monotonic/boost/object_model/type/number.hpp
==============================================================================
--- sandbox/monotonic/boost/object_model/type/number.hpp (original)
+++ sandbox/monotonic/boost/object_model/type/number.hpp 2009-06-26 17:07:28 EDT (Fri, 26 Jun 2009)
@@ -31,6 +31,7 @@
Int,
Float,
String,
+
List,
Vector,
Map,
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 17:07:28 EDT (Fri, 26 Jun 2009)
@@ -333,6 +333,10 @@
>
</File>
<File
+ RelativePath="..\..\..\boost\object_model\detail\method_pointer.hpp"
+ >
+ </File>
+ <File
RelativePath="..\..\..\boost\object_model\detail\postfix.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 17:07:28 EDT (Fri, 26 Jun 2009)
@@ -28,6 +28,18 @@
using namespace boost;
namespace om = boost::object_model;
+BOOST_AUTO_TEST_CASE(test_vector)
+{
+ om::registry<> reg;
+ typedef om::registry<>::vector_type vector;
+ reg.register_class<vector>();
+ reg.register_class<int>();
+ om::object<vector> vec = reg.create<vector>();
+ vec->push_back(reg.create<int>(42));
+ BOOST_ASSERT(vec.exists());
+ BOOST_ASSERT(vec->size() == 1);
+}
+
BOOST_AUTO_TEST_CASE(test_type_specifier)
{
om::registry<> reg;
@@ -121,6 +133,10 @@
void bar()
{
}
+ int grok()
+ {
+ return 42;
+ }
int spam(int n)
{
return n*2;
@@ -132,10 +148,14 @@
BOOST_AUTO_TEST_CASE(test_builder)
{
om::registry<> reg;
+ reg.add_builtins();
+ typedef om::registry<>::vector_type vector;
+
om::class_builder<Foo>(reg)
.methods
- ("bar", &Foo::bar)
- ("spam", &Foo::spam)
+ //("bar", &Foo::bar)
+ //("spam", &Foo::spam)
+ ("grok", &Foo::grok)
.fields
("num", &Foo::num)
("str", &Foo::str)
@@ -144,6 +164,15 @@
BOOST_ASSERT(foo.exists());
BOOST_ASSERT(foo.is_type<Foo>());
+ BOOST_ASSERT(reg.has_method(foo, "grok"));
+
+ om::object<vector> stack = reg.create<vector>();
+ reg.get_method(foo, "grok").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);
+
+
//BOOST_ASSERT(foo.get_class().has_method("bar"));
//BOOST_ASSERT(foo.get_class().has_method("spam"));
//BOOST_ASSERT(foo.get_class().has_field("num"));
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