Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54442 - in sandbox/monotonic: boost boost/heterogenous libs/monotonic/test/clones
From: christian.schladetsch_at_[hidden]
Date: 2009-06-28 03:04:36


Author: cschladetsch
Date: 2009-06-28 03:04:34 EDT (Sun, 28 Jun 2009)
New Revision: 54442
URL: http://svn.boost.org/trac/boost/changeset/54442

Log:
added
Added:
   sandbox/monotonic/boost/heterogenous/
   sandbox/monotonic/boost/heterogenous/vector.hpp (contents, props changed)
Text files modified:
   sandbox/monotonic/boost/cloneable.hpp | 1
   sandbox/monotonic/libs/monotonic/test/clones/clones.vcproj | 8 ++
   sandbox/monotonic/libs/monotonic/test/clones/main.cpp | 134 +++------------------------------------
   3 files changed, 21 insertions(+), 122 deletions(-)

Modified: sandbox/monotonic/boost/cloneable.hpp
==============================================================================
--- sandbox/monotonic/boost/cloneable.hpp (original)
+++ sandbox/monotonic/boost/cloneable.hpp 2009-06-28 03:04:34 EDT (Sun, 28 Jun 2009)
@@ -9,6 +9,7 @@
 #include <boost/abstract_allocator.hpp>
 #include <boost/aligned_storage.hpp>
 #include <boost/type_traits/is_convertible.hpp>
+#include <boost/ptr_container/ptr_vector.hpp>
 
 namespace boost
 {

Added: sandbox/monotonic/boost/heterogenous/vector.hpp
==============================================================================
--- (empty file)
+++ sandbox/monotonic/boost/heterogenous/vector.hpp 2009-06-28 03:04:34 EDT (Sun, 28 Jun 2009)
@@ -0,0 +1,134 @@
+// Copyright (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)
+
+#ifndef BOOST_HETEROGENOUS_VECTOR_HPP
+#define BOOST_HETEROGENOUS_VECTOR_HPP
+
+#include <boost/cloneable.hpp>
+#include <boost/ptr_container/ptr_vector.hpp>
+
+namespace boost
+{
+ namespace heterogenous
+ {
+ template <class Alloc = cloneable::make_cloneable_allocator<std::allocator<char> > >
+ struct vector
+ {
+ typedef ptr_vector<cloneable::common_base, cloneable::allocator, Alloc> implementation;
+ typedef Alloc allocator_type;
+ typedef typename implementation::value_type value_type;
+ typedef typename implementation::reference reference_type;
+ typedef typename implementation::iterator iterator;
+ typedef typename implementation::const_iterator const_iterator;
+
+ private:
+ implementation impl;
+
+ public:
+
+ size_t size() const
+ {
+ return impl.size();
+ }
+
+ iterator begin()
+ {
+ return impl.begin();
+ }
+ iterator end()
+ {
+ return impl.end();
+ }
+ const_iterator begin() const
+ {
+ return impl.begin();
+ }
+ const_iterator end() const
+ {
+ return impl.end();
+ }
+ reference_type at(size_t n)
+ {
+ return impl.at(n);
+ }
+ reference_type operator[](size_t n)
+ {
+ return impl[n];
+ }
+ template <class Other>
+ bool is_type_at(size_t n) const
+ {
+ return ptr_at<Other>(n) != 0;
+ }
+ template <class Other>
+ Other &ref_at(size_t n)
+ {
+ Other *ptr = ptr_at<Other>(n);
+ if (ptr == 0)
+ throw std::bad_cast();
+ return *ptr;
+ }
+ template <class Other>
+ Other *ptr_at(size_t n)
+ {
+ return dynamic_cast<Other *>(&at(n));
+ }
+ template <class U>
+ void push_back()
+ {
+ U *ptr = construct_type<U>();
+ base().push_back(ptr);
+ }
+ template <class U, class A0>
+ void push_back(A0 a0)
+ {
+ U *ptr = allocate_type<U>();
+ new (ptr) U(a0);
+ impl.push_back(ptr);
+ }
+ template <class U, class A0, class A1>
+ void push_back(A0 a0, A1 a1)
+ {
+ U *ptr = allocate_type<U>();
+ new (ptr) U(a0, a1);
+ impl.push_back(ptr);
+ }
+ template <class U, class A0, class A1, class A2>
+ void push_back(A0 a0, A1 a1, A2 a2)
+ {
+ U *ptr = allocate_type<U>();
+ new (ptr) U(a0, a1, a2);
+ impl.push_back(ptr);
+ }
+
+ allocator_type get_allocator()
+ {
+ return impl.get_allocator();
+ }
+ private:
+ template <class U>
+ U *allocate_type()
+ {
+ typename allocator_type::template rebind<U>::other alloc(get_allocator());
+ return alloc.allocate(1);
+ }
+ template <class U>
+ U *construct_type()
+ {
+ typename allocator_type::template rebind<U>::other alloc(get_allocator());
+ U *ptr = alloc.allocate(1);
+ alloc.construct(ptr);
+ return ptr;
+ }
+
+ };
+
+ } // namespace heterogenous
+
+} // namespace boost
+
+#endif // BOOST_HETEROGENOUS_VECTOR_HPP
+
+//EOF

Modified: sandbox/monotonic/libs/monotonic/test/clones/clones.vcproj
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/clones/clones.vcproj (original)
+++ sandbox/monotonic/libs/monotonic/test/clones/clones.vcproj 2009-06-28 03:04:34 EDT (Sun, 28 Jun 2009)
@@ -347,6 +347,14 @@
                                         </File>
                                 </Filter>
                         </Filter>
+ <Filter
+ Name="heterogenous"
+ >
+ <File
+ RelativePath="..\..\..\..\boost\heterogenous\vector.hpp"
+ >
+ </File>
+ </Filter>
                 </Filter>
                 <File
                         RelativePath=".\main.cpp"

Modified: sandbox/monotonic/libs/monotonic/test/clones/main.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/clones/main.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/clones/main.cpp 2009-06-28 03:04:34 EDT (Sun, 28 Jun 2009)
@@ -11,10 +11,7 @@
 //
 
 #include <string>
-#include <boost/abstract_allocator.hpp>
-#include <boost/cloneable.hpp>
-#include <boost/monotonic/allocator.hpp>
-#include <boost/ptr_container/ptr_vector.hpp>
+#include <boost/heterogenous/vector.hpp>
 
 using namespace std;
 using namespace boost;
@@ -45,124 +42,6 @@
         explicit derived3(float f, int n, std::string const &s) : real(f), num(n), str(s) { }
 };
 
