Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78395 - in sandbox/role: . boost/role libs/role/example libs/role/test
From: vicente.botet_at_[hidden]
Date: 2012-05-09 16:03:25


Author: viboes
Date: 2012-05-09 16:03:24 EDT (Wed, 09 May 2012)
New Revision: 78395
URL: http://svn.boost.org/trac/boost/changeset/78395

Log:
Role: Added first POC
Added:
   sandbox/role/Jamfile.v2 (contents, props changed)
   sandbox/role/Jamroot.jam (contents, props changed)
   sandbox/role/README.txt (contents, props changed)
   sandbox/role/boost-build.jam (contents, props changed)
   sandbox/role/boost/role/
   sandbox/role/boost/role/delete.hpp (contents, props changed)
   sandbox/role/boost/role/entity_role.hpp (contents, props changed)
   sandbox/role/libs/role/example/
   sandbox/role/libs/role/example/ex_xx.cpp (contents, props changed)
   sandbox/role/libs/role/test/Jamfile.v2 (contents, props changed)

Added: sandbox/role/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/role/Jamfile.v2 2012-05-09 16:03:24 EDT (Wed, 09 May 2012)
@@ -0,0 +1,28 @@
+# Copyright Rene Rivera 2007.
+#
+# 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)
+
+# Usage:
+#
+# bjam [options | properties | targets]
+#
+# Options:
+#
+# --boost=<BOOST> The directotory of a Boost source tree.
+# Default; BOOST env var (if found)
+# Default; ../boost (if found)
+#
+# --boost-build=<BOOST_BUILD>
+# The directory for the Boost.Build v2 files.
+# Default; BOOST_BUILD_PATH env var (if found)
+# Default; BOOST_BUILD env var (if found)
+# Default; <BOOST>/tools/build/v2 (if found)
+
+#~ If we have the Boost sources we can use the project...
+
+if [ GLOB $(BOOST) : [ modules.peek project : JAMFILE ] ]
+{
+ use-project /boost : $(BOOST) ;
+}

Added: sandbox/role/Jamroot.jam
==============================================================================
--- (empty file)
+++ sandbox/role/Jamroot.jam 2012-05-09 16:03:24 EDT (Wed, 09 May 2012)
@@ -0,0 +1,9 @@
+
+import modules ;
+
+local boost = [ modules.peek : BOOST ] ;
+
+project sandbox : requirements <include>$(boost) ;
+
+# This seems to prevent some Boost.Build errors that otherwise occur :-(
+use-project /boost : $(boost) ;

Added: sandbox/role/README.txt
==============================================================================
--- (empty file)
+++ sandbox/role/README.txt 2012-05-09 16:03:24 EDT (Wed, 09 May 2012)
@@ -0,0 +1,22 @@
+This directory contains the file "boost-build.jam" which search for a Boost install as follows:
+
+* In a directory specified by the --boost=path command line option.
+* In a directory specified by the BOOST environment variable.
+* In the directories ../boost and ../Trunk.
+
+In addition the variables BOOST and BOOST_ROOT are set to point to the root of the Boost install, so to refer to other
+Boost libraries and the main Boost headers, your Jamfile should contain something like:
+
+import modules ;
+
+local boost-path = [ modules.peek : BOOST ] ;
+
+And then you can refer to a Boost library "foo" as:
+
+$(boost-path)/libs/foo/build//boost_foo
+
+Note that if your project does not specify a Jamroot file, then a default one is provided for you,
+and that this file will automatically add $(BOOST)/ to your include path.
+
+
+

