Skip to content

Commit

Permalink
Update traits.h
Browse files Browse the repository at this point in the history
  • Loading branch information
prince-chrismc authored May 16, 2020
1 parent c1cfb73 commit c5663f5
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions include/jwt-cpp/traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@

namespace jwt {
namespace json {
enum class type {
null,
boolean,
integer,
number,
string,
array,
object,
};

template<typename value,
enum type,
typename object,
typename array,
typename string,
typename number,
typename integer,
typename boolean,
/*typename null = nullptr*/>
struct traits {
Expand All @@ -18,18 +28,32 @@ namespace jwt {
using string = string;
using number = number;
using boolean = boolean;
using integer = integer;
// using null = null;
};
}
}

struct picojson_traits : traits<
picojson::value,
picojson::type, // TBA
picojson::object,
picojson::array,
std::string,
double,
int64_t,
bool> {
static jwt::json::type get_type(const traits::value& val) {
using jwt::json::type;

if (val.is<picojson::null>()) return type::null;
else if (val.is<bool>()) return type::boolean;
else if (val.is<int64_t>()) return type::integer;
else if (val.is<double>()) return type::number;
else if (val.is<std::string>()) return type::string;
else if (val.is<picojson::array>()) return type::array;
else if (val.is<picojson::object>()) return type::object;
else throw std::logic_error("invalid type");

}
};

0 comments on commit c5663f5

Please sign in to comment.