-namespace boost
-{
- namespace heterogenous
- {
- template <class Alloc = cloneable::make_cloneable_allocator<std::allocator<char> > >
- struct vector
- {
- typedef ptr_vector<cloneable::common_base, cloneable::allocator, Alloc> implementation;
- typedef Alloc allocator_type;
- typedef typename implementation::value_type value_type;
- typedef typename implementation::reference reference_type;
- typedef typename implementation::iterator iterator;
- typedef typename implementation::const_iterator const_iterator;
-
- private:
- implementation impl;
-
- public:
-
- size_t size() const
- {
- return impl.size();
- }
-
- iterator begin()
- {
- return impl.begin();
- }
- iterator end()
- {
- return impl.end();
- }
- const_iterator begin() const
- {
- return impl.begin();
- }
- const_iterator end() const
- {
- return impl.end();
- }
- reference_type at(size_t n)
- {
- return impl.at(n);
- }
- reference_type operator[](size_t n)
- {
- return impl[n];
- }
- template <class Other>
- bool is_type_at(size_t n) const
- {
- return ptr_at<Other>(n) != 0;
- }
- template <class Other>
- Other &ref_at(size_t n)
- {
- Other *ptr = ptr_at<Other>(n);
- if (ptr == 0)
- throw std::bad_cast();
- return *ptr;
- }
- template <class Other>
- Other *ptr_at(size_t n)
- {
- return dynamic_cast<Other *>(&at(n));
- }
- template <class U>
- void push_back()
- {
- U *ptr = construct_type<U>();
- base().push_back(ptr);
- }
- template <class U, class A0>
- void push_back(A0 a0)
- {
- U *ptr = allocate_type<U>();
- new (ptr) U(a0);
- impl.push_back(ptr);
- }
- template <class U, class A0, class A1>
- void push_back(A0 a0, A1 a1)
- {
- U *ptr = allocate_type<U>();
- new (ptr) U(a0, a1);
- impl.push_back(ptr);
- }
- template <class U, class A0, class A1, class A2>
- void push_back(A0 a0, A1 a1, A2 a2)
- {
- U *ptr = allocate_type<U>();
- new (ptr) U(a0, a1, a2);
- impl.push_back(ptr);
- }
-
- allocator_type get_allocator()
- {
- return impl.get_allocator();
- }
- private:
- template <class U>
- U *allocate_type()
- {
- typename allocator_type::template rebind<U>::other alloc(get_allocator());
- return alloc.allocate(1);
- }
- template <class U>
- U *construct_type()
- {
- typename allocator_type::template rebind<U>::other alloc(get_allocator());
- U *ptr = alloc.allocate(1);
- alloc.construct(ptr);
- return ptr;
- }
-
- };
- }
-}
-
 int main()
 {
         // there is a problem with static_move_ptr<>
@@ -194,6 +73,17 @@
                 BOOST_ASSERT(p3->num == -123);
                 BOOST_ASSERT(p3->str == "spam");
 
+ bool caught = false;
+ try
+ {
+ derived3 &pp = copy.ref_at<derived2>(0);
+ }
+ catch (std::bad_cast)
+ {
+ caught = true;
+ }
+ BOOST_ASSERT(caught);
+
         }
         monotonic::static_storage<>::release();
 


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