summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-08-18 03:34:09 +0000
committerAlan Conway <aconway@apache.org>2007-08-18 03:34:09 +0000
commit86dfb3e98b4c680db636bdbcd1fb63e7b0784f2b (patch)
tree1820a8750ed9e862395fc5a5c61d2660a703336a /cpp/src
parent857c70fa8b6ca7e9a3b0544e1fd746fdf2752e9d (diff)
downloadqpid-python-86dfb3e98b4c680db636bdbcd1fb63e7b0784f2b.tar.gz
* 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
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/qpid/client/Response.h3
-rw-r--r--cpp/src/qpid/framing/Blob.h20
-rw-r--r--cpp/src/qpid/framing/MethodHolder.cpp8
-rw-r--r--cpp/src/qpid/framing/MethodHolder.h14
-rwxr-xr-xcpp/src/tests/quick_perftest2
5 files changed, 31 insertions, 16 deletions
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 <class T> T& as()
{
framing::AMQMethodBody* response(future->getResponse());
- return dynamic_cast<T&>(*response);
+ assert(response);
+ return *boost::polymorphic_downcast<T*>(response);
}
template <class T> 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<void>(); }
/** Copy a blob. */
- Blob(const Blob& b) { assign(b); }
+ Blob(const Blob& b) { setType<void>(); assign(b); }
+
+ /** @see construct() */
+ template<class Expr>
+ Blob( const Expr & expr ) { setType<void>(); construct(expr,&expr); }
+
+ ~Blob() { clear(); }
/** Assign a blob */
Blob& operator=(const Blob& b) {
@@ -123,12 +131,6 @@ class Blob
return *this;
}
- /** @see construct() */
- template<class Expr>
- 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<T>(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<void>::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<AMQMethodBody*>(blob.get());
+}
+
+const AMQMethodBody* MethodHolder::get() const {
+ return const_cast<MethodHolder*>(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<AMQMethodBody*>(blob.get());
- }
- const AMQMethodBody* get() const {
- return reinterpret_cast<const AMQMethodBody*>(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<MAX_METHODBODY_SIZE> 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