mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-13 22:50:19 +02:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user