Added: sandbox/role/boost-build.jam
==============================================================================
--- (empty file)
+++ sandbox/role/boost-build.jam 2012-05-09 16:03:24 EDT (Wed, 09 May 2012)
@@ -0,0 +1,70 @@
+# Copyright Rene Rivera 2007.
+#
+# 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)
+
+# For instructions see Jamfile.v2, or "bjam --help".
+
+local rule if-has-file ( file + : dir * )
+{
+ local result ;
+ if $(dir)
+ {
+ result = [ GLOB $(dir) : $(file) ] ;
+ }
+ return $(result[1]:P) ;
+}
+
+#~ Attempts to find the Boost source tree...
+
+local boost-src = [ if-has-file LICENSE_1_0.txt :
+ [ MATCH --boost=(.*) : $(ARGV) ]
+ $(BOOST)
+ $(.boost-build-file:D)/../boost
+ $(.boost-build-file:D)/../Trunk
+ ] ;
+
+# error handling:
+if ! $(boost-src)
+{
+ ECHO Unable to find the Boost source tree in the locations searched. ;
+ ECHO Try setting the environment variable BOOST to point to your ;
+ ECHO Boost tree, or else invoke bjam with the --boost=path option. ;
+ ECHO The Boost include path will not be automatically set. ;
+ ECHO The paths searched were [ MATCH --boost=(.*) : $(ARGV) ] $(BOOST) $(.boost-build-file:D)/../boost $(.boost-build-file:D)/../Trunk ;
+ ECHO But the file LICENSE_1_0.txt was not found in any of them ;
+}
+
+#~ Attempts to find the Boost.Build files...
+
+local boost-build-src = [ if-has-file bootstrap.jam :
+ [ MATCH --boost-build=(.*) : $(ARGV) ]
+ $(BOOST_BUILD_PATH)
+ $(BOOST_BUILD)
+ $(boost-src)/tools/build/v2
+ ] ;
+
+# error handling:
+if ! $(boost-build-src)
+{
+ ECHO Unable to find the Boost.Build source tree in the locations searched. ;
+ ECHO Try setting the environment variable BOOST_BUILD to point to your ;
+ ECHO Boost.Build tree, or else invoke bjam with the --boost-build=path option. ;
+ ECHO The paths searched were [ MATCH --boost-build=(.*) : $(ARGV) ] $(BOOST_BUILD_PATH) $(BOOST_BUILD) $(boost-src)/tools/build/v2 ;
+ ECHO But bootstrap.jam was not found in any of these ;
+ ECHO More failures will very likely follow... ;
+}
+
+#~ Set some common vars to refer to the Boost sources...
+
+BOOST ?= $(boost-src) ;
+BOOST_ROOT ?= $(boost-src) ;
+
+#~ And load up Boost.Build...
+
+boost-build $(boost-build-src) ;
+
+
+
+

Added: sandbox/role/boost/role/delete.hpp
==============================================================================
--- (empty file)
+++ sandbox/role/boost/role/delete.hpp 2012-05-09 16:03:24 EDT (Wed, 09 May 2012)
@@ -0,0 +1,45 @@
+// Copyright (C) 2012 Vicente J. Botet Escriba
+//
+// 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)
+
+#ifndef BOOST_ROLE_DETAIL_DELETE_HPP
+#define BOOST_ROLE_DETAIL_DELETE_HPP
+
+#include <boost/config.hpp>
+
+/**
+ * BOOST_ROLE_DELETE_COPY_CTOR deletes the copy constructor when the compiler supports it or
+ * makes it private.
+ *
+ * BOOST_ROLE_DELETE_COPY_ASSIGN deletes the copy assignment when the compiler supports it or
+ * makes it private.
+ */
+#ifndef BOOST_NO_DELETED_FUNCTIONS
+#define BOOST_ROLE_DELETE_COPY_CTOR(CLASS) \
+ CLASS(CLASS const&) = delete; \
+
+#define BOOST_ROLE_DELETE_COPY_ASSIGN(CLASS) \
+ CLASS& operator=(CLASS const&) = delete;
+
+#else // BOOST_NO_DELETED_FUNCTIONS
+#define BOOST_ROLE_DELETE_COPY_CTOR(CLASS) \
+ private: \
+ CLASS(CLASS&); \
+ public:
+
+#define BOOST_ROLE_DELETE_COPY_ASSIGN(CLASS) \
+ private: \
+ CLASS& operator=(CLASS&); \
+ public:
+#endif // BOOST_NO_DELETED_FUNCTIONS
+
+/**
+ * BOOST_ROLE_NO_COPYABLE deletes the copy constructor and assignment when the compiler supports it or
+ * makes them private.
+ */
+#define BOOST_ROLE_NO_COPYABLE(CLASS) \
+ BOOST_ROLE_DELETE_COPY_CTOR(CLASS) \
+ BOOST_ROLE_DELETE_COPY_ASSIGN(CLASS)
+
+#endif // BOOST_ROLE_DETAIL_DELETE_HPP

