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

restbed.model-source.mustache Maven / Gradle / Ivy

There is a newer version: 3.0.0-rc1
Show newest version
{{>licenseInfo}}
{{#models}}{{#model}}

#include "{{classname}}.h"

#include 
#include 
#include 
#include 

using boost::property_tree::ptree;
using boost::property_tree::read_json;
using boost::property_tree::write_json;

{{#modelNamespaceDeclarations}}
namespace {{this}} {
{{/modelNamespaceDeclarations}}

{{classname}}::{{classname}}()
{
    {{#vars}}{{#isNotContainer}}{{#isPrimitiveType}}m_{{name}} = {{{defaultValue}}};
    {{/isPrimitiveType}}{{^isPrimitiveType}}{{#isString}}m_{{name}} = {{{defaultValue}}};
    {{/isString}}{{#isDateTime}}m_{{name}} = {{{defaultValue}}};
    {{/isDateTime}}{{/isPrimitiveType}}{{/isNotContainer}}{{/vars}}
}

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

std::string {{classname}}::toJsonString()
{
	std::stringstream ss;
	ptree pt;
	{{#vars}}
	{{#isNotContainer}}
	{{#isPrimitiveType}}
	pt.put("{{name}}", m_{{name}});
	{{/isPrimitiveType}}
	{{^isPrimitiveType}}
	{{#isString}}
	pt.put("{{name}}", m_{{name}});
	{{/isString}}
	{{#isDateTime}}
	pt.put("{{name}}", m_{{name}});
	{{/isDateTime}}
	{{/isPrimitiveType}}
	{{/isNotContainer}}
	{{/vars}}
	write_json(ss, pt, false);
	return ss.str();
}

void {{classname}}::fromJsonString(std::string const& jsonString)
{
	std::stringstream ss(jsonString);
	ptree pt;
	read_json(ss,pt);
	{{#vars}}
	{{#isNotContainer}}
	{{#isPrimitiveType}}
	m_{{name}} = pt.get("{{name}}", {{{defaultValue}}});
	{{/isPrimitiveType}}
	{{^isPrimitiveType}}
	{{#isString}}
	m_{{name}} = pt.get("{{name}}", {{{defaultValue}}});
	{{/isString}}
	{{#isDateTime}}
	m_{{name}} = pt.get("{{name}}", {{{defaultValue}}});
	{{/isDateTime}}
	{{/isPrimitiveType}}
	{{/isNotContainer}}
	{{/vars}}
}

{{#vars}}
{{{datatype}}} {{classname}}::{{getter}}() const
{
    return m_{{name}};
}
void {{classname}}::{{setter}}({{{datatype}}} value)
{
    m_{{name}} = value;
}
{{/vars}}

{{#modelNamespaceDeclarations}}
}
{{/modelNamespaceDeclarations}}

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy