summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/Makefile.am2
-rw-r--r--cpp/type.hpp2
-rw-r--r--cpp/type/pair.hpp51
-rw-r--r--cpp/type/set.hpp56
4 files changed, 111 insertions, 0 deletions
diff --git a/cpp/Makefile.am b/cpp/Makefile.am
index b7bf069..edbeb28 100644
--- a/cpp/Makefile.am
+++ b/cpp/Makefile.am
@@ -18,7 +18,9 @@ nobase_include_HEADERS = \
msgpack/type/integer.hpp \
msgpack/type/map.hpp \
msgpack/type/nil.hpp \
+ msgpack/type/pair.hpp \
msgpack/type/raw.hpp \
+ msgpack/type/set.hpp \
msgpack/type/tuple.hpp \
msgpack/type/define.hpp
diff --git a/cpp/type.hpp b/cpp/type.hpp
index 8ffe3bf..2a6aa62 100644
--- a/cpp/type.hpp
+++ b/cpp/type.hpp
@@ -4,7 +4,9 @@
#include "msgpack/type/integer.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/tuple.hpp"
#include "msgpack/type/define.hpp"
diff --git a/cpp/type/pair.hpp b/cpp/type/pair.hpp
new file mode 100644
index 0000000..316b9fe
--- /dev/null
+++ b/cpp/type/pair.hpp
@@ -0,0 +1,51 @@
+//
+// 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_PAIR_HPP__
+#define MSGPACK_TYPE_PAIR_HPP__
+
+#include "msgpack/object.hpp"
+#include <utility>
+
+namespace msgpack {
+
+
+template <typename T1, typename T2>
+inline std::pair<T1, T2>& operator>> (object o, std::pair<T1, T2>& v)
+{
+ if(o.type != type::ARRAY) { throw type_error(); }
+ if(o.via.array.size != 2) { throw type_error(); }
+ o.via.array.ptr[0].convert(&v.first);
+ o.via.array.ptr[1].convert(&v.second);
+ return v;
+}
+
+
+template <typename Stream, typename T1, typename T2>
+inline packer<Stream>& operator<< (packer<Stream>& o, const std::pair<T1, T2>& v)
+{
+ o.pack_array(2);
+ o.pack(v.first);
+ o.pack(v.second);
+ return o;
+}
+
+
+} // namespace msgpack
+
+#endif /* msgpack/type/pair.hpp */
+
diff --git a/cpp/type/set.hpp b/cpp/type/set.hpp
new file mode 100644
index 0000000..3f1920a
--- /dev/null
+++ b/cpp/type/set.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_SET_HPP__
+#define MSGPACK_TYPE_SET_HPP__
+
+#include "msgpack/object.hpp"
+#include <set>
+
+namespace msgpack {
+
+
+template <typename T>
+inline std::set<T>& operator>> (object o, std::set<T>& v)
+{
+ if(o.type != type::ARRAY) { throw type_error(); }
+ object* p = o.via.array.ptr + o.via.array.size;
+ object* const pbegin = o.via.array.ptr;
+ while(p > pbegin) {
+ --p;
+ v.insert(p->as<T>());
+ }
+ return v;
+}
+
+
+template <typename Stream, typename T>
+inline packer<Stream>& operator<< (packer<Stream>& o, const std::set<T>& v)
+{
+ o.pack_array(v.size());
+ for(typename std::set<T>::const_iterator it(v.begin()), it_end(v.end());
+ it != it_end; ++it) {
+ o.pack(*it);
+ }
+ return o;
+}
+
+
+} // namespace msgpack
+
+#endif /* msgpack/type/set.hpp */
+