cpp-restbed-server.model-header.mustache Maven / Gradle / Ivy
{{>licenseInfo}}
{{#models}}{{#model}}/*
* {{classname}}.h
*
* {{description}}
*/
#ifndef {{classname}}_H_
#define {{classname}}_H_
{{{defaultInclude}}}
{{#imports}}{{{this}}}
{{/imports}}
#include
#include
{{#hasEnums}}
#include
{{/hasEnums}}
#include
{{#interfaces}}
#include "{{{this}}}.h"
{{/interfaces}}
#include "helpers.h"
{{#modelNamespaceDeclarations}}
namespace {{this}} {
{{/modelNamespaceDeclarations}}
///
/// {{description}}
///
{{#circularReferences}}
class {{{this}}};
{{/circularReferences}}
class {{declspec}} {{classname}} {{#interfaces}}{{#-first}}:{{/-first}}{{^-first}},{{/-first}} public {{{this}}}{{/interfaces}}
{
public:
{{classname}}() = default;
explicit {{classname}}(boost::property_tree::ptree const& pt);
virtual ~{{classname}}() = default;
{{classname}}(const {{classname}}& other) = default; // copy constructor
{{classname}}({{classname}}&& other) noexcept = default; // move constructor
{{classname}}& operator=(const {{classname}}& other) = default; // copy assignment
{{classname}}& operator=({{classname}}&& other) noexcept = default; // move assignment
std::string toJsonString(bool prettyJson = false) const;
void fromJsonString(std::string const& jsonString);
boost::property_tree::ptree toPropertyTree() const;
void fromPropertyTree(boost::property_tree::ptree const& pt);
{{#isEnum}}
std::string toString() const;
void fromString(const std::string& str);
{{/isEnum}}
/////////////////////////////////////////////
/// {{classname}} members
{{#isEnum}}
{{{dataType}}} getEnumValue() const;
void setEnumValue(const {{{dataType}}}& val);
{{/isEnum}}
{{#vars}}
///
/// {{description}}
///
{{{dataType}}} {{getter}}() const;
void {{setter}}({{{dataType}}} value);
{{/vars}}
protected:
{{#isEnum}}
{{{dataType}}} m_{{{name}}}EnumValue;
{{/isEnum}}
{{#vars}}
{{^isContainer}}
{{^isModel}}
{{{dataType}}} m_{{name}} = {{{defaultValue}}};
{{/isModel}}
{{#isModel}}
{{{dataType}}} m_{{name}};
{{/isModel}}
{{/isContainer}}
{{#isContainer}}
{{{dataType}}} m_{{name}};
{{/isContainer}}
{{/vars}}
};
std::vector<{{classname}}> create{{classname}}VectorFromJsonString(const std::string& json);
template<>
inline boost::property_tree::ptree toPt<{{classname}}>(const {{classname}}& val) {
return val.toPropertyTree();
}
template<>
inline {{classname}} fromPt<{{classname}}>(const boost::property_tree::ptree& pt) {
{{classname}} ret;
ret.fromPropertyTree(pt);
return ret;
}
{{#modelNamespaceDeclarations}}
}
{{/modelNamespaceDeclarations}}
#endif /* {{classname}}_H_ */
{{/model}}
{{/models}}