Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54597 - in sandbox: cloneable/boost/cloneable cloneable/libs/cloneable/test monotonic/libs/monotonic/test
From: christian.schladetsch_at_[hidden]
Date: 2009-07-02 17:17:26


Author: cschladetsch
Date: 2009-07-02 17:17:25 EDT (Thu, 02 Jul 2009)
New Revision: 54597
URL: http://svn.boost.org/trac/boost/changeset/54597

Log:
added ability to search a set, using base type
Text files modified:
   sandbox/cloneable/boost/cloneable/adaptor.hpp | 1
   sandbox/cloneable/boost/cloneable/set.hpp | 76 ++++++++++++++++++++++++++++++++++-----
   sandbox/cloneable/libs/cloneable/test/cloneable.vcproj | 8 ++++
   sandbox/cloneable/libs/cloneable/test/tests.cpp | 44 ++++++----------------
   sandbox/monotonic/libs/monotonic/test/monotonic.vcproj | 4 ++
   5 files changed, 91 insertions(+), 42 deletions(-)

Modified: sandbox/cloneable/boost/cloneable/adaptor.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/adaptor.hpp (original)
+++ sandbox/cloneable/boost/cloneable/adaptor.hpp 2009-07-02 17:17:25 EDT (Thu, 02 Jul 2009)
@@ -18,6 +18,7 @@
                 struct adaptor : T, base<adaptor<T, Base>, Base>
                 {
                         adaptor() { }
+ adaptor(const adaptor &X) : T(X), base<adaptor<T,Base>,Base>(X) { }
 
                         template <class A0>
                         adaptor(A0 a0) : T(a0)

Modified: sandbox/cloneable/boost/cloneable/set.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/set.hpp (original)
+++ sandbox/cloneable/boost/cloneable/set.hpp 2009-07-02 17:17:25 EDT (Thu, 02 Jul 2009)
@@ -11,6 +11,7 @@
 
 #include <boost/cloneable/detail/make_clone_allocator.hpp>
 #include <boost/cloneable/allocator.hpp>
+#include <boost/cloneable/adaptor.hpp>
 
 namespace boost
 {
@@ -35,7 +36,7 @@
                         typedef typename implementation::const_iterator const_iterator;
                         typedef set<Base, Pred, Alloc> this_type;
 
- private:
+ //private:
                         implementation impl;
 
                 public:
@@ -117,17 +118,72 @@
                                 return impl.end();
                         }
 
- template <class U, class A0>
- iterator find(A0 a0) // strong
+ struct impl
                         {
- abstract_base_type *instance = 0;
- instance = detail::construct<U,base_type>(get_allocator(), a0).to_abstract();
- BOOST_CLONEABLE_SCOPE_EXIT((instance))
+ template <class U>
+ struct find
                                 {
- cloneable::release(instance, self->get_allocator());
- }
- BOOST_CLONEABLE_SCOPE_EXIT_END
- return impl.find(*instance);
+ template <class A0>
+ static iterator given(this_type *cont, A0 a0)
+ {
+ abstract_base_type *instance = 0;
+ instance = detail::construct<U,base_type>(cont->get_allocator(), a0).to_abstract();
+ BOOST_SCOPE_EXIT((instance)(cont))
+ {
+ cloneable::release(instance, cont->get_allocator());
+ }
+ BOOST_SCOPE_EXIT_END
+ return cont->find_instance<U>(instance);
+ }
+ template <class A0, class A1>
+ static iterator given(this_type *cont, A0 a0, A1 a1)
+ {
+ abstract_base_type *instance = 0;
+ instance = detail::construct<U,base_type>(cont->get_allocator(), a0, a1).to_abstract();
+ BOOST_SCOPE_EXIT((instance)(cont))
+ {
+ cloneable::release(instance, cont->get_allocator());
+ }
+ BOOST_SCOPE_EXIT_END
+ return cont->find_instance<U>(instance);
+ }
+ };
+ struct default_key : base<default_key, base_type>
+ {
+ default_key() { }
+ default_key(base_type const &X) : base<default_key, base_type>::base_type(X) { }
+ };
+
+ template <>
+ struct find<base_type>
+ {
+ template <class A0>
+ static iterator given(this_type *cont, A0 a0)
+ {
+ return cont->impl.find(default_key(base_type(a0)));
+ }
+ template <class A0, class A1>
+ static iterator given(this_type *cont, A0 a0, A1 a1)
+ {
+ return cont->impl.find(default_key(base_type(a0, a1)));
+ }
+ };
+ };
+ template <class U>
+ iterator find_instance(value_type instance)
+ {
+ iterator found = impl.find(*instance);
+ if (found == impl.end())
+ return found;
+ if (U *ptr = dynamic_cast<U *>(&*found))
+ return found;
+ return impl.end();
+ }
+
+ template <class U, class A0>
+ iterator find(A0 a0)
+ {
+ return impl::find<U>::given(this, a0);
                         }
 
                         typename implementation::allocator_type get_allocator()

