cpp-rest-sdk-client.model-source.mustache Maven / Gradle / Ivy
{{>licenseInfo}}
{{#models}}{{#model}}
#include "{{classFilename}}.h"
{{#modelNamespaceDeclarations}}
namespace {{this}} {
{{/modelNamespaceDeclarations}}
{{#isEnum}}
{{classname}}::{{classname}}()
{
}
{{classname}}::~{{classname}}()
{
}
void {{classname}}::validate()
{
// TODO: implement validation
}
web::json::value {{classname}}::toJson() const
{
web::json::value val = web::json::value::object();
{{#allowableValues}}{{#enumVars}}
if (m_value == e{{classname}}::{{classname}}_{{name}}) val = web::json::value::string(U({{{value}}}));{{/enumVars}}{{/allowableValues}}
return val;
}
bool {{classname}}::fromJson(const web::json::value& val)
{
auto s = val.as_string();
{{#allowableValues}}{{#enumVars}}
if (s == utility::conversions::to_string_t({{{value}}})) m_value = e{{classname}}::{{classname}}_{{name}};{{/enumVars}}{{/allowableValues}}
return true;
}
void {{classname}}::toMultipart(std::shared_ptr multipart, const utility::string_t& prefix) const
{
utility::string_t namePrefix = prefix;
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t("."))
{
namePrefix += utility::conversions::to_string_t(".");
}
utility::string_t s;
{{#allowableValues}}{{#enumVars}}
if (m_value == e{{classname}}::{{classname}}_{{name}}) s = utility::conversions::to_string_t({{{value}}});{{/enumVars}}{{/allowableValues}}
multipart->add(ModelBase::toHttpContent(namePrefix, s));
}
bool {{classname}}::fromMultiPart(std::shared_ptr multipart, const utility::string_t& prefix)
{
bool ok = true;
utility::string_t namePrefix = prefix;
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t("."))
{
namePrefix += utility::conversions::to_string_t(".");
}
{
utility::string_t s;
ok = ModelBase::fromHttpContent(multipart->getContent(namePrefix), s);
e{{classname}} v;
{{#allowableValues}}{{#enumVars}}
if (s == utility::conversions::to_string_t({{{value}}})) v = e{{classname}}::{{classname}}_{{name}};{{/enumVars}}{{/allowableValues}}
setValue(v);
}
return ok;
}
{{classname}}::e{{classname}} {{classname}}::getValue() const
{
return m_value;
}
void {{classname}}::setValue({{classname}}::e{{classname}} const value)
{
m_value = value;
}
{{/isEnum}}
{{^isEnum}}
{{classname}}::{{classname}}()
{
{{#vars}}
{{^isInherited}}
{{^isContainer}}
{{#isPrimitiveType}}
m_{{name}} = {{{defaultValue}}};
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isString}}
m_{{name}} = {{{defaultValue}}};
{{/isString}}
{{#isDateTime}}
m_{{name}} = {{{defaultValue}}};
{{/isDateTime}}
{{/isPrimitiveType}}
{{/isContainer}}
m_{{name}}IsSet = false;
{{/isInherited}}
{{/vars}}
}
{{classname}}::~{{classname}}()
{
}
void {{classname}}::validate()
{
// TODO: implement validation
}
web::json::value {{classname}}::toJson() const
{
{{#parent}}
web::json::value val = this->{{{parent}}}::toJson();{{/parent}}
{{^parent}}
web::json::value val = web::json::value::object();
{{/parent}}
{{#vars}}{{^isInherited}}
if(m_{{name}}IsSet)
{
val[utility::conversions::to_string_t("{{baseName}}")] = ModelBase::toJson(m_{{name}});
}{{/isInherited}}{{/vars}}
return val;
}
bool {{classname}}::fromJson(const web::json::value& val)
{
bool ok = true;
{{#parent}}
ok &= this->{{{parent}}}::fromJson(val);
{{/parent}}
{{#vars}}{{^isInherited}}
if(val.has_field(utility::conversions::to_string_t("{{baseName}}")))
{
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t("{{baseName}}"));
if(!fieldValue.is_null())
{
{{{dataType}}} refVal_{{baseName}};
ok &= ModelBase::fromJson(fieldValue, refVal_{{baseName}});
{{setter}}(refVal_{{baseName}});
}
}{{/isInherited}}{{/vars}}
return ok;
}
void {{classname}}::toMultipart(std::shared_ptr multipart, const utility::string_t& prefix) const
{
utility::string_t namePrefix = prefix;
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t("."))
{
namePrefix += utility::conversions::to_string_t(".");
}
{{#vars}}
if(m_{{name}}IsSet)
{
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("{{baseName}}"), m_{{name}}));
}
{{/vars}}
}
bool {{classname}}::fromMultiPart(std::shared_ptr multipart, const utility::string_t& prefix)
{
bool ok = true;
utility::string_t namePrefix = prefix;
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t("."))
{
namePrefix += utility::conversions::to_string_t(".");
}
{{#vars}}
if(multipart->hasContent(utility::conversions::to_string_t("{{baseName}}")))
{
{{{dataType}}} refVal_{{baseName}};
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t("{{baseName}}")), refVal_{{baseName}} );
{{setter}}(refVal_{{baseName}});
}
{{/vars}}
return ok;
}
{{#vars}}
{{^isInherited}}
{{#isContainer}}
{{{dataType}}}& {{classname}}::{{getter}}()
{
return m_{{name}};
}
{{/isContainer}}
{{^isContainer}}
{{{dataType}}} {{classname}}::{{getter}}() const
{
return m_{{name}};
}
{{/isContainer}}
{{#isPrimitiveType}}
void {{classname}}::{{setter}}({{{dataType}}} value)
{{/isPrimitiveType}}
{{^isPrimitiveType}}
void {{classname}}::{{setter}}(const {{{dataType}}}& value)
{{/isPrimitiveType}}
{
m_{{name}} = value;
m_{{name}}IsSet = true;
}
bool {{classname}}::{{nameInCamelCase}}IsSet() const
{
return m_{{name}}IsSet;
}
void {{classname}}::unset{{name}}()
{
m_{{name}}IsSet = false;
}
{{/isInherited}}
{{/vars}}
{{/isEnum}}
{{#modelNamespaceDeclarations}}
}
{{/modelNamespaceDeclarations}}
{{/model}}
{{/models}}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy