diff options
author | frsyuki <frsyuki@users.sourceforge.jp> | 2009-08-10 18:26:01 +0900 |
---|---|---|
committer | frsyuki <frsyuki@users.sourceforge.jp> | 2009-08-10 18:26:01 +0900 |
commit | 0627324da62922d332c75ec51525141329187beb (patch) | |
tree | 13f0157cff542d281e348cd091451976ba8b0413 /cpp | |
parent | 394331cd4ece745b9c5b5eb155560aaece8dc2bc (diff) | |
download | msgpack-python-0627324da62922d332c75ec51525141329187beb.tar.gz |
c++: rebuild type/*.hpp
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/Makefile.am | 8 | ||||
-rw-r--r-- | cpp/type.hpp | 8 | ||||
-rw-r--r-- | cpp/type/bool.hpp (renamed from cpp/type/boolean.hpp) | 4 | ||||
-rw-r--r-- | cpp/type/deque.hpp | 56 | ||||
-rw-r--r-- | cpp/type/float.hpp | 2 | ||||
-rw-r--r-- | cpp/type/int.hpp (renamed from cpp/type/integer.hpp) | 6 | ||||
-rw-r--r-- | cpp/type/list.hpp | 56 | ||||
-rw-r--r-- | cpp/type/pair.hpp | 1 | ||||
-rw-r--r-- | cpp/type/raw.hpp | 19 | ||||
-rw-r--r-- | cpp/type/string.hpp | 47 | ||||
-rw-r--r-- | cpp/type/vector.hpp (renamed from cpp/type/array.hpp) | 7 |
11 files changed, 177 insertions, 37 deletions
diff --git a/cpp/Makefile.am b/cpp/Makefile.am index edbeb28..45cc13c 100644 --- a/cpp/Makefile.am +++ b/cpp/Makefile.am @@ -12,15 +12,17 @@ nobase_include_HEADERS = \ msgpack/object.hpp \ msgpack/zone.hpp \ msgpack/type.hpp \ - msgpack/type/array.hpp \ - msgpack/type/boolean.hpp \ + msgpack/type/bool.hpp \ msgpack/type/float.hpp \ - msgpack/type/integer.hpp \ + msgpack/type/int.hpp \ + msgpack/type/list.hpp \ msgpack/type/map.hpp \ msgpack/type/nil.hpp \ msgpack/type/pair.hpp \ msgpack/type/raw.hpp \ msgpack/type/set.hpp \ + msgpack/type/string.hpp \ + msgpack/type/vector.hpp \ msgpack/type/tuple.hpp \ msgpack/type/define.hpp diff --git a/cpp/type.hpp b/cpp/type.hpp index 2a6aa62..2bd805d 100644 --- a/cpp/type.hpp +++ b/cpp/type.hpp @@ -1,12 +1,14 @@ -#include "msgpack/type/array.hpp" -#include "msgpack/type/boolean.hpp" +#include "msgpack/type/bool.hpp" #include "msgpack/type/float.hpp" -#include "msgpack/type/integer.hpp" +#include "msgpack/type/int.hpp" +#include "msgpack/type/list.hpp" #include "msgpack/type/map.hpp" #include "msgpack/type/nil.hpp" #include "msgpack/type/pair.hpp" #include "msgpack/type/raw.hpp" #include "msgpack/type/set.hpp" +#include "msgpack/type/string.hpp" +#include "msgpack/type/vector.hpp" #include "msgpack/type/tuple.hpp" #include "msgpack/type/define.hpp" diff --git a/cpp/type/boolean.hpp b/cpp/type/bool.hpp index 86bd697..f3ac6fa 100644 --- a/cpp/type/boolean.hpp +++ b/cpp/type/bool.hpp @@ -15,8 +15,8 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#ifndef MSGPACK_TYPE_BOOLEAN_HPP__ -#define MSGPACK_TYPE_BOOLEAN_HPP__ +#ifndef MSGPACK_TYPE_BOOL_HPP__ +#define MSGPACK_TYPE_BOOL_HPP__ #include "msgpack/object.hpp" #include <vector> diff --git a/cpp/type/deque.hpp b/cpp/type/deque.hpp new file mode 100644 index 0000000..d34d243 --- /dev/null +++ b/cpp/type/deque.hpp @@ -0,0 +1,56 @@ +// +// MessagePack for C++ static resolution routine +// +// Copyright (C) 2008-2009 FURUHASHI Sadayuki +// +// 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_TYPE_DEQUE_HPP__ +#define MSGPACK_TYPE_DEQUE_HPP__ + +#include "msgpack/object.hpp" +#include <deque> + +namespace msgpack { + + +template <typename T> +inline std::deque<T>& operator>> (object o, std::deque<T>& v) +{ + if(o.type != type::ARRAY) { throw type_error(); } + v.resize(o.via.array.size); + object* p = o.via.array.ptr; + object* const pend = o.via.array.ptr + o.via.array.size; + typename std::deque<T>::iterator it = v.begin(); + for(; p < pend; ++p, ++it) { + p->convert(&*it); + } + return v; +} + +template <typename Stream, typename T> +inline packer<Stream>& operator<< (packer<Stream>& o, const std::deque<T>& v) +{ + o.pack_array(v.size()); + for(typename std::deque<T>::const_iterator it(v.begin()), it_end(v.end()); + it != it_end; ++it) { + o.pack(*it); + } + return o; +} + + +} // namespace msgpack + +#endif /* msgpack/type/deque.hpp */ + diff --git a/cpp/type/float.hpp b/cpp/type/float.hpp index 108709d..390e340 100644 --- a/cpp/type/float.hpp +++ b/cpp/type/float.hpp @@ -34,7 +34,6 @@ inline float& operator>> (object o, float& v) return v; } - template <typename Stream> inline packer<Stream>& operator<< (packer<Stream>& o, const float& v) { @@ -50,7 +49,6 @@ inline double& operator>> (object o, double& v) return v; } - template <typename Stream> inline packer<Stream>& operator<< (packer<Stream>& o, const double& v) { diff --git a/cpp/type/integer.hpp b/cpp/type/int.hpp index ecb7b89..8fdc386 100644 --- a/cpp/type/integer.hpp +++ b/cpp/type/int.hpp @@ -15,8 +15,8 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#ifndef MSGPACK_TYPE_INTEGER_HPP__ -#define MSGPACK_TYPE_INTEGER_HPP__ +#ifndef MSGPACK_TYPE_INT_HPP__ +#define MSGPACK_TYPE_INT_HPP__ #include "msgpack/object.hpp" #include <limits> @@ -143,5 +143,5 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const unsigned long long& } // namespace msgpack -#endif /* msgpack/type/integer.hpp */ +#endif /* msgpack/type/int.hpp */ diff --git a/cpp/type/list.hpp b/cpp/type/list.hpp new file mode 100644 index 0000000..6ecc02f --- /dev/null +++ b/cpp/type/list.hpp @@ -0,0 +1,56 @@ +// +// MessagePack for C++ static resolution routine +// +// Copyright (C) 2008-2009 FURUHASHI Sadayuki +// +// 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_TYPE_LIST_HPP__ +#define MSGPACK_TYPE_LIST_HPP__ + +#include "msgpack/object.hpp" +#include <list> + +namespace msgpack { + + +template <typename T> +inline std::list<T>& operator>> (object o, std::list<T>& v) +{ + if(o.type != type::ARRAY) { throw type_error(); } + v.resize(o.via.array.size); + object* p = o.via.array.ptr; + object* const pend = o.via.array.ptr + o.via.array.size; + typename std::list<T>::iterator it = v.begin(); + for(; p < pend; ++p, ++it) { + p->convert(&*it); + } + return v; +} + +template <typename Stream, typename T> +inline packer<Stream>& operator<< (packer<Stream>& o, const std::list<T>& v) +{ + o.pack_array(v.size()); + for(typename std::list<T>::const_iterator it(v.begin()), it_end(v.end()); + it != it_end; ++it) { + o.pack(*it); + } + return o; +} + + +} // namespace msgpack + +#endif /* msgpack/type/list.hpp */ + diff --git a/cpp/type/pair.hpp b/cpp/type/pair.hpp index 316b9fe..ba72c1f 100644 --- a/cpp/type/pair.hpp +++ b/cpp/type/pair.hpp @@ -34,7 +34,6 @@ inline std::pair<T1, T2>& operator>> (object o, std::pair<T1, T2>& v) return v; } - template <typename Stream, typename T1, typename T2> inline packer<Stream>& operator<< (packer<Stream>& o, const std::pair<T1, T2>& v) { diff --git a/cpp/type/raw.hpp b/cpp/type/raw.hpp index b6ace3f..8c68aba 100644 --- a/cpp/type/raw.hpp +++ b/cpp/type/raw.hpp @@ -69,16 +69,6 @@ inline type::raw_ref& operator>> (object o, type::raw_ref& v) return v; } - -inline std::string& operator>> (object o, std::string& v) -{ - type::raw_ref r; - o >> r; - v.assign(r.ptr, r.size); - return v; -} - - template <typename Stream> inline packer<Stream>& operator<< (packer<Stream>& o, const type::raw_ref& v) { @@ -88,15 +78,6 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const type::raw_ref& v) } -template <typename Stream> -inline packer<Stream>& operator<< (packer<Stream>& o, const std::string& v) -{ - o.pack_raw(v.size()); - o.pack_raw_body(v.data(), v.size()); - return o; -} - - } // namespace msgpack #endif /* msgpack/type/raw.hpp */ diff --git a/cpp/type/string.hpp b/cpp/type/string.hpp new file mode 100644 index 0000000..2a23058 --- /dev/null +++ b/cpp/type/string.hpp @@ -0,0 +1,47 @@ +// +// MessagePack for C++ static resolution routine +// +// Copyright (C) 2008-2009 FURUHASHI Sadayuki +// +// 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_TYPE_STRING_HPP__ +#define MSGPACK_TYPE_STRING_HPP__ + +#include "msgpack/object.hpp" +#include <string> + +namespace msgpack { + + +inline std::string& operator>> (object o, std::string& v) +{ + type::raw_ref r; + o >> r; + v.assign(r.ptr, r.size); + return v; +} + +template <typename Stream> +inline packer<Stream>& operator<< (packer<Stream>& o, const std::string& v) +{ + o.pack_raw(v.size()); + o.pack_raw_body(v.data(), v.size()); + return o; +} + + +} // namespace msgpack + +#endif /* msgpack/type/string.hpp */ + diff --git a/cpp/type/array.hpp b/cpp/type/vector.hpp index 5b80dc1..754cdc0 100644 --- a/cpp/type/array.hpp +++ b/cpp/type/vector.hpp @@ -15,8 +15,8 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#ifndef MSGPACK_TYPE_ARRAY_HPP__ -#define MSGPACK_TYPE_ARRAY_HPP__ +#ifndef MSGPACK_TYPE_VECTOR_HPP__ +#define MSGPACK_TYPE_VECTOR_HPP__ #include "msgpack/object.hpp" #include <vector> @@ -38,7 +38,6 @@ inline std::vector<T>& operator>> (object o, std::vector<T>& v) return v; } - template <typename Stream, typename T> inline packer<Stream>& operator<< (packer<Stream>& o, const std::vector<T>& v) { @@ -53,5 +52,5 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const std::vector<T>& v) } // namespace msgpack -#endif /* msgpack/type/array.hpp */ +#endif /* msgpack/type/vector.hpp */ |