diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Makefile.am | 8 | ||||
-rw-r--r-- | cpp/src/qpid/amqp_0_10/built_in_types.h | 23 | ||||
-rw-r--r-- | cpp/src/qpid/amqp_0_10/helpers.cpp | 30 | ||||
-rw-r--r-- | cpp/src/qpid/amqp_0_10/helpers.h | 55 | ||||
-rw-r--r-- | cpp/src/tests/serialize.cpp | 4 |
5 files changed, 86 insertions, 34 deletions
diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index df0b867b00..0a63ce1b90 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -11,11 +11,13 @@ EXTRA_DIST= $(platform_dist) # This phony target is needed by generated makefile fragments: force: -# AMQP_XML is defined in ../configure.ac -specs=@AMQP_XML@ $(top_srcdir)/xml/cluster.xml - if GENERATE +# AMQP_PREVIEW_XML and AMQP_FINAL_XML are defined in ../configure.ac +amqp_99_0_xml=@AMQP_PREVIEW_XML@ $(top_srcdir)/xml/cluster.xml +amqp_0_10_xml=@AMQP_FINAL_XML@ +specs=$(amqp_99_0_xml) $(amqp_0_10_xml) + # Ruby generator. rgen_dir=$(top_srcdir)/rubygen rgen_cmd=ruby -I $(rgen_dir) $(rgen_dir)/generate $(srcdir)/gen $(specs) all $(srcdir)/rubygen.mk diff --git a/cpp/src/qpid/amqp_0_10/built_in_types.h b/cpp/src/qpid/amqp_0_10/built_in_types.h index 6cd9c72367..445f07459c 100644 --- a/cpp/src/qpid/amqp_0_10/built_in_types.h +++ b/cpp/src/qpid/amqp_0_10/built_in_types.h @@ -29,6 +29,7 @@ #include <boost/array.hpp> #include <stdint.h> #include <string> +#include <vector> /**@file Mapping from built-in AMQP types to C++ types */ @@ -66,7 +67,7 @@ typedef double Double; typedef float Float; typedef framing::SequenceNumber SequenceNo; using framing::Uuid; -typedef sys::AbsTime DateTime; +typedef sys::AbsTime Datetime; typedef Decimal<Uint8, Int32> Dec32; typedef Decimal<Uint8, Int64> Dec64; @@ -89,14 +90,18 @@ typedef CodableString<Uint16, Uint16> Str16Utf16; typedef CodableString<Uint8, Uint32> Vbin32; -/** FIXME aconway 2008-02-20: todo -byte-ranges 2 byte ranges within a 64-bit payload -sequence-set 2 ranged set representation -map 0xa8 4 a mapping of keys to typed values -list 0xa9 4 a series of consecutive type-value pairs -array 0xaa 4 a defined length collection of values of a single type -struct32 0xab 4 a coded struct with a 32-bit size -*/ +// FIXME aconway 2008-02-26: array encoding +template <class T> struct Array : public std::vector<T> {}; + +// FIXME aconway 2008-02-26: Unimplemented types: +struct ByteRanges {}; +struct SequenceSet {}; +struct Map {}; +struct List {}; +struct Struct32 {}; + +// Top level enum definitions. +enum SegmentType { CONTROL, COMMAND, HEADER, BODY }; }} // namespace qpid::amqp_0_10 diff --git a/cpp/src/qpid/amqp_0_10/helpers.cpp b/cpp/src/qpid/amqp_0_10/helpers.cpp new file mode 100644 index 0000000000..4333a2cd92 --- /dev/null +++ b/cpp/src/qpid/amqp_0_10/helpers.cpp @@ -0,0 +1,30 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include "helpers.h" + +namespace qpid { +namespace amqp_0_10 { + +Control::~Control() {} +Command::~Command() {} +Struct::~Struct() {} + +}} // namespace qpid::amqp_0_10 diff --git a/cpp/src/qpid/amqp_0_10/helpers.h b/cpp/src/qpid/amqp_0_10/helpers.h index 1d93d1d51c..c916a3e869 100644 --- a/cpp/src/qpid/amqp_0_10/helpers.h +++ b/cpp/src/qpid/amqp_0_10/helpers.h @@ -8,7 +8,7 @@ * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance +n * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 @@ -27,43 +27,58 @@ namespace qpid { namespace amqp_0_10 { -struct ClassAttributes { uint8_t code; const char* name }; +/** Static information about an AMQP class */ +struct ClassInfo { uint8_t code; const char* name; }; -struct MemberAttributes { - ClassAttributes class_; - const char* name - uint8_t code; +/** Info about a class memeber - command, control or struct */ +struct MemberInfo { + ClassInfo* class_; // 0 for top level struct. + const char* name; + uint8_t code; std::string fullName() const { - return std::string(class_.name)+"."+name; + return std::string(class_->name)+"."+name; } }; -struct StructAttributes : public MemberAttributes { uint8_t size, pack; }; +/** Info about a struct */ +struct StructInfo : public MemberInfo { uint8_t size, pack; }; -static const ClassAttributes getClass(uint8_t code); -static const MemberAttributes getCommand(uint8_t classCode, uint8_t code); -static const MemberAttributes getControl(uint8_t classCode, uint8_t code); +// Look up info by code. +const ClassInfo& getClassInfo(uint8_t code); +const MemberInfo& getCommandInfo(uint8_t classCode, uint8_t code); +const MemberInfo& getControlInfo(uint8_t classCode, uint8_t code); +const StructInfo& getStructInfo(uint8_t classCode, uint8_t code); -struct Command : public Member { +struct Command { + virtual ~Command(); class Visitor; - virtual const MemberAttributes& attributes() const = 0; + virtual const MemberInfo& info() const = 0; virtual void accept(Visitor&) const = 0; }; -struct Control : public Member { +struct Control { + virtual ~Control(); class Visitor; - struct Attributes { uint8_t classCode, code }; - - virtual const MemberAttributes& attributes() const = 0; + virtual const MemberInfo& info() const = 0; virtual void accept(Visitor&) const = 0; }; - -struct Struct : public Member { - virtual const StructAttributes& attributes() const = 0; +struct Struct { + virtual ~Struct(); + virtual const StructInfo& info() const = 0; }; +/** Base class for generated enum domains. + * Enums map to classes for type safety and to provide separate namespaces + * for clashing values. + */ +struct Enum { + int value; + Enum(int v=0) : value(v) {} + operator int() const { return value; } + template <class S> void serialize(S &s) { s(value); } +}; }} // namespace qpid::amqp_0_10 diff --git a/cpp/src/tests/serialize.cpp b/cpp/src/tests/serialize.cpp index 72a92ee226..a120be6458 100644 --- a/cpp/src/tests/serialize.cpp +++ b/cpp/src/tests/serialize.cpp @@ -79,7 +79,7 @@ template <class A, class B, class C, class D> struct concat4 { typedef typename typedef mpl::vector<Bit, Boolean, Char, Int32, Int64, Int8, Uint16, CharUtf32, Uint32, Uint64, Bin8, Uint8>::type IntegralTypes; typedef mpl::vector<Bin1024, Bin128, Bin16, Bin256, Bin32, Bin40, Bin512, Bin64, Bin72>::type BinTypes; typedef mpl::vector<Double, Float>::type FloatTypes; -typedef mpl::vector<SequenceNo, Uuid, DateTime, Dec32, Dec64> FixedSizeClassTypes; +typedef mpl::vector<SequenceNo, Uuid, Datetime, Dec32, Dec64> FixedSizeClassTypes; typedef mpl::vector<Vbin8, Str8Latin, Str8, Str8Utf16, Vbin16, Str16Latin, Str16, Str16Utf16, Vbin32> VariableSizeTypes; @@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE(testNetworkByteOrder) { void testValue(bool& b) { b = true; } template <class T> typename boost::enable_if<boost::is_arithmetic<T> >::type testValue(T& n) { n=42; } void testValue(long long& l) { l = 12345; } -void testValue(DateTime& dt) { dt = qpid::sys::now(); } +void testValue(Datetime& dt) { dt = qpid::sys::now(); } void testValue(Uuid& uuid) { uuid=Uuid(true); } template <class E, class M> void testValue(Decimal<E,M>& d) { d.exponent=2; d.mantissa=1234; } void testValue(SequenceNo& s) { s = 42; } |