Added a minimal forward declaration header file for pack/unpack overloading.

This commit is contained in:
Takatoshi Kondo
2014-10-13 00:04:10 +09:00
parent 3ddeb08e6e
commit 4c00f448aa
34 changed files with 207 additions and 146 deletions

View File

@@ -84,6 +84,7 @@ LIST (APPEND msgpack_HEADERS
IF (MSGPACK_ENABLE_CXX)
LIST (APPEND msgpack_HEADERS
include/msgpack.hpp
include/msgpack_forward.hpp
include/msgpack/adaptor/bool.hpp
include/msgpack/adaptor/char_ptr.hpp
include/msgpack/adaptor/cpp11/array.hpp
@@ -115,6 +116,7 @@ IF (MSGPACK_ENABLE_CXX)
include/msgpack/detail/cpp11_zone.hpp
include/msgpack/fbuffer.hpp
include/msgpack/object.hpp
include/msgpack/object_forward.hpp
include/msgpack/pack.hpp
include/msgpack/sbuffer.hpp
include/msgpack/type.hpp

View File

@@ -19,6 +19,7 @@
#define MSGPACK_CPP03_DEFINE_HPP
#include "msgpack/versioning.hpp"
#include "msgpack_forward.hpp"
#define MSGPACK_DEFINE(...) \
template <typename Packer> \

View File

@@ -19,7 +19,7 @@
#define MSGPACK_CPP03_MSGPACK_TUPLE_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
namespace msgpack {

View File

@@ -23,7 +23,7 @@
#include <vector>
#include "msgpack/versioning.hpp"
#include "msgpack/cpp_config.hpp"
#include "msgpack_forward.hpp"
#ifndef MSGPACK_ZONE_CHUNK_SIZE
#define MSGPACK_ZONE_CHUNK_SIZE 8192

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_BOOL_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
#include <vector>
namespace msgpack {

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_CHAR_PTR_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
#include <cstring>
namespace msgpack {

View File

@@ -20,12 +20,10 @@
#define MSGPACK_CPP11_ARRAY_HPP
#include "msgpack/versioning.hpp"
#include "msgpack_forward.hpp"
#include <array>
#include "msgpack/object.hpp"
#include "msgpack/cpp_config.hpp"
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_ARRAY_CHAR_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
#include <array>
namespace msgpack {

View File

@@ -20,12 +20,10 @@
#define MSGPACK_CPP11_FORWARD_LIST_HPP
#include "msgpack/versioning.hpp"
#include "msgpack_forward.hpp"
#include <forward_list>
#include "msgpack/object.hpp"
#include "msgpack/cpp_config.hpp"
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {

View File

@@ -19,12 +19,10 @@
#define MSGPACK_CPP11_TUPLE_HPP
#include "msgpack/versioning.hpp"
#include "msgpack_forward.hpp"
#include <tuple>
#include "msgpack/object.hpp"
#include "msgpack/cpp_config.hpp"
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_DEQUE_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
#include <deque>
namespace msgpack {

View File

@@ -19,6 +19,7 @@
#define MSGPACK_CPP03_DEFINE_HPP
#include "msgpack/versioning.hpp"
#include "msgpack_forward.hpp"
#define MSGPACK_DEFINE(...) \
template <typename Packer> \

View File

@@ -19,7 +19,7 @@
#define MSGPACK_CPP03_MSGPACK_TUPLE_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
namespace msgpack {

View File

@@ -19,6 +19,7 @@
#define MSGPACK_CPP11_DEFINE_HPP
#include "msgpack/versioning.hpp"
#include "msgpack_forward.hpp"
#include <type_traits>

View File

@@ -19,12 +19,10 @@
#define MSGPACK_CPP11_MSGPACK_TUPLE_HPP
#include "msgpack/versioning.hpp"
#include "msgpack_forward.hpp"
#include <tuple>
#include "msgpack/object.hpp"
#include "msgpack/cpp_config.hpp"
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_FIXINT_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
#include "msgpack/adaptor/int.hpp"
namespace msgpack {

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_FLOAT_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
#include <vector>
namespace msgpack {

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_INT_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
#include <limits>
namespace msgpack {

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_LIST_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
#include <list>
namespace msgpack {

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_MAP_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
#include <map>
#include <vector>
#include <algorithm>

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_NIL_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
namespace msgpack {

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_PAIR_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
#include <utility>
namespace msgpack {

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_RAW_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
#include <string.h>
#include <string>

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_SET_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
#include <set>

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_STRING_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
#include <string>
namespace msgpack {

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_TR1_UNORDERED_MAP_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_TR1_UNORDERED_SET_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_VECTOR_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
#include <vector>
namespace msgpack {

View File

@@ -19,7 +19,7 @@
#define MSGPACK_TYPE_VECTOR_CHAR_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
#include "msgpack_forward.hpp"
#include <vector>
namespace msgpack {

View File

@@ -23,7 +23,7 @@
#include <vector>
#include "msgpack/versioning.hpp"
#include "msgpack/cpp_config.hpp"
#include "msgpack_forward.hpp"
#ifndef MSGPACK_ZONE_CHUNK_SIZE
#define MSGPACK_ZONE_CHUNK_SIZE 8192

View File

@@ -1,7 +1,7 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2010 FURUHASHI Sadayuki
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -19,9 +19,9 @@
#define MSGPACK_OBJECT_HPP
#include "msgpack/versioning.hpp"
#include "object.h"
#include "pack.hpp"
#include "zone.hpp"
#include "msgpack/object_forward.hpp"
#include "msgpack/pack.hpp"
#include "msgpack/zone.hpp"
#include <string.h>
#include <stdexcept>
#include <typeinfo>
@@ -32,114 +32,6 @@ namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
class type_error : public std::bad_cast { };
namespace type {
enum object_type {
NIL = MSGPACK_OBJECT_NIL,
BOOLEAN = MSGPACK_OBJECT_BOOLEAN,
POSITIVE_INTEGER = MSGPACK_OBJECT_POSITIVE_INTEGER,
NEGATIVE_INTEGER = MSGPACK_OBJECT_NEGATIVE_INTEGER,
DOUBLE = MSGPACK_OBJECT_DOUBLE,
STR = MSGPACK_OBJECT_STR,
BIN = MSGPACK_OBJECT_BIN,
ARRAY = MSGPACK_OBJECT_ARRAY,
MAP = MSGPACK_OBJECT_MAP,
EXT = MSGPACK_OBJECT_EXT
};
}
struct object;
struct object_kv;
struct object_array {
uint32_t size;
object* ptr;
};
struct object_map {
uint32_t size;
object_kv* ptr;
};
struct object_str {
uint32_t size;
const char* ptr;
};
struct object_bin {
uint32_t size;
const char* ptr;
};
struct object_ext {
int8_t type() const { return ptr[0]; }
const char* data() const { return &ptr[1]; }
uint32_t size;
const char* ptr;
};
struct object {
union union_type {
bool boolean;
uint64_t u64;
int64_t i64;
double dec;
object_array array;
object_map map;
object_str str;
object_bin bin;
object_ext ext;
};
type::object_type type;
union_type via;
bool is_nil() const { return type == type::NIL; }
template <typename T>
T as() const;
template <typename T>
void convert(T& v) const;
template <typename T>
void convert(T* v) const;
object();
object(msgpack_object o);
template <typename T>
explicit object(const T& v);
template <typename T>
object(const T& v, zone& z);
// obsolete
template <typename T>
object(const T& v, zone* z);
template <typename T>
object& operator=(const T& v);
operator msgpack_object() const;
struct with_zone;
private:
struct implicit_type;
public:
implicit_type convert() const;
};
struct object_kv {
object key;
object val;
};
struct object::with_zone : object {
with_zone(msgpack::zone& zone) : zone(zone) { }
msgpack::zone& zone;

View File

@@ -0,0 +1,144 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed 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.
//
#ifndef MSGPACK_OBJECT_FORWARD_HPP
#define MSGPACK_OBJECT_FORWARD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/zone.hpp"
#include "msgpack/object.h"
#include <typeinfo>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace type {
enum object_type {
NIL = MSGPACK_OBJECT_NIL,
BOOLEAN = MSGPACK_OBJECT_BOOLEAN,
POSITIVE_INTEGER = MSGPACK_OBJECT_POSITIVE_INTEGER,
NEGATIVE_INTEGER = MSGPACK_OBJECT_NEGATIVE_INTEGER,
DOUBLE = MSGPACK_OBJECT_DOUBLE,
STR = MSGPACK_OBJECT_STR,
BIN = MSGPACK_OBJECT_BIN,
ARRAY = MSGPACK_OBJECT_ARRAY,
MAP = MSGPACK_OBJECT_MAP,
EXT = MSGPACK_OBJECT_EXT
};
}
struct object;
struct object_kv;
struct object_array {
uint32_t size;
object* ptr;
};
struct object_map {
uint32_t size;
object_kv* ptr;
};
struct object_str {
uint32_t size;
const char* ptr;
};
struct object_bin {
uint32_t size;
const char* ptr;
};
struct object_ext {
int8_t type() const { return ptr[0]; }
const char* data() const { return &ptr[1]; }
uint32_t size;
const char* ptr;
};
struct object {
union union_type {
bool boolean;
uint64_t u64;
int64_t i64;
double dec;
object_array array;
object_map map;
object_str str;
object_bin bin;
object_ext ext;
};
type::object_type type;
union_type via;
bool is_nil() const { return type == type::NIL; }
template <typename T>
T as() const;
template <typename T>
void convert(T& v) const;
template <typename T>
void convert(T* v) const;
object();
object(msgpack_object o);
template <typename T>
explicit object(const T& v);
template <typename T>
object(const T& v, zone& z);
// obsolete
template <typename T>
object(const T& v, zone* z);
template <typename T>
object& operator=(const T& v);
operator msgpack_object() const;
struct with_zone;
private:
struct implicit_type;
public:
implicit_type convert() const;
};
class type_error : public std::bad_cast { };
struct object_kv {
object key;
object val;
};
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_OBJECT_FORWARD_HPP

View File

@@ -0,0 +1,26 @@
/*
* MessagePack for C++ version switcher
*
* Copyright (C) 2014 KONDO Takatoshi
*
* Licensed 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.
*/
#ifndef MSGPACK_FORWARD_HPP
#define MSGPACK_FORWARD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/zone.hpp"
#include "msgpack/object_forward.hpp"
#include "msgpack/pack.hpp"
#endif // MSGPACK_FORWARD_HPP

View File

@@ -53,6 +53,7 @@ nobase_include_HEADERS = \
if ENABLE_CXX
nobase_include_HEADERS += \
../include/msgpack.hpp \
../include/msgpack_forward.hpp \
../include/msgpack/adaptor/bool.hpp \
../include/msgpack/adaptor/char_ptr.hpp \
../include/msgpack/adaptor/cpp11/array.hpp \
@@ -84,6 +85,7 @@ nobase_include_HEADERS += \
../include/msgpack/detail/cpp11_zone.hpp \
../include/msgpack/fbuffer.hpp \
../include/msgpack/object.hpp \
../include/msgpack/object_forward.hpp \
../include/msgpack/pack.hpp \
../include/msgpack/sbuffer.hpp \
../include/msgpack/type.hpp \