diff options
| author | Alan Conway <aconway@apache.org> | 2007-11-22 23:55:39 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2007-11-22 23:55:39 +0000 |
| commit | cb070d9813e4232b4ec8409ca555b529ee5cee4b (patch) | |
| tree | 7f8ed15de2c4f933db59b79b52222c70f2a2a240 /cpp/src/qpid/framing/Blob.h | |
| parent | 4d16c847bd0868ac8ff3039ce22fcdae28606aeb (diff) | |
| download | qpid-python-cb070d9813e4232b4ec8409ca555b529ee5cee4b.tar.gz | |
Added framing::BodyHolder:
- Uniform holder for all body types, replaces MethodHolder.
- Uses in_place constructors to avoid avoid body copy.
framing::AMQFrame:
- Holds body in heap-allocated intrusive_ptr<BodyHolder>
- Uses in_place constructors to avoid avoid body copy.
Removed/downgraded to TODO many redundant FIXME comments.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@597513 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/framing/Blob.h')
| -rw-r--r-- | cpp/src/qpid/framing/Blob.h | 73 |
1 files changed, 41 insertions, 32 deletions
diff --git a/cpp/src/qpid/framing/Blob.h b/cpp/src/qpid/framing/Blob.h index 9d0c33dee6..344e4ac4db 100644 --- a/cpp/src/qpid/framing/Blob.h +++ b/cpp/src/qpid/framing/Blob.h @@ -25,38 +25,45 @@ #include <boost/aligned_storage.hpp> #include <boost/checked_delete.hpp> #include <boost/utility/typed_in_place_factory.hpp> +#include <boost/type_traits/is_base_and_derived.hpp> +#include <boost/utility/enable_if.hpp> #include <new> #include <assert.h> -namespace boost { +namespace qpid { +namespace framing { -/** - * 0-arg typed_in_place_factory constructor and in_place() override. - * - * Boost doesn't provide the 0 arg version since it assumes - * in_place_factory will be used when there is no default ctor. - */ +using boost::in_place; +using boost::typed_in_place_factory_base; + +/** 0-arg typed_in_place_factory, missing in boost. */ template <class T> -class typed_in_place_factory0 : public typed_in_place_factory_base { - public: +struct typed_in_place_factory0 : public typed_in_place_factory_base { typedef T value_type ; void apply ( void* address ) const { new (address) T(); } }; +/** 0-arg in_place<T>() function, missing from boost. */ template<class T> typed_in_place_factory0<T> in_place() { return typed_in_place_factory0<T>(); } -} // namespace boost - - -namespace qpid { -namespace framing { - -using boost::in_place; - +template <class T, class R=void> +struct EnableInPlace + : public boost::enable_if<boost::is_base_and_derived< + typed_in_place_factory_base, T>, + R> +{}; + +template <class T, class R=void> +struct DisableInPlace + : public boost::disable_if<boost::is_base_and_derived< + typed_in_place_factory_base, T>, + R> +{}; + template <class T> struct BlobHelper { static void destroy(void* ptr) { static_cast<T*>(ptr)->~T(); } static void copy(void* dest, const void* src) { @@ -108,11 +115,10 @@ class Blob basePtr=0; } - template<class TypedInPlaceFactory> - void construct (const TypedInPlaceFactory& factory, - const boost::typed_in_place_factory_base* ) + template<class Factory> + typename EnableInPlace<Factory>::type apply(const Factory& factory) { - typedef typename TypedInPlaceFactory::value_type T; + typedef typename Factory::value_type T; assert(empty()); factory.apply(store.address()); setType<T>(); @@ -135,28 +141,31 @@ class Blob Blob(const Blob& b) { initialize(); assign(b); } /** @see construct() */ - template<class Expr> - Blob( const Expr & expr ) { initialize(); construct(expr,&expr); } + template<class InPlace> + Blob(const InPlace & expr, typename EnableInPlace<InPlace>::type* =0) { + initialize(); apply(expr); + } ~Blob() { clear(); } - /** Assign a blob */ + /** Assign from another blob. */ Blob& operator=(const Blob& b) { clear(); assign(b); return *this; } - /** Construcct an object in the blob. Destroyes the previous object. - *@param expr an expresion of the form: in_place<T>(x,y,z) - * will construct an object using the constructor T(x,y,z) - */ - template<class Expr> void - construct(const Expr& expr) { clear(); construct(expr,&expr); } + /** Assign from an in_place constructor expression. */ + template<class InPlace> + typename EnableInPlace<InPlace,Blob&>::type operator=(const InPlace& expr) { + clear(); apply(expr); return *this; + } - /** Copy construct an instance of T into the Blob. */ + /** Assign from an object of type T. */ template <class T> - Blob& operator=(const T& x) { clear(); construct(in_place<T>(x)); return *this; } + typename DisableInPlace<T, Blob&>::type operator=(const T& x) { + clear(); apply(in_place<T>(x)); return *this; + } /** Get pointer to blob contents, returns 0 if empty. */ BaseType* get() { return basePtr; } |
