mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-14 06:55:50 +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,4 +1,4 @@
|
||||
#include "msgpack.hpp"
|
||||
#include <msgpack_fwd.hpp>
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
@@ -15,6 +15,31 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
class TestEnumMemberClass
|
||||
{
|
||||
public:
|
||||
TestEnumMemberClass()
|
||||
: t1(STATE_A), t2(STATE_B), t3(STATE_C) {}
|
||||
|
||||
enum TestEnumType {
|
||||
STATE_INVALID = 0,
|
||||
STATE_A = 1,
|
||||
STATE_B = 2,
|
||||
STATE_C = 3
|
||||
};
|
||||
TestEnumType t1;
|
||||
TestEnumType t2;
|
||||
TestEnumType t3;
|
||||
|
||||
MSGPACK_DEFINE(t1, t2, t3);
|
||||
};
|
||||
|
||||
MSGPACK_ADD_ENUM(TestEnumMemberClass::TestEnumType);
|
||||
|
||||
#include <msgpack.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const unsigned int kLoop = 1000;
|
||||
@@ -488,27 +513,6 @@ TEST(MSGPACK_USER_DEFINED, simple_buffer_class_new_to_old)
|
||||
}
|
||||
}
|
||||
|
||||
class TestEnumMemberClass
|
||||
{
|
||||
public:
|
||||
TestEnumMemberClass()
|
||||
: t1(STATE_A), t2(STATE_B), t3(STATE_C) {}
|
||||
|
||||
enum TestEnumType {
|
||||
STATE_INVALID = 0,
|
||||
STATE_A = 1,
|
||||
STATE_B = 2,
|
||||
STATE_C = 3
|
||||
};
|
||||
TestEnumType t1;
|
||||
TestEnumType t2;
|
||||
TestEnumType t3;
|
||||
|
||||
MSGPACK_DEFINE(t1, t2, t3);
|
||||
};
|
||||
|
||||
MSGPACK_ADD_ENUM(TestEnumMemberClass::TestEnumType);
|
||||
|
||||
TEST(MSGPACK_USER_DEFINED, simple_buffer_enum_member)
|
||||
{
|
||||
TestEnumMemberClass val1;
|
||||
|
Reference in New Issue
Block a user