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();
|
2017-10-28 16:31:07 +02:00
|
|
|
|
2017-11-06 15:31:21 +01:00
|
|
|
ApplicationUtilities::Argument additionalClassesArg;
|
|
|
|
};
|
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;
|
|
|
|
std::string qualifiedNameIfRelevant(clang::CXXRecordDecl *record) const;
|
|
|
|
|
|
|
|
private:
|
2017-10-28 16:31:07 +02:00
|
|
|
std::vector<const RelevantClass *> findRelevantBaseClasses(const RelevantClass &relevantClass) const;
|
|
|
|
|
|
|
|
std::vector<RelevantClass> m_relevantClasses;
|
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-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
|