2017-10-28 16:31:07 +02:00
|
|
|
#ifndef REFLECTIVE_RAPIDJSON_CODE_JSON_SERIALIZATION_GENERATOR_H
|
|
|
|
#define REFLECTIVE_RAPIDJSON_CODE_JSON_SERIALIZATION_GENERATOR_H
|
|
|
|
|
|
|
|
#include "./codegenerator.h"
|
|
|
|
|
2017-11-06 15:31:21 +01:00
|
|
|
#include <c++utilities/application/argumentparser.h>
|
|
|
|
|
2017-10-28 16:31:07 +02:00
|
|
|
namespace ReflectiveRapidJSON {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief The JSONSerializationCodeGenerator class generates code for JSON (de)serialization
|
|
|
|
* of objects inheriting from an instantiation of JsonSerializable.
|
|
|
|
*/
|
|
|
|
class JsonSerializationCodeGenerator : public CodeGenerator {
|
|
|
|
public:
|
2017-11-06 15:31:21 +01:00
|
|
|
struct Options {
|
|
|
|
Options();
|
2018-02-02 18:21:04 +01:00
|
|
|
Options(const Options &other) = delete;
|
2017-11-11 12:37:24 +01:00
|
|
|
void appendTo(ApplicationUtilities::Argument *arg);
|
2017-10-28 16:31:07 +02:00
|
|
|
|
2017-11-11 12:37:24 +01:00
|
|
|
ApplicationUtilities::ConfigValueArgument additionalClassesArg;
|
|
|
|
ApplicationUtilities::ConfigValueArgument visibilityArg;
|
2017-11-06 15:31:21 +01:00
|
|
|
};
|
2017-10-28 16:31:07 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct RelevantClass {
|
2017-11-06 15:31:21 +01:00
|
|
|
explicit RelevantClass(std::string &&qualifiedName, clang::CXXRecordDecl *record);
|
2017-10-28 16:31:07 +02:00
|
|
|
|
|
|
|
std::string qualifiedName;
|
|
|
|
clang::CXXRecordDecl *record;
|
|
|
|
};
|
|
|
|
|
2017-11-06 15:31:21 +01:00
|
|
|
public:
|
|
|
|
JsonSerializationCodeGenerator(CodeFactory &factory, const Options &options);
|
|
|
|
|
|
|
|
void addDeclaration(clang::Decl *decl) override;
|
|
|
|
void generate(std::ostream &os) const override;
|
|
|
|
|
|
|
|
private:
|
2017-11-11 23:29:17 +01:00
|
|
|
std::string qualifiedNameIfRelevant(clang::CXXRecordDecl *record) const;
|
|
|
|
std::vector<RelevantClass> findRelevantClasses() const;
|
2017-11-06 21:25:45 +01:00
|
|
|
static std::vector<const RelevantClass *> findRelevantBaseClasses(
|
|
|
|
const RelevantClass &relevantClass, const std::vector<RelevantClass> &relevantBases);
|
2017-10-28 16:31:07 +02:00
|
|
|
|
2017-11-06 21:25:45 +01:00
|
|
|
std::vector<clang::CXXRecordDecl *> m_records;
|
2017-12-26 16:29:51 +01:00
|
|
|
std::vector<RelevantClass> m_adaptionRecords;
|
2017-11-06 15:31:21 +01:00
|
|
|
const Options &m_options;
|
2017-10-28 16:31:07 +02:00
|
|
|
};
|
|
|
|
|
2017-11-06 15:31:21 +01:00
|
|
|
inline JsonSerializationCodeGenerator::JsonSerializationCodeGenerator(CodeFactory &factory, const Options &options)
|
2017-10-28 16:31:07 +02:00
|
|
|
: CodeGenerator(factory)
|
2017-11-06 15:31:21 +01:00
|
|
|
, m_options(options)
|
2017-10-28 16:31:07 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-12-24 02:02:40 +01:00
|
|
|
inline void JsonSerializationCodeGenerator::Options::appendTo(ApplicationUtilities::Argument *arg)
|
|
|
|
{
|
|
|
|
arg->addSubArgument(&additionalClassesArg);
|
|
|
|
arg->addSubArgument(&visibilityArg);
|
|
|
|
}
|
|
|
|
|
2017-11-06 15:31:21 +01:00
|
|
|
inline JsonSerializationCodeGenerator::RelevantClass::RelevantClass(std::string &&qualifiedName, clang::CXXRecordDecl *record)
|
2017-10-28 16:31:07 +02:00
|
|
|
: qualifiedName(qualifiedName)
|
|
|
|
, record(record)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ReflectiveRapidJSON
|
|
|
|
|
|
|
|
#endif // REFLECTIVE_RAPIDJSON_CODE_JSON_SERIALIZATION_GENERATOR_H
|