Modified: sandbox/cloneable/libs/cloneable/test/cloneable.vcproj
==============================================================================
--- sandbox/cloneable/libs/cloneable/test/cloneable.vcproj (original)
+++ sandbox/cloneable/libs/cloneable/test/cloneable.vcproj 2009-07-02 17:17:25 EDT (Thu, 02 Jul 2009)
@@ -252,6 +252,14 @@
                                 </Filter>
                         </Filter>
                 </Filter>
+ <Filter
+ Name="doc"
+ >
+ <File
+ RelativePath="..\..\..\..\..\..\..\Lib\boost_1_39_0\libs\cloneable\doc\cloneable.qbk"
+ >
+ </File>
+ </Filter>
                 <File
                         RelativePath=".\tests.cpp"
>

Modified: sandbox/cloneable/libs/cloneable/test/tests.cpp
==============================================================================
--- sandbox/cloneable/libs/cloneable/test/tests.cpp (original)
+++ sandbox/cloneable/libs/cloneable/test/tests.cpp 2009-07-02 17:17:25 EDT (Thu, 02 Jul 2009)
@@ -515,62 +515,42 @@
 
 namespace set_test
 {
- struct my_base : abstract_object<my_base>
+ struct set_base
         {
                 int number;
- my_base(int n = 0) : number(n) { }
- bool less(const my_base &other) const
+ set_base(int n = 0) : number(n) { }
+ bool operator<(const set_base &other) const
                 {
                         return number < other.number;
                 }
         };
- struct S0 : base<S0, my_base>
+ struct S0 : base<S0, set_base>
         {
- S0(int n = 0) : my_base(n) { }
+ S0(int n = 0) : set_base(n) { }
         };
- struct S1 : base<S1, my_base>
+ struct S1 : base<S1, set_base>
         {
- S1(int n = 0) : my_base(n) { }
+ S1(int n = 0) : set_base(n) { }
         };
 
- struct S2 : base<S2, my_base>
+ struct S2 : base<S2, set_base>
         {
- S2(int n = 0) : my_base(n) { }
+ S2(int n = 0) : set_base(n) { }
         };
-
- //struct set_less
- // //: std::binary_function<default_base_type const &,default_base_type const &,bool>
- // : boost::function<bool (default_base_type const &,default_base_type const &)>
- //{
- // bool operator()(default_base_type const &a, default_base_type const &b) const
- // {
- // return &a < &b;
- // }
- //};
 }
 
-//namespace boost
-//{
-// namespace cloneable
-// {
-// // hax due to result_of<> issue with ptr_set and predicates
-// bool operator<(default_base_type const &a, default_base_type const &b)
-// {
-// return &a < &b;
-// }
-// }
-//}
-
 BOOST_AUTO_TEST_CASE(test_set)
 {
         using namespace set_test;
- cloneable::set<set_test::my_base> set;
+ cloneable::set<set_base> set;
         set.emplace_insert<S0>(1);
         set.emplace_insert<S1>(2);
         set.emplace_insert<S2>(3);
         set.emplace_insert<S2>(4);
 
+ BOOST_ASSERT(set.size() == 4);
         BOOST_ASSERT(set.find<S0>(1) != set.end());
+ BOOST_ASSERT(set.find<set_base>(2) != set.end());
 }
 
 

Modified: sandbox/monotonic/libs/monotonic/test/monotonic.vcproj
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/monotonic.vcproj (original)
+++ sandbox/monotonic/libs/monotonic/test/monotonic.vcproj 2009-07-02 17:17:25 EDT (Thu, 02 Jul 2009)
@@ -475,6 +475,10 @@
                                 RelativePath="..\doc\index.html"
>
                         </File>
+ <File
+ RelativePath="..\..\..\..\..\..\..\Lib\boost_1_39_0\libs\monotonic\doc\monotonic.qbk"
+ >
+ </File>
                 </Filter>
                 <Filter
                         Name="results"


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