Rapidjson: How to Get() an enumerator

194 Views Asked by At

I am trying to implement a Exploding Kittens card game, where the type of the card is an enumerator class.

enum class card_type
{
    Kitten,
    Bomb,
    ...
}

and use it as a private variable card_type* value. Afterwards, as I pass the events as JSON queries, I would like to get the value from JSON using RapidJSON.

static serializable_value<T>* from_json(const rapidjson::Value& json) 
{
    if (json.HasMember("value")) {
        T val = json["value"].Get<T>();
        return new serializable_value<T>(val);
    }
    return nullptr;
}

and call it as

serializable_value<card_type>::from_json(json["value"].GetObject())

where serializable_value is just a helper class for handling JSON.

This code works perfectly fine, if I don't use enum class, but rather use int* value and serializable_value<int>::from_json(json["value"].GetObject())

How to handle a enum class which should be nothing more, but an unsigned int?

Also here a full stack trace:

error: no member named 'Get' in 'rapidjson::internal::TypeHelper<rapidjson::GenericValue<rapidjson::UTF8<>>, card_type>'
    T Get() const { return internal::TypeHelper<ValueType, T>::Get(*this); }
                                                               ^
/src/common/game_state/cards/../../serialization/serializable_value.h:52:35: note: in instantiation of function template specialization 'rapidjson::GenericValue<rapidjson::UTF8<>>::Get<card_type>' requested here
            T val = json["value"].Get<T>();
                                  ^
/src/common/game_state/cards/card.cpp:35:80: note: in instantiation of member function 'serializable_value<card_type>::from_json' requested here
        return new card(json["id"].GetString(), serializable_value<card_type>::from_json(json["value"].GetObject()));
0

There are 0 best solutions below