00001 #ifndef QPID_AMQP_0_10_BUILT_IN_TYPES_H
00002 #define QPID_AMQP_0_10_BUILT_IN_TYPES_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "qpid/Serializer.h"
00025 #include "qpid/framing/SequenceNumber.h"
00026 #include "qpid/framing/Uuid.h"
00027 #include "qpid/sys/Time.h"
00028 #include "Decimal.h"
00029 #include "SerializableString.h"
00030 #include <boost/array.hpp>
00031 #include <boost/range/iterator_range.hpp>
00032 #include <string>
00033 #include <ostream>
00034 #include <vector>
00035 #include <stdint.h>
00036
00039 namespace qpid {
00040 namespace amqp_0_10 {
00041
00045 template <class T, int Unique=0> struct Wrapper {
00046 T value;
00047 Wrapper() {}
00048 Wrapper(const T& x) : value(x) {}
00049 Wrapper& operator=(const T& x) { value=x; return *this; }
00050 operator T&() { return value; }
00051 operator const T&() const { return value; }
00052 template <class S> void serialize(S& s) { s(value); }
00053 };
00054
00055 template<class T>
00056 inline std::ostream& operator<<(std::ostream& o, const Wrapper<T>& w) {
00057 return o << w.value;
00058 }
00059
00061 struct Void { template <class S> void serialize(S&) {} };
00062 inline std::ostream& operator<<(std::ostream& o, const Void&) { return o; }
00063
00065 struct Bit : Wrapper<bool> {
00066 template <class S> void serialize(S& s) { s.split(*this); }
00067 template <class S> void encode(S&) const {}
00068 template <class S> void decode(S&) { value=true; }
00069 };
00070 inline std::ostream& operator<<(std::ostream& o, const Bit& b) {
00071 return o << b.value;
00072 }
00073
00074
00075 typedef bool Boolean;
00076 typedef char Char;
00077 typedef int8_t Int8;
00078 typedef int16_t Int16;
00079 typedef int32_t Int32;
00080 typedef int64_t Int64;
00081 typedef uint8_t Uint8;
00082 typedef uint16_t Uint16;
00083 typedef uint32_t Uint32;
00084 typedef uint64_t Uint64;
00085 typedef Wrapper<uint32_t> CharUtf32;
00086
00087 template <size_t N> struct Bin : public boost::array<char, N> {
00088 template <class S> void serialize(S& s) { s.raw(this->begin(), this->size()); }
00089 };
00090
00091 template <size_t N> std::ostream& operator<<(std::ostream& o, const Bin<N>& b) {
00092 return o << boost::make_iterator_range(b.begin(), b.end());
00093 }
00094
00095 template <> struct Bin<1> : public boost::array<char, 1> {
00096 Bin(char c=0) { this->front() = c; }
00097 operator char() { return this->front(); }
00098 template <class S> void serialize(S& s) { s(front()); }
00099 };
00100
00101 typedef Bin<1> Bin8;
00102 typedef Bin<128> Bin1024;
00103 typedef Bin<16> Bin128;
00104 typedef Bin<2> Bin16;
00105 typedef Bin<32> Bin256;
00106 typedef Bin<4> Bin32;
00107 typedef Bin<5> Bin40;
00108 typedef Bin<64> Bin512;
00109 typedef Bin<8> Bin64;
00110 typedef Bin<9> Bin72;
00111
00112 typedef double Double;
00113 typedef float Float;
00114 typedef framing::SequenceNumber SequenceNo;
00115 using framing::Uuid;
00116 typedef sys::AbsTime Datetime;
00117
00118 typedef Decimal<Uint8, Int32> Dec32;
00119 typedef Decimal<Uint8, Int64> Dec64;
00120
00121
00122
00123 typedef SerializableString<Uint8, Uint8> Vbin8;
00124 typedef SerializableString<char, Uint8, 1> Str8Latin;
00125 typedef SerializableString<char, Uint8> Str8;
00126 typedef SerializableString<Uint16, Uint8> Str8Utf16;
00127
00128 typedef SerializableString<Uint8, Uint16> Vbin16;
00129 typedef SerializableString<char, Uint16, 1> Str16Latin;
00130 typedef SerializableString<char, Uint16> Str16;
00131 typedef SerializableString<Uint16, Uint16> Str16Utf16;
00132
00133 typedef SerializableString<Uint8, Uint32> Vbin32;
00134
00135
00136 class Map;
00137 class UnknownType;
00138 template <class T> struct ArrayDomain;
00139 typedef ArrayDomain<UnknownType> Array;
00140
00141
00142 struct ByteRanges { template <class S> void serialize(S&) {} };
00143 struct SequenceSet { template <class S> void serialize(S&) {} };
00144 struct List { template <class S> void serialize(S&) {} };
00145 struct Struct32 { template <class S> void serialize(S&) {} };
00146
00147
00148 inline std::ostream& operator<<(std::ostream& o, const ByteRanges&) { return o; }
00149 inline std::ostream& operator<<(std::ostream& o, const SequenceSet&) { return o; }
00150 inline std::ostream& operator<<(std::ostream& o, const List&) { return o; }
00151 inline std::ostream& operator<<(std::ostream& o, const Struct32&) { return o; }
00152
00153 enum SegmentType { CONTROL, COMMAND, HEADER, BODY };
00154
00155 inline SerializeAs<SegmentType, uint8_t> serializable(SegmentType& st) {
00156 return SerializeAs<SegmentType, uint8_t>(st);
00157 }
00158
00159
00160 }}
00161
00162 #endif