All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cpp-rest-sdk-client.model-source.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
{{>licenseInfo}}
{{#models}}{{#model}}

#include "{{packageName}}/model/{{classFilename}}.h"

{{#modelNamespaceDeclarations}}
namespace {{this}} {
{{/modelNamespaceDeclarations}}
{{#oneOf}}{{#-first}}

void {{classname}}::validate()
{
    // TODO: implement validation
}

const {{classname}}::VariantType& {{classname}}::getVariant() const
{
    return m_variantValue;
}

void {{classname}}::setVariant({{classname}}::VariantType value)
{
    m_variantValue = value;
}

web::json::value {{classname}}::toJson() const
{
    web::json::value val = web::json::value::object();

    std::visit([&](auto&& arg) {
        using T = std::decay_t;
        if constexpr (std::is_same_v) {
            val = web::json::value::null();
        } else {
            val = arg.toJson();
        }
    }, m_variantValue);

    return val;
}

void {{classname}}::toMultipart(std::shared_ptr multipart, const utility::string_t& prefix) const
{
    std::visit([&](auto&& arg) {
        using T = std::decay_t;
        if constexpr (!std::is_same_v) {
          arg.toMultipart(multipart, prefix);
        }
    }, m_variantValue);
}

{{#oneOf}}
template bool {{classname}}::fromJson<{{.}}>(const web::json::value& json);
template bool {{classname}}::fromMultiPart<{{.}}>(std::shared_ptr multipart, const utility::string_t& namePrefix);
{{/oneOf}}

{{/-first}}{{/oneOf}}
{{^oneOf}}
{{#isEnum}}

namespace
{
using EnumUnderlyingType = {{#isNumeric}}int64_t{{/isNumeric}}{{^isNumeric}}utility::string_t{{/isNumeric}};

{{classname}}::e{{classname}} toEnum(const EnumUnderlyingType& val)
{
{{#allowableValues}}
{{#isNumeric}}
    switch (val)
    {
    {{#enumVars}}
    case {{value}}:
        return {{classname}}::e{{classname}}::{{classname}}_{{name}};
    {{#-last}}
    default:
        break;
    {{/-last}}
    {{/enumVars}}
    }
{{/isNumeric}}
{{^isNumeric}}
    {{#enumVars}}
    if (val == utility::conversions::to_string_t(U("{{{value}}}")))
        return {{classname}}::e{{classname}}::{{classname}}_{{name}};
    {{/enumVars}}
{{/isNumeric}}
{{/allowableValues}}
    return {};
}

EnumUnderlyingType fromEnum({{classname}}::e{{classname}} e)
{
{{#allowableValues}}
    switch (e)
    {
{{#enumVars}}
    case {{classname}}::e{{classname}}::{{classname}}_{{name}}:
        return {{#isNumeric}}{{value}}{{/isNumeric}}{{^isNumeric}}U("{{value}}"){{/isNumeric}};
{{#-last}}
    default:
        break;
{{/-last}}
{{/enumVars}}
    }
{{/allowableValues}}
    return {};
}
}

{{classname}}::{{classname}}()
{
}

{{classname}}::~{{classname}}()
{
}

void {{classname}}::validate()
{
    // TODO: implement validation
}

web::json::value {{classname}}::toJson() const
{
    auto val = fromEnum(m_value);
    return web::json::value(val);
}

bool {{classname}}::fromJson(const web::json::value& val)
{
    m_value = toEnum({{#isNumeric}}val.as_number().to_int64(){{/isNumeric}}{{^isNumeric}}val.as_string(){{/isNumeric}});
    return true;
}

void {{classname}}::toMultipart(std::shared_ptr multipart, const utility::string_t& prefix) const
{
    utility::string_t namePrefix = prefix;
    if (!namePrefix.empty() && namePrefix.back() != U('.'))
    {
        namePrefix.push_back(U('.'));
    }

    auto e = fromEnum(m_value);
    multipart->add(ModelBase::toHttpContent(namePrefix, e));
}

bool {{classname}}::fromMultiPart(std::shared_ptr multipart, const utility::string_t& prefix)
{
    bool ok = true;
    utility::string_t namePrefix = prefix;
    if (!namePrefix.empty() && namePrefix.back() != U('.'))
    {
        namePrefix.push_back(U('.'));
    }
    {
        EnumUnderlyingType e;
        ok = ModelBase::fromHttpContent(multipart->getContent(namePrefix), e);
        if (ok)
        {
            auto v = toEnum(e);
            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->{{{.}}}::toJson();{{/parent}}
    {{^parent}}
    web::json::value val = web::json::value::object();
    {{/parent}}
    {{#vars}}{{^isInherited}}
    if(m_{{name}}IsSet)
    {
        val[utility::conversions::to_string_t(U("{{baseName}}"))] = ModelBase::toJson(m_{{name}});
    }{{/isInherited}}{{/vars}}

    return val;
}

bool {{classname}}::fromJson(const web::json::value& val)
{
    bool ok = true;
    {{#parent}}
    ok &= this->{{{.}}}::fromJson(val);
    {{/parent}}
    {{#vars}}{{^isInherited}}
    if(val.has_field(utility::conversions::to_string_t(U("{{baseName}}"))))
    {
        const web::json::value& fieldValue = val.at(utility::conversions::to_string_t(U("{{baseName}}")));
        if(!fieldValue.is_null())
        {
            {{{dataType}}} refVal_{{setter}};
            ok &= ModelBase::fromJson(fieldValue, refVal_{{setter}});
            {{setter}}(refVal_{{setter}});
        }
    }{{/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(U(".")))
    {
        namePrefix += utility::conversions::to_string_t(U("."));
    }
    {{#vars}}
    if(m_{{name}}IsSet)
    {
        multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(U("{{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(U(".")))
    {
        namePrefix += utility::conversions::to_string_t(U("."));
    }

    {{#vars}}
    if(multipart->hasContent(utility::conversions::to_string_t(U("{{baseName}}"))))
    {
        {{{dataType}}} refVal_{{setter}};
        ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(U("{{baseName}}"))), refVal_{{setter}} );
        {{setter}}(refVal_{{setter}});
    }
    {{/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}}
{{/oneOf}}
{{#modelNamespaceDeclarations}}
}
{{/modelNamespaceDeclarations}}


{{/model}}
{{/models}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy