Created
April 30, 2010 00:54
-
-
Save frsyuki/384544 to your computer and use it in GitHub Desktop.
MessagePack dynamic class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <msgpack.hpp> | |
#include <tr1/memory> | |
#include <iostream> | |
class dynamic { | |
public: | |
typedef std::tr1::shared_ptr<msgpack::zone> shared_zone; | |
dynamic() { } | |
dynamic(msgpack::object obj) : | |
m_obj(obj) { } | |
dynamic(msgpack::object obj, shared_zone z) : | |
m_obj(obj), m_zone(z) { } | |
template <typename T> | |
dynamic(const T& v, shared_zone z = shared_zone(new msgpack::zone())) : | |
m_obj(v, z.get()), m_zone(z) { } | |
operator msgpack::object() const { return m_obj; } | |
msgpack::object* operator-> () { return &m_obj; } | |
const msgpack::object* operator-> () const { return &m_obj; } | |
msgpack::object& operator* () { return m_obj; } | |
const msgpack::object& operator* () const { return m_obj; } | |
shared_zone zone() { return m_zone; }; | |
private: | |
msgpack::object m_obj; | |
shared_zone m_zone; | |
}; | |
int main(void) | |
{ | |
std::vector<std::string> vec; | |
vec.push_back("hello"); | |
vec.push_back("dynamic"); | |
dynamic dy(vec); | |
std::cout << *dy << std::endl; //=> ["hello", "dynamic"] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment