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,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;