Added: sandbox/role/boost/role/entity_role.hpp
==============================================================================
--- (empty file)
+++ sandbox/role/boost/role/entity_role.hpp 2012-05-09 16:03:24 EDT (Wed, 09 May 2012)
@@ -0,0 +1,497 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2012.
+// 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)
+//
+// See http://www.boost.org/libs/role for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+/**
+ * @file
+ * @brief Defines the entity/role facilities.
+ *
+ */
+
+#ifndef BOOST_ROLE_ENTITY_ROLE_HPP
+#define BOOST_ROLE_ENTITY_ROLE_HPP
+
+#include <boost/config.hpp>
+#include <boost/role/delete.hpp>
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+#include <boost/static_assert.hpp>
+
+#include <vector>
+
+/**
+ * std::tuple<void*, void*, ...> subject;
+ */
+namespace boost
+{
+ namespace entity_role
+ {
+ /**
+ * A static id generator.
+ */
+ template <typename Tag, typename Int = std::size_t>
+ class id
+ {
+ public:
+ typedef Tag tag_tpe;
+ typedef Int int_type;
+
+ id() :
+ id_(next_id_++)
+ {
+ }
+ int_type get()
+ {
+ return id_;
+ }
+ private:
+ int_type id_;
+ static int_type next_id_;
+ };
+
+ template <typename Tag, typename Int>
+ Int id<Tag, Int>::next_id_ = 0;
+
+ /**
+ * A Roles specification consists of the entity, the role type and the tag.
+ */
+ template <typename Entity, typename Role, typename Tag>
+ struct role_spec
+ {
+ typedef Entity entity_type;
+ typedef Role role_type;
+ static const id<Entity> id_;
+ };
+
+ template <typename Entity, typename Role, typename Tag>
+ const id<Entity> role_spec<Entity, Role, Tag>::id_;
+
+ /**
+ * All the Entities have this class as base class.
+ */
+ class entity_base;
+
+ /**
+ * All the Roles have this class as base class.
+ * A Role is non-copyable and contains a pointer to its entity.
+ */
+ class role_base
+ {
+ public:
+ BOOST_ROLE_NO_COPYABLE( role_base)
+
+ entity_base& get_entity()
+ {
+ return *entity_;
+ }
+ void set_entity(entity_base& e)
+ {
+ entity_ = &e;
+ }
+ void unset_entity()
+ {
+ entity_ = 0;
+ }
+
+ protected:
+ entity_base* entity_;
+ explicit role_base(entity_base& e) :
+ entity_(&e)
+ {
+ }
+ };
+
+ /**
+ * @example
+ *
+ * class Rake : public role<User>
+ * {
+ * public:
+ * Rake(User&);
+ * ...
+ * };
+ * struct F1 : role_spec<User, Rake, F1> {};
+ *
+ * User u;
+ * add_tagged_role<F1>(u);
+ */
+
+ template <typename Entity, typename Base = role_base>
+ class role: public Base
+ {
+ public:
+ typedef Entity entity_type;
+ typedef Base base_type;
+
+ explicit role(entity_type& e) :
+ base_type(e)
+ {
+ }
+
+ ~role()
+ {
+ }
+
+ entity_type& get_entity()
+ {
+ return *static_cast<entity_type*> (this->entity_);
+ }
+ void set_entity(entity_type& e)
+ {
+ this->entity_ = &e;
+ }
+ void unset_entity()
+ {
+ this->entity_ = 0;
+ }
+ };
+
+ /**
+ * @example
+ *
+ * class Rake : public unique_role<User, Rake>
+ * {
+ * public:
+ * Rake(User&);
+ * ...
+ * };
+ * User u;
+ * add_role<Rake>(u);
+ */
+ template <typename Entity, typename Role, typename Base = role_base>
+ class unique_role: public role<Entity, Base> , public role_spec<Entity, Role, Role>
+ {
+ public:
+ typedef Entity entity_type;
+ typedef role<Entity, Base> base_type;
+
+ explicit unique_role(entity_type& e) :
+ base_type(e)
+ {
+ }
+ };
+
+ /**
+ *
+ */
+ class entity_base
+ {
+ public:
+ static const std::size_t max_num_of_roles = 0;
+ entity_base()
+BOOST_NOEXCEPT ;
+ entity_base(const entity_base& e) BOOST_NOEXCEPT;
+ protected:
+ class impl;
+ shared_ptr<impl> impl_;
+
+ entity_base(impl*) BOOST_NOEXCEPT;
+
+ bool has_role2(std::size_t id) const;
+ shared_ptr<role_base> use_role2(std::size_t);
+ void add_role2(shared_ptr<role_base> r, std::size_t id);
+ void remove_role2(std::size_t id);
+ void move_role2(entity_base& e, std::size_t to, std::size_t from);
+
+ };
+
+ /////////////////////////
+ // This should be placed on a specific header file available to
+ class entity_base::impl
+ {
+ std::vector<shared_ptr<role_base> > roles_;
+ public:
+ BOOST_ROLE_NO_COPYABLE(impl)
+ explicit impl()
+ {
+ }
+ ~impl()
+ {}
+
+ bool has_role(std::size_t id) const
+ {
+ return (id < roles_.size()) && roles_[id];
+ }
+
+ shared_ptr<role_base> use_role(std::size_t id)
+ {
+ return roles_[id];
+ }
+
+ void add_role(shared_ptr<role_base> r, std::size_t id)
+ {
+ if (roles_.size() <= id)
+ {
+ roles_.resize(id+1);
+ }
+ roles_[id] = r;
+ }
+ void remove_role(std::size_t id)
+ {
+ if (!has_role(id)) return;
+
+ roles_[id]->unset_entity();
+ roles_[id].reset();
+ }
+
+ void move_role(entity_base& target, std::size_t to, std::size_t from)
+ {
+ if (!has_role(from)) return;
+
+ roles_[from]->set_entity(target);
+ target.add_role2(roles_[from], to);
+ roles_[from].reset();
+ }
+ };
+
+ entity_base::entity_base()
+ : impl_(new impl())
+ {
+ }
+ entity_base::entity_base(const entity_base& rhs)
+ : impl_(rhs.impl_)
+ {
+ }
+ entity_base::entity_base(entity_base::impl *impl)
+ : impl_(impl)
+ {
+ }
+
+ bool
+ entity_base::has_role2(std::size_t id) const
+ {
+ return impl_->has_role(id);
+ }
+ shared_ptr<role_base>
+ entity_base::use_role2(std::size_t id)
+ {
+ return impl_->use_role(id);
+ }
+
+ void
+ entity_base::add_role2(shared_ptr<role_base> r, std::size_t id)
+ {
+ impl_->add_role(r, id);
+ }
+ void
+ entity_base::remove_role2(std::size_t id)
+ {
+ impl_->remove_role(id);
+ }
+ void
+ entity_base::move_role2(entity_base& target, std::size_t to, std::size_t from)
+ {
+ impl_->move_role(target, to, from);
+ }
+ /////////////////////////
+
+ /**
+ * This mixin provides access of up to @c N Roles associated to the entity @c Entity.
+ *
+ * @TParams
+ * @TParam{Entity,the entity to been defined}
+ * @TParam{N,the number of roles of this entity}
+ * @TParam{Base,the base class}
+ *
+ * @Example
+ * <code>
+ * class User : public entity<User, 3>
+ * {
+ * };
+ * class Subscriber : public entity<Subscriber, 5, User>
+ * {
+ * };
+ * </code>
+ */
+ template <typename Entity, std::size_t N, typename Base=entity_base>
+ class entity : public Base
+ {
+ public:
+ /**
+ * Default constructor
+ */
+ entity() BOOST_NOEXCEPT
+ : Base()
+ {}
+ /**
+ * Copy constructor
+ */
+ entity(const entity& e) BOOST_NOEXCEPT
+ : Base(e)
+ {}
+
+ protected:
+ /**
+ * First role id associated to this entity slice.
+ */
+ static const std::size_t first_role = Base::max_num_of_roles;
+ /**
+ * Last+1 role id associated to this entity slice.
+ */
+ static const std::size_t max_num_of_roles = N+Base::max_num_of_roles;
+
+ /**
+ * The implementation type
+ */
+ typedef typename Base::impl impl;
+
+ /**
+ * constructor from impl
+ */
+ entity(impl* i)
+ : Base(i)
+ {}
+
+ bool has_role(id<Entity> id) const;
+ shared_ptr<role<Entity> > use_role(id<Entity>);
+ void add_role(shared_ptr<role<Entity> > r, id<Entity> id);
+ void remove_role(id<Entity> id);
+ void move_role(Entity& e, id<Entity> to, id<Entity> from);
+
+ template <typename Tag, typename Entity2>
+ friend bool has_tagged_role(const Entity2& e) BOOST_NOEXCEPT;
+ template <typename Tag, typename Entity2>
+ friend shared_ptr<typename Tag::role_type> use_tagged_role(Entity2& e);
+ template <typename Tag, typename Entity2, typename Role>
+ friend shared_ptr<Role> add_tagged_role(Entity2& e, Role* r);
+ template <typename Tag, typename Entity2>
+ friend void remove_tagged_role(Entity2& e);
+ template <typename ToTag, typename FromTag, typename Entity2>
+ friend void move_tagged_role(Entity2& to, Entity2& from);
+
+ };
+
+ template <typename Entity, std::size_t N, typename Base>
+ bool
+ entity<Entity,N,Base>::has_role(id<Entity> id) const
+ {
+ return this->has_role2(first_role+id.get());
+ }
+
+ template <typename Entity, std::size_t N, typename Base>
+ shared_ptr<role<Entity> >
+ entity<Entity,N,Base>::use_role(id<Entity> id)
+ {
+ return static_pointer_cast<role<Entity> >(this->use_role2(first_role+id.get()));
+ }
+
+ template <typename Entity, std::size_t N, typename Base>
+ void
+ entity<Entity,N,Base>::add_role(shared_ptr<role<Entity> > r, id<Entity> id)
+ {
+ this->add_role2(static_pointer_cast<role_base>(r), first_role+id.get());
+ }
+
+ template <typename Entity, std::size_t N, typename Base>
+ void
+ entity<Entity,N,Base>::remove_role(id<Entity> id)
+ {
+ this->remove_role2(first_role+id.get());
+ }
+
+ template <typename Entity, std::size_t N, typename Base>
+ void
+ entity<Entity,N,Base>::move_role(Entity& target, id<Entity> to, id<Entity> from)
+ {
+ this->move_role2(target, first_role+to.get(), first_role+from.get());
+ }
+
+ //////////////////
+
+ template <typename Tag, typename Entity>
+ const shared_ptr<typename Tag::role_type> use_tagged_role(const Entity& e)
+ {
+ typedef typename Tag::role_type Role;
+ typedef typename Tag::entity_type entity_type;
+ return static_pointer_cast<Role>(static_cast<const entity_type&>(e).use_role(Tag::id_));
+ }
+ template <typename Tag, typename Entity>
+ shared_ptr<typename Tag::role_type> use_tagged_role(Entity& e)
+ {
+ typedef typename Tag::entity_type entity_type;
+ typedef typename Tag::role_type Role;
+ return static_pointer_cast<Role>(static_cast<entity_type&>(e).use_role(Tag::id_));
+ }
+ template <class Role, typename Entity>
+ const shared_ptr<Role> use_role(const Entity& e)
+ {
+ return use_tagged_role<Role>(e);
+ }
+ template <class Role, typename Entity>
+ shared_ptr<Role> use_role(Entity& e)
+ {
+ return use_tagged_role<Role>(e);
+ }
+
+ template <typename Tag, typename Entity>
+ bool has_tagged_role(const Entity& e) BOOST_NOEXCEPT
+ {
+ typedef typename Tag::entity_type entity_type;
+ return static_cast<const entity_type&>(e).has_role(Tag::id_);
+ }
+ template <class Role, typename Entity>
+ bool has_role(const Entity& e) BOOST_NOEXCEPT
+ {
+ return has_tagged_role<Role>(e);
+ }
+
+ template <typename Tag, typename Entity, typename Role>
+ shared_ptr<Role> add_tagged_role(Entity& e, Role* r)
+ {
+ typedef typename Tag::entity_type entity_type;
+ shared_ptr<role<typename Tag::entity_type> > sp(r);
+ static_cast<entity_type&>(e).add_role(sp, Tag::id_);
+ r->set_entity(e);
+ return static_pointer_cast<Role>(sp);
+ }
+ template <typename Entity, class Role>
+ shared_ptr<Role> add_role(Entity& e, Role* r)
+ {
+ return add_tagged_role<Role>(e, r);
+ }
+ template <typename Tag, typename Entity>
+ shared_ptr<typename Tag::role_type> add_tagged_role(Entity& e)
+ {
+ typedef typename Tag::role_type Role;
+ return add_tagged_role<Tag>(e, new Role(e));
+ }
+ template <class Role, typename Entity>
+ shared_ptr<Role> add_role(Entity& e)
+ {
+ return add_tagged_role<Role>(e);
+ }
+
+ template <typename Tag, typename Entity>
+ void remove_tagged_role(Entity& e)
+ {
+ typedef typename Tag::entity_type entity_type;
+ static_cast<entity_type&>(e).remove_role(Tag::id_);
+ }
+ template <class Role, typename Entity>
+ void remove_role(Entity& e)
+ {
+ remove_tagged_role<Role>(e);
+ }
+
+ template <typename ToTag, typename FromTag, typename Entity>
+ void move_tagged_role(Entity& to, Entity& from)
+ {
+ typedef typename ToTag::entity_type entity_type;
+ static_cast<entity_type&>(from).move_role(to, ToTag::id_, FromTag::id_);
+ }
+ template <class Role, typename Entity>
+ void move_role(Entity& to, Entity& from)
+ {
+ move_tagged_role<Role,Role>(to, from);
+ }
+
+ }
+}
+
+#endif // header

