diff options
author | Andrew Stitcher <astitcher@apache.org> | 2013-10-29 21:53:36 +0000 |
---|---|---|
committer | Andrew Stitcher <astitcher@apache.org> | 2013-10-29 21:53:36 +0000 |
commit | 75c01a275bb269042b30262dde28f68faf32c785 (patch) | |
tree | 451473a9d12fa47cce6b2a7d212a98a392cadeb6 /qpid/cpp/include | |
parent | de9e2692a0ddfdef4dac98334953019d6887902f (diff) | |
download | qpid-python-75c01a275bb269042b30262dde28f68faf32c785.tar.gz |
QPID-4327: Include file moved to correct place
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1536903 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/include')
-rw-r--r-- | qpid/cpp/include/qpid/framing/BufferTypes.h | 106 |
1 files changed, 0 insertions, 106 deletions
diff --git a/qpid/cpp/include/qpid/framing/BufferTypes.h b/qpid/cpp/include/qpid/framing/BufferTypes.h deleted file mode 100644 index 4199755852..0000000000 --- a/qpid/cpp/include/qpid/framing/BufferTypes.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef QPID_FRAMING_BUFFERTYPES_H -#define QPID_FRAMING_BUFFERTYPES_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. - * - */ - -/**@file - * Using templates with framing::Buffer is difficultg becase of the many - * different put/get function names. Here we define a set of types - * corresponding the basic types of Buffer but presenting a uniform - * encode/decode/encodedSize interface. - * - * It also provides some convenience templates for the common case of - * encoding a single encodable value as a string, e.g. - * - * LongString ls("hello"); - * std::string encoded = encodeStr(ls); - * LongString ls2 = decodeStr<LongString>(encoded); - * LongString ls3; - * decodeStr(encoded, ls3); - */ - -namespace qpid { -namespace framing { - -// Templates to help define types -template <class ValueType> struct BufferTypeTraits { - typedef void (Buffer::*Put)(const ValueType&); - typedef void (Buffer::*Get)(ValueType&); -}; - -template <class ValueType, - typename BufferTypeTraits<ValueType>::Put PutFn, - typename BufferTypeTraits<ValueType>::Get GetFn> -struct EncodeDecodeTemplate { - EncodeDecodeTemplate(const ValueType& s) : value(s) {} - operator ValueType() const { return value; } - - ValueType value; - void encode(framing::Buffer& buf) const { (buf.*PutFn)(value); } - void decode(framing::Buffer& buf) { (buf.*GetFn)(value); } -}; - -template <size_t Size, - typename BufferTypeTraits<std::string>::Put PutFn, - typename BufferTypeTraits<std::string>::Get GetFn - > -struct StringTypeTemplate : public EncodeDecodeTemplate<std::string, PutFn, GetFn> { - typedef EncodeDecodeTemplate<std::string, PutFn, GetFn> Base; - StringTypeTemplate(const std::string& s) : Base(s) {} - size_t encodedSize() const { return Size + Base::value.size(); } -}; - - -// Convenience tempates for encoding/decoding values to/from a std::string. - -/** Encode value as a string. */ -template <class T> std::string encodeStr(const T& value) { - std::string encoded(value.encodedSize(), '\0'); - framing::Buffer buffer(&encoded[0], encoded.size()); - value.encode(buffer); - return encoded; -} - -/** Decode value from a string. */ -template <class T> void decodeStr(const std::string& encoded, T& value) { - framing::Buffer b(const_cast<char*>(&encoded[0]), encoded.size()); - value.decode(b); -} - -/** Decode value from a string. */ -template <class T> T decodeStr(const std::string& encoded) { - T value; - decodeStr(encoded, value); - return value; -} - -// The types - -typedef StringTypeTemplate<4, &Buffer::putLongString, &Buffer::getLongString> LongString; -typedef StringTypeTemplate<2, &Buffer::putMediumString, &Buffer::getMediumString> MediumString; -typedef StringTypeTemplate<1, &Buffer::putShortString, &Buffer::getShortString> ShortString; - -// TODO aconway 2013-07-26: Add integer types. - -}} // namespace qpid::framing - -#endif /*!QPID_FRAMING_BUFFERTYPES_H*/ |