#ifndef QPID_AMQP_0_10_BUILT_IN_TYPES_H #define QPID_AMQP_0_10_BUILT_IN_TYPES_H /* * * 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 "qpid/Serializer.h" #include "qpid/framing/Uuid.h" #include "qpid/sys/IntegerTypes.h" #include "qpid/sys/Time.h" #include "qpid/amqp_0_10/Decimal.h" #include "qpid/amqp_0_10/SerializableString.h" #include #include #include #include #include /**@file Mapping from built-in AMQP types to C++ types */ namespace qpid { namespace framing { class SequenceNumber; class SequenceSet; } namespace amqp_0_10 { /** Wrapper that behaves like type T but is a distinct type for * overloading purposes. Unique allows multiple distinc wrappers. */ template struct Wrapper { T value; Wrapper() {} Wrapper(const T& x) : value(x) {} Wrapper& operator=(const T& x) { value=x; return *this; } operator T&() { return value; } operator const T&() const { return value; } template void serialize(S& s) { s(value); } }; template inline std::ostream& operator<<(std::ostream& o, const Wrapper& w) { return o << w.value; } /** Void type */ struct Void { template void serialize(S&) {} }; inline std::ostream& operator<<(std::ostream& o, const Void&) { return o; } /** Bit is a presence indicator - an optional value with no encoding. */ struct Bit : public Wrapper { Bit(bool b=false) : Wrapper(b) {} using Wrapper::operator=; template void serialize(S& s) { s.split(*this); } template void encode(S&) const { } template void decode(S&) { *this = true; } }; inline std::ostream& operator<<(std::ostream& o, const Bit& b) { return o << bool(b); } // Fixed size types typedef bool Boolean; typedef char Char; typedef int8_t Int8; typedef int16_t Int16; typedef int32_t Int32; typedef int64_t Int64; typedef uint8_t Uint8; typedef uint16_t Uint16; typedef uint32_t Uint32; typedef uint64_t Uint64; typedef Wrapper CharUtf32; template struct Bin : public boost::array { template void serialize(S& s) { s.raw(this->begin(), this->size()); } }; template std::ostream& operator<<(std::ostream& o, const Bin& b) { return o << boost::make_iterator_range(b.begin(), b.end()); } template <> struct Bin<1> : public boost::array { Bin(char c=0) { this->front() = c; } operator char() { return this->front(); } template void serialize(S& s) { s(front()); } }; typedef Bin<1> Bin8; typedef Bin<128> Bin1024; typedef Bin<16> Bin128; typedef Bin<2> Bin16; typedef Bin<32> Bin256; typedef Bin<4> Bin32; typedef Bin<5> Bin40; typedef Bin<64> Bin512; typedef Bin<8> Bin64; typedef Bin<9> Bin72; typedef double Double; typedef float Float; typedef framing::SequenceNumber SequenceNo; using framing::Uuid; typedef sys::AbsTime Datetime; typedef Decimal Dec32; typedef Decimal Dec64; // Variable width types typedef SerializableString Vbin8; typedef SerializableString Str8Latin; typedef SerializableString Str8; typedef SerializableString Str8Utf16; typedef SerializableString Vbin16; typedef SerializableString Str16Latin; typedef SerializableString Str16; typedef SerializableString Str16Utf16; typedef SerializableString Vbin32; typedef framing::SequenceSet SequenceSet; // Forward declare class types. class Map; class Struct32; class UnknownType; template struct ArrayDomain; typedef ArrayDomain Array; // FIXME aconway 2008-04-08: TODO struct ByteRanges { template void serialize(S&) {} }; struct List { template void serialize(S&) {} }; // FIXME aconway 2008-03-10: dummy ostream operators inline std::ostream& operator<<(std::ostream& o, const ByteRanges&) { return o; } inline std::ostream& operator<<(std::ostream& o, const SequenceSet&) { return o; } inline std::ostream& operator<<(std::ostream& o, const List&) { return o; } enum SegmentType { CONTROL, COMMAND, HEADER, BODY }; inline SerializeAs serializable(SegmentType& st) { return SerializeAs(st); } }} // namespace qpid::amqp_0_10 #endif