Added: sandbox/role/libs/role/example/ex_xx.cpp
==============================================================================
--- (empty file)
+++ sandbox/role/libs/role/example/ex_xx.cpp 2012-05-09 16:03:24 EDT (Wed, 09 May 2012)
@@ -0,0 +1,147 @@
+// Copyright (C) 2012 Vicente J. Botet Escriba
+//
+// 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)
+
+#include <iostream>
+#include <boost/role/entity_role.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+using namespace boost::entity_role;
+
+namespace Ex
+{
+ class User: public entity<User, 3>
+ {
+ typedef entity<User, 3> base_type;
+ public:
+ User(int id=0) :
+ base_type(new impl(id))
+ {
+ }
+ protected:
+ struct impl : public base_type::impl
+ {
+ impl() : id_(0) {}
+ impl(int id) : id_(id) {}
+ int id_;
+ };
+ User(impl* i) :
+ base_type(i)
+ {
+ }
+ };
+ class Rake: public unique_role<User, Rake>
+ {
+ public:
+ Rake(User& u) :
+ unique_role<User, Rake> (u), i(0)
+ {
+ }
+ int i;
+ };
+ class Searcher: public unique_role<User, Searcher>
+ {
+ public:
+ Searcher(User& u) :
+ unique_role<User, Searcher> (u), i(0)
+ {
+ }
+ int i;
+ };
+ class Tracker: public entity<Tracker, 2>, public unique_role<User, Tracker>
+ {
+ public:
+ Tracker(User& u) :
+ entity<Tracker, 2>(), unique_role<User, Tracker>(u), i(0)
+ {
+ }
+ int i;
+ };
+ class HsupaUser: public entity<HsupaUser, 2, User>
+ {
+ };
+ class Role1: public unique_role<HsupaUser, Role1>
+ {
+ public:
+ Role1(HsupaUser& u) :
+ unique_role<HsupaUser, Role1> (u), i(0)
+ {
+ }
+ int i;
+ };
+}
+
+int main()
+{
+ std::cout << __FILE__ << ":" << __LINE__ << std::endl;
+ {
+ Ex::User u;
+ add_role<Ex::Rake> (u);
+ BOOST_TEST( has_role<Ex::Rake> (u));
+ }
+ {
+ Ex::HsupaUser u;
+ add_role<Ex::Rake> (u);
+ BOOST_TEST( has_role<Ex::Rake> (u));
+ }
+ {
+ Ex::HsupaUser u;
+ add_role<Ex::Role1> (u);
+ BOOST_TEST( has_role<Ex::Role1> (u));
+ }
+ {
+ Ex::User u;
+ add_role<Ex::Rake> (u);
+ add_role<Ex::Rake> (u);
+ BOOST_TEST( has_role<Ex::Rake> (u));
+ }
+ {
+ Ex::User u;
+ add_role<Ex::Rake> (u);
+ use_role<Ex::Rake> (u)->i = 1;
+ }
+ {
+ Ex::User u;
+ add_role<Ex::Rake> (u);
+ BOOST_TEST(&use_role<Ex::Rake> (u)->get_entity() == &u);
+ }
+ {
+ Ex::HsupaUser u;
+ add_role<Ex::Rake> (u);
+ use_role<Ex::Rake> (u)->i = 1;
+ }
+ {
+ Ex::User u;
+ add_role<Ex::Rake> (u);
+ remove_role<Ex::Rake> (u);
+ BOOST_TEST(!has_role<Ex::Rake> (u));
+ }
+ {
+ Ex::HsupaUser u;
+ add_role<Ex::Rake> (u);
+ remove_role<Ex::Rake> (u);
+ BOOST_TEST(!has_role<Ex::Rake> (u));
+ }
+ {
+ Ex::User u, v;
+ add_role<Ex::Rake> (u);
+ BOOST_TEST( has_role<Ex::Rake> (u));
+ BOOST_TEST(!has_role<Ex::Rake> (v));
+ move_role<Ex::Rake> (v, u);
+ BOOST_TEST(!has_role<Ex::Rake> (u));
+ BOOST_TEST( has_role<Ex::Rake> (v));
+ }
+ {
+ Ex::HsupaUser u, v;
+ add_role<Ex::Rake> (u);
+ BOOST_TEST( has_role<Ex::Rake> (u));
+ BOOST_TEST(!has_role<Ex::Rake> (v));
+ move_role<Ex::Rake> (v, u);
+ BOOST_TEST(!has_role<Ex::Rake> (u));
+ BOOST_TEST( has_role<Ex::Rake> (v));
+ }
+ std::cout << __FILE__ << ":" << __LINE__ << std::endl;
+ return 1 + boost::report_errors();
+}
+

