enum support had been incomplete.
This fix made enum support complete.

Replaced int with auto on c++11 scoped enum.
Replaced template specializations with function overloads on operator<< and operator>> for enum.

enum can convert to object with and without zone.

When you want to adapt enum, you need to write as follows:

// NOT msgpack.hpp

enum yourenum {
    elem
};

MSGPACK_ADD_ENUM(yourenum);

// msgpack.hpp should be included after MSGPACK_ADD_ENUM(...)

int main() {
    msgpack::object obj(yourenum::elem);
}
This commit is contained in:
Takatoshi Kondo
2015-01-31 21:59:21 +09:00
parent 978e6b9057
commit c4fb47c00d
8 changed files with 269 additions and 76 deletions

View File

@@ -1,6 +1,24 @@
#include <msgpack.hpp>
#include <msgpack_fwd.hpp>
#include <gtest/gtest.h>
class enum_member {
public:
enum_member() : flag(A) { }
enum flags_t {
A = 0,
B = 1
};
flags_t flag;
MSGPACK_DEFINE(flag);
};
MSGPACK_ADD_ENUM(enum_member::flags_t);
#include <msgpack.hpp>
class compatibility {
public:
compatibility() : str1("default"), str2("default") { }
@@ -43,23 +61,6 @@ TEST(convert, compatibility_more)
EXPECT_EQ("mpio", to.str2);
}
class enum_member {
public:
enum_member() : flag(A) { }
enum flags_t {
A = 0,
B = 1
};
flags_t flag;
MSGPACK_DEFINE(flag);
};
MSGPACK_ADD_ENUM(enum_member::flags_t);
TEST(convert, enum_member)
{
enum_member src;
@@ -73,4 +74,3 @@ TEST(convert, enum_member)
EXPECT_EQ(enum_member::B, to.flag);
}