Chlumsky/json-cpp-gen

Type aliases in configuration

Chlumsky opened this issue · 3 comments

Add a section to the configuration file for "typedefs", (e.g. artery::MemInt = std::ptrdiff_t). This is especially useful before #9 is implemented, but even then it may be good for types included from libraries or conditional aliases.

Added to configuration as typeAliases map with key being name of alias and value an existing type. The current implementation (546eb13) works for non-template types (e.g. "mynamespace::String": "std::string") and template instances (e.g. "StringVector": "std::vector<std::string>") but cannot create aliases for templates (e.g. "List": "std::vector"). This needs to be added but the implementation is non-trivial.

Another issue is code duplication. Assuming we alias String as std::string, then a structure containing

struct Foo {
    String aString;
    std::string bString;
};

works fine, with parseStdString being used for both members. However, just changing it to

struct Foo {
    std::vector<String> a;
    std::vector<std::string> b;
};

results in two distinct but equivalent parse functions. This could be solved by overriding actualType() of template types to create a new type instance for the actual type of its template arguments with the help of TemplateInstanceCache.

The code duplication issue has been fixed in c748af6.

Support for template container types added in f02e905.