Added: sandbox/role/libs/role/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/role/libs/role/test/Jamfile.v2 2012-05-09 16:03:24 EDT (Wed, 09 May 2012)
@@ -0,0 +1,72 @@
+#~ Copyright Vicente J. Botet Escriba 2012
+#~ 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)
+
+
+project
+ : requirements
+ #<library>/boost/test//boost_test_exec_monitor/<link>static
+ <include>../../..
+ <define>BOOST_ALL_NO_LIB=1
+
+ <warnings>all
+ <toolset>gcc:<cxxflags>-Wextra
+ <toolset>gcc:<cxxflags>-pedantic
+ <toolset>gcc:<cxxflags>-Wno-long-long
+ #<toolset>gcc:<cxxflags>-ansi
+ #<toolset>gcc:<cxxflags>-fpermissive
+ <toolset>gcc:<cxxflags>-Wno-long-long
+ <toolset>gcc:<cxxflags>-Wshadow
+ <toolset>gcc:<cxxflags>-Wcast-align
+
+ <toolset>darwin:<cxxflags>-Wextra
+ <toolset>darwin:<cxxflags>-pedantic
+ <toolset>darwin:<cxxflags>-ansi
+ <toolset>darwin:<cxxflags>-fpermissive
+ <toolset>darwin:<cxxflags>-Wno-long-long
+ #<toolset>darwin:<cxxflags>-Wno-type-limits
+
+ #<toolset>pathscale:<cxxflags>-Wextra
+ <toolset>pathscale:<cxxflags>-Wno-long-long
+ <toolset>pathscale:<cxxflags>-pedantic
+
+ <toolset>clang:<cxxflags>-Wextra
+ <toolset>clang:<cxxflags>-pedantic
+ <toolset>clang:<cxxflags>-ansi
+ #<toolset>clang:<cxxflags>-fpermissive
+ <toolset>clang:<cxxflags>-Wno-long-long
+
+ <toolset>gcc-mingw-4.4.0:<cxxflags>-fdiagnostics-show-option
+ <toolset>gcc-mingw-4.5.0:<cxxflags>-fdiagnostics-show-option
+ <toolset>gcc-mingw-4.6.0:<cxxflags>-fdiagnostics-show-option
+ <toolset>gcc-mingw-4.6.3:<cxxflags>-fdiagnostics-show-option
+ <toolset>gcc-mingw-4.7.0:<cxxflags>-fdiagnostics-show-option
+ <toolset>gcc-mingw-4.8.0:<cxxflags>-fdiagnostics-show-option
+
+ <toolset>darwin-4.6.2:<cxxflags>-Wno-delete-non-virtual-dtor
+ <toolset>darwin-4.6.2:<cxxflags>-Wno-type-limits
+ <toolset>darwin-4.7.0:<cxxflags>-Wno-delete-non-virtual-dtor
+ <toolset>darwin-4.7.0:<cxxflags>-Wno-type-limits
+
+
+ #<toolset>clang-2.8:<cxxflags>-Wno-delete-non-virtual-dtor
+ #<toolset>clang-2.8:<cxxflags>-Wno-unused-function
+ <toolset>clang-2.8:<cxxflags>-Wno-sign-compare
+ #<toolset>clang-2.9:<cxxflags>-Wno-delete-non-virtual-dtor
+ #<toolset>clang-2.9:<cxxflags>-Wno-unused-function
+ <toolset>clang-3.0:<cxxflags>-Wno-delete-non-virtual-dtor
+ #<toolset>clang-3.0:<cxxflags>-Wno-unused-function
+ #<toolset>clang-3.0:<cxxflags>-Wno-unused-variable
+
+ #<toolset>gcc:<warnings-as-errors>on
+ #<toolset>intel:<warnings-as-errors>on
+ #<toolset>msvc:<warnings-as-errors>on
+ ;
+
+import testing ;
+
+
+test-suite examples :
+ [ run ../example/ex_xx.cpp ]
+ ;
+


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