etherealjoy 12f3661d6f Qt5cpp plug memleaks (#7695)
* Small fixes to prevent crash when empty json body is provided.

* WIP: plug mem-leaks

* fixup: add the QJsonObject instance in toJsonArray instead of pointer

* fixup: simplify toJsonMap

Actually the original solution is incomplete, because "innerType" maps to a single C++ type. Have a look at Qt's builtin QJsonObject::fromVariantMap.

* Updates to antis81:patch-1 after tests.

* update to remove string allocation

* Updates due to address of members being passed

* Update PetStore Examples

* Small updates for Header includes
2018-03-07 20:54:40 +08:00

37 lines
823 B
Plaintext

{{>licenseInfo}}
#ifndef ModelFactory_H_
#define ModelFactory_H_
#include "{{prefix}}Object.h"
{{#models}}{{#model}}
#include "{{classname}}.h"{{/model}}{{/models}}
{{#cppNamespaceDeclarations}}
namespace {{this}} {
{{/cppNamespaceDeclarations}}
inline void* create(QString type) {
{{#models}}{{#model}}if(QString("{{classname}}").compare(type) == 0) {
return new {{classname}}();
}
{{/model}}{{/models}}
return nullptr;
}
inline void* create(QString json, QString type) {
if(type.startsWith("QString")) {
return new QString();
}
auto val = static_cast<{{prefix}}Object*>(create(type));
if(val != nullptr) {
return val->fromJson(json);
}
return nullptr;
}
{{#cppNamespaceDeclarations}}
}
{{/cppNamespaceDeclarations}}
#endif /* ModelFactory_H_ */