From 86dfb3e98b4c680db636bdbcd1fb63e7b0784f2b Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Sat, 18 Aug 2007 03:34:09 +0000 Subject: * src/qpid/framing/MethodHolder.h * src/qpid/framing/Blob.h - add empty() test - get() returns 0 when empty * src/qpid/client/Response.h: assert checks. * src/tests/perftest.cpp: default to listen and publish. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@567221 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/client/Response.h | 3 ++- cpp/src/qpid/framing/Blob.h | 20 ++++++++++++-------- cpp/src/qpid/framing/MethodHolder.cpp | 8 ++++++++ cpp/src/qpid/framing/MethodHolder.h | 14 +++++++------- cpp/src/tests/quick_perftest | 2 ++ 5 files changed, 31 insertions(+), 16 deletions(-) create mode 100755 cpp/src/tests/quick_perftest (limited to 'cpp/src') diff --git a/cpp/src/qpid/client/Response.h b/cpp/src/qpid/client/Response.h index ad37d7c0f4..7866df916c 100644 --- a/cpp/src/qpid/client/Response.h +++ b/cpp/src/qpid/client/Response.h @@ -39,7 +39,8 @@ public: template T& as() { framing::AMQMethodBody* response(future->getResponse()); - return dynamic_cast(*response); + assert(response); + return *boost::polymorphic_downcast(response); } template bool isA() { diff --git a/cpp/src/qpid/framing/Blob.h b/cpp/src/qpid/framing/Blob.h index 643c4ab93d..ea44dc104e 100644 --- a/cpp/src/qpid/framing/Blob.h +++ b/cpp/src/qpid/framing/Blob.h @@ -97,6 +97,7 @@ class Blob void construct (const TypedInPlaceFactory& factory, const boost::typed_in_place_factory_base* ) { + assert(empty()); typedef typename TypedInPlaceFactory::value_type T; assert(sizeof(T) <= Size); factory.apply(store.address()); @@ -104,6 +105,7 @@ class Blob } void assign(const Blob& b) { + assert(empty()); b.copy(this->get(), b.get()); copy = b.copy; destroy = b.destroy; @@ -114,7 +116,13 @@ class Blob Blob() { setType(); } /** Copy a blob. */ - Blob(const Blob& b) { assign(b); } + Blob(const Blob& b) { setType(); assign(b); } + + /** @see construct() */ + template + Blob( const Expr & expr ) { setType(); construct(expr,&expr); } + + ~Blob() { clear(); } /** Assign a blob */ Blob& operator=(const Blob& b) { @@ -123,12 +131,6 @@ class Blob return *this; } - /** @see construct() */ - template - Blob( const Expr & expr ) { construct(expr,&expr); } - - ~Blob() { clear(); } - /** Construcct an object in the blob. Destroyes the previous object. *@param expr an expresion of the form: in_place(x,y,z) * will construct an object using the constructor T(x,y,z) @@ -144,7 +146,7 @@ class Blob void* get() { return store.address(); } /** Get const pointer to blob contents */ - const void* get() const { return store.address(); } + const void* get() const { return empty() ? 0 : store.address(); } /** Destroy the object in the blob making it empty. */ void clear() { @@ -153,6 +155,8 @@ class Blob oldDestroy(store.address()); } + bool empty() const { return destroy == BlobHelper::destroy; } + static size_t size() { return Size; } }; diff --git a/cpp/src/qpid/framing/MethodHolder.cpp b/cpp/src/qpid/framing/MethodHolder.cpp index de8f0da6d4..b1582dd571 100644 --- a/cpp/src/qpid/framing/MethodHolder.cpp +++ b/cpp/src/qpid/framing/MethodHolder.cpp @@ -31,6 +31,14 @@ using namespace boost; namespace qpid { namespace framing { +AMQMethodBody* MethodHolder::get() { + return static_cast(blob.get()); +} + +const AMQMethodBody* MethodHolder::get() const { + return const_cast(this)->get(); +} + void MethodHolder::encode(Buffer& b) const { const AMQMethodBody* body = get(); b.putShort(body->amqpClassId()); diff --git a/cpp/src/qpid/framing/MethodHolder.h b/cpp/src/qpid/framing/MethodHolder.h index 59dbb1a708..a8bc8f2728 100644 --- a/cpp/src/qpid/framing/MethodHolder.h +++ b/cpp/src/qpid/framing/MethodHolder.h @@ -75,13 +75,13 @@ class MethodHolder void encode(Buffer&) const; void decode(Buffer&); uint32_t size() const; - - AMQMethodBody* get() { - return reinterpret_cast(blob.get()); - } - const AMQMethodBody* get() const { - return reinterpret_cast(blob.get()); - } + + /** Return method pointer or 0 if empty. */ + AMQMethodBody* get(); + const AMQMethodBody* get() const; + + /** True if no method has been set */ + bool empty() const { return blob.empty(); } private: Blob blob; diff --git a/cpp/src/tests/quick_perftest b/cpp/src/tests/quick_perftest new file mode 100755 index 0000000000..cbafc57872 --- /dev/null +++ b/cpp/src/tests/quick_perftest @@ -0,0 +1,2 @@ +#!/bin/sh +exec `dirname $0`/test_env ./perftest --listen --publish --count 1000 -- cgit v1.2.1