Rename Reflector -> JsonReflector

So helper methods for other applications of reflections
would go into a separate namespace to prevent conflicts.
This commit is contained in:
Martchus 2017-11-02 23:35:56 +01:00
parent fdadb17c04
commit daf1a8602c
6 changed files with 45 additions and 45 deletions

View File

@ -47,9 +47,9 @@ void JsonSerializationCodeGenerator::generate(ostream &os) const
return;
}
// put everything into namespace ReflectiveRapidJSON::Reflector
// put everything into namespace ReflectiveRapidJSON::JsonReflector
os << "namespace ReflectiveRapidJSON {\n"
"namespace Reflector {\n\n";
"namespace JsonReflector {\n\n";
// add push and pull functions for each class, for an example of the resulting
// output, see ../lib/tests/jsonserializable.cpp (code under comment "pretend serialization code...")
@ -101,8 +101,8 @@ void JsonSerializationCodeGenerator::generate(ostream &os) const
os << "}\n\n";
}
// close namespace ReflectiveRapidJSON::Reflector
os << "} // namespace Reflector\n"
// close namespace ReflectiveRapidJSON::JsonReflector
os << "} // namespace JsonReflector\n"
"} // namespace ReflectiveRapidJSON\n";
}

View File

@ -1,5 +1,5 @@
namespace ReflectiveRapidJSON {
namespace Reflector {
namespace JsonReflector {
// define code for (de)serializing TestNamespace1::Person objects
template <> inline void push<::TestNamespace1::Person>(const ::TestNamespace1::Person &reflectable, ::RAPIDJSON_NAMESPACE::Value::Object &value, ::RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
@ -27,5 +27,5 @@ template <> inline void pull<::TestNamespace1::Person>(::TestNamespace1::Person
}
}
} // namespace Reflector
} // namespace JsonReflector
} // namespace ReflectiveRapidJSON

View File

@ -18,7 +18,7 @@
#include <boost/hana.hpp>
namespace ReflectiveRapidJSON {
namespace Reflector {
namespace JsonReflector {
// define functions to "push" values to a RapidJSON array or object
@ -59,7 +59,7 @@ void pull(Type &reflectable, const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_N
});
}
} // namespace Reflector
} // namespace JsonReflector
} // namespace ReflectiveRapidJSON
#endif // REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_BOOST_HANA_H

View File

@ -48,7 +48,7 @@ inline RAPIDJSON_NAMESPACE::Document parseJsonDocFromString(const char *json, st
return document;
}
namespace Reflector {
namespace JsonReflector {
// define functions to "push" values to a RapidJSON array or object
@ -143,14 +143,14 @@ template <class Tuple, std::size_t N> struct TuplePushHelper {
static void push(const Tuple &tuple, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
{
TuplePushHelper<Tuple, N - 1>::push(tuple, value, allocator);
Reflector::push(std::get<N - 1>(tuple), value, allocator);
JsonReflector::push(std::get<N - 1>(tuple), value, allocator);
}
};
template <class Tuple> struct TuplePushHelper<Tuple, 1> {
static void push(const Tuple &tuple, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
{
Reflector::push(std::get<0>(tuple), value, allocator);
JsonReflector::push(std::get<0>(tuple), value, allocator);
}
};
} // namespace Detail
@ -517,14 +517,14 @@ template <class Tuple, std::size_t N> struct TuplePullHelper {
static void pull(Tuple &tuple, const RAPIDJSON_NAMESPACE::Value::Array &value, JsonDeserializationErrors *errors)
{
TuplePullHelper<Tuple, N - 1>::pull(tuple, value, errors);
Reflector::pull(std::get<N - 1>(tuple), value[N - 1], errors);
JsonReflector::pull(std::get<N - 1>(tuple), value[N - 1], errors);
}
};
template <class Tuple> struct TuplePullHelper<Tuple, 1> {
static void pull(Tuple &tuple, const RAPIDJSON_NAMESPACE::Value::Array &value, JsonDeserializationErrors *errors)
{
Reflector::pull(std::get<0>(tuple), value[0], errors);
JsonReflector::pull(std::get<0>(tuple), value[0], errors);
}
};
} // namespace Detail
@ -716,7 +716,7 @@ template <typename Type> Type fromJson(const std::string &json)
return fromJson<Type>(json.data(), json.size());
}
} // namespace Reflector
} // namespace JsonReflector
} // namespace ReflectiveRapidJSON
#endif // REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_H

View File

@ -37,7 +37,7 @@ template <typename Type> struct JsonSerializable {
*/
template <typename Type> void JsonSerializable<Type>::push(RAPIDJSON_NAMESPACE::Value &container)
{
return Reflector::push<Type>(*this, container);
return JsonReflector::push<Type>(*this, container);
}
/*!
@ -45,7 +45,7 @@ template <typename Type> void JsonSerializable<Type>::push(RAPIDJSON_NAMESPACE::
*/
template <typename Type> void JsonSerializable<Type>::push(RAPIDJSON_NAMESPACE::Value &container, const char *name)
{
return Reflector::push<Type>(*this, name, container);
return JsonReflector::push<Type>(*this, name, container);
}
/*!
@ -54,7 +54,7 @@ template <typename Type> void JsonSerializable<Type>::push(RAPIDJSON_NAMESPACE::
*/
template <typename Type> RAPIDJSON_NAMESPACE::StringBuffer JsonSerializable<Type>::toJson() const
{
return Reflector::toJson<Type>(static_cast<const Type &>(*this));
return JsonReflector::toJson<Type>(static_cast<const Type &>(*this));
}
/*!
@ -62,7 +62,7 @@ template <typename Type> RAPIDJSON_NAMESPACE::StringBuffer JsonSerializable<Type
*/
template <typename Type> Type JsonSerializable<Type>::fromJson(const char *json, std::size_t jsonSize, JsonDeserializationErrors *errors)
{
return Reflector::fromJson<Type>(json, jsonSize, errors);
return JsonReflector::fromJson<Type>(json, jsonSize, errors);
}
/*!
@ -70,7 +70,7 @@ template <typename Type> Type JsonSerializable<Type>::fromJson(const char *json,
*/
template <typename Type> Type JsonSerializable<Type>::fromJson(const char *json, JsonDeserializationErrors *errors)
{
return Reflector::fromJson<Type>(json, std::strlen(json), errors);
return JsonReflector::fromJson<Type>(json, std::strlen(json), errors);
}
/*!
@ -78,7 +78,7 @@ template <typename Type> Type JsonSerializable<Type>::fromJson(const char *json,
*/
template <typename Type> Type JsonSerializable<Type>::fromJson(const std::string &json, JsonDeserializationErrors *errors)
{
return Reflector::fromJson<Type>(json.data(), json.size(), errors);
return JsonReflector::fromJson<Type>(json.data(), json.size(), errors);
}
/*!

View File

@ -63,7 +63,7 @@ enum class SomeEnumClass {
// pretend serialization code for structs has been generated
namespace ReflectiveRapidJSON {
namespace Reflector {
namespace JsonReflector {
template <> inline void push<TestObject>(const TestObject &reflectable, Value::Object &value, Document::AllocatorType &allocator)
{
@ -134,9 +134,9 @@ inline void pull<NestingArray>(NestingArray &reflectable, const GenericValue<UTF
}
}
} // namespace Reflector
} // namespace JsonReflector
// namespace Reflector
// namespace JsonReflector
} // namespace ReflectiveRapidJSON
/// \endcond
@ -196,23 +196,23 @@ void JsonReflectorTests::testSerializePrimitives()
// string
const string foo("foo"); // musn't be destroyed until JSON is actually written
Reflector::push<string>(foo, array, alloc);
Reflector::push<const char *>("bar", array, alloc);
JsonReflector::push<string>(foo, array, alloc);
JsonReflector::push<const char *>("bar", array, alloc);
// number
Reflector::push<int>(25, array, alloc);
Reflector::push<double>(12.5, array, alloc);
JsonReflector::push<int>(25, array, alloc);
JsonReflector::push<double>(12.5, array, alloc);
// enum
Reflector::push<SomeEnum>(SomeEnumItem2, array, alloc);
Reflector::push<SomeEnumClass>(SomeEnumClass::Item2, array, alloc);
Reflector::push<SomeEnumClass>(SomeEnumClass::Item3, array, alloc);
JsonReflector::push<SomeEnum>(SomeEnumItem2, array, alloc);
JsonReflector::push<SomeEnumClass>(SomeEnumClass::Item2, array, alloc);
JsonReflector::push<SomeEnumClass>(SomeEnumClass::Item3, array, alloc);
// array
Reflector::push<vector<const char *>>({ "foo1", "bar1" }, array, alloc);
Reflector::push<list<const char *>>({ "foo2", "bar2" }, array, alloc);
Reflector::push<initializer_list<const char *>>({ "foo3", "bar3" }, array, alloc);
Reflector::push<tuple<int, double>>(make_tuple(2, 413.0), array, alloc);
JsonReflector::push<vector<const char *>>({ "foo1", "bar1" }, array, alloc);
JsonReflector::push<list<const char *>>({ "foo2", "bar2" }, array, alloc);
JsonReflector::push<initializer_list<const char *>>({ "foo3", "bar3" }, array, alloc);
JsonReflector::push<tuple<int, double>>(make_tuple(2, 413.0), array, alloc);
// boolean
Reflector::push<bool>(true, array, alloc);
Reflector::push<bool>(false, array, alloc);
JsonReflector::push<bool>(true, array, alloc);
JsonReflector::push<bool>(false, array, alloc);
StringBuffer strbuf;
Writer<StringBuffer> jsonWriter(strbuf);
@ -278,13 +278,13 @@ void JsonReflectorTests::testDeserializePrimitives()
float float1 = 0.0;
double double1 = 0.0;
JsonDeserializationErrors errors;
Reflector::pull(str1, array, &errors);
Reflector::pull(int1, array, &errors);
Reflector::pull(float1, array, &errors);
Reflector::pull(str2, array, &errors);
Reflector::pull(bool1, array, &errors);
Reflector::pull(double1, array, &errors);
Reflector::pull(bool2, array, &errors);
JsonReflector::pull(str1, array, &errors);
JsonReflector::pull(int1, array, &errors);
JsonReflector::pull(float1, array, &errors);
JsonReflector::pull(str2, array, &errors);
JsonReflector::pull(bool1, array, &errors);
JsonReflector::pull(double1, array, &errors);
JsonReflector::pull(bool2, array, &errors);
CPPUNIT_ASSERT_EQUAL(0_st, errors.size());
CPPUNIT_ASSERT_EQUAL("a"s, str1);
@ -297,7 +297,7 @@ void JsonReflectorTests::testDeserializePrimitives()
// deserialize primitives as tuple
tuple<string, int, float, string, bool, double, bool> arrayAsTuple;
Reflector::pull(arrayAsTuple, doc, &errors);
JsonReflector::pull(arrayAsTuple, doc, &errors);
CPPUNIT_ASSERT_EQUAL(0_st, errors.size());
CPPUNIT_ASSERT_EQUAL("a"s, get<0>(arrayAsTuple));
CPPUNIT_ASSERT_EQUAL(5, get<1>(arrayAsTuple));
@ -307,7 +307,7 @@ void JsonReflectorTests::testDeserializePrimitives()
CPPUNIT_ASSERT_EQUAL(4.125, get<5>(arrayAsTuple));
CPPUNIT_ASSERT_EQUAL(false, get<6>(arrayAsTuple));
tuple<string, int> anotherTuple;
Reflector::pull(anotherTuple, doc, &errors);
JsonReflector::pull(anotherTuple, doc, &errors);
CPPUNIT_ASSERT_EQUAL(1_st, errors.size());
CPPUNIT_ASSERT_EQUAL(JsonDeserializationErrorKind::ArraySizeMismatch, errors.front().kind);
}