
/******************************  LICENSE  *******************************

 * (C) Copyright 1996-2017 ECMWF.
 * 
 * This software is licensed under the terms of the Apache Licence Version 2.0
 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. 
 * In applying this licence, ECMWF does not waive the privileges and immunities 
 * granted to it by virtue of its status as an intergovernmental organisation nor
 * does it submit to any jurisdiction.

 *******************************  LICENSE  *******************************/

/*! \\file {{object }}Attributes.h
    \\brief Definition of {{ object }} Attributes class.

    This file is automatically generated.
    Do Not Edit!
*/

#include "{{ object }}Attributes.h"
#include "MagicsParameter.h"
#include "ParameterSettings.h"

using namespace magics;

{{ object }}Attributes::{{ object }}Attributes(){{ ":" if not string_parameters | length == 0 or not factory_parameters | length == 0 }}
	{% for param  in string_parameters -%} 
 	{{ param.member }}_(ParameterManager::{{ param.method }}("{{ param.name }}")){{ "," if not loop.last }}
	{% endfor -%}
	{{ "," if not string_parameters | length == 0 and not factory_parameters | length == 0 }}
	{% for param  in factory_parameters -%}
	{{ param.member }}_(MagTranslator<{{ param.from }}, {{ param.to }}>().magics("{{ param.name }}")){{ "," if not loop.last }}
	{% endfor %} 
{
} 


{{ object }}Attributes::~{{ object }}Attributes()
{
	
}

    
void {{ object }}Attributes::set(const std::map<string, string>& params)
{
	vector<string> prefix({{ prefix | length -}});
	int i = 0;
	{% for key in prefix -%} 
	prefix[i++] = "{{ key }}";
	{% endfor %}
	{% for param  in string_parameters -%} 
 	setAttribute(prefix, "{{ param.name }}", {{ param.member }}_, params);
	{% endfor %}
	{% for param  in factory_parameters -%} 
 	{{ param.method }}(prefix, "{{ param.name }}", {{ param.member }}_, params);
	{% endfor %}
}

void {{ object }}Attributes::copy(const {{ object }}Attributes& other)
{
	{% for param  in string_parameters -%} 
 		{{ param.member }}_ = other.{{ param.member }}_;
	{% endfor -%}
	{% for param  in factory_parameters -%} 
	{% if param.enum  -%}
		{{ param.member }}_ = other.{{ param.member }}_;
	{% else -%}
 		{{ param.member }}_ = unique_ptr<{{ param.to }}>(other.{{ param.member }}_->clone());
	{% endif -%}
	{% endfor %}
} 


bool {{ object }}Attributes::accept(const string& node)
{	
	if ( magCompare(node, "{{ tag }}")  )
		return true;
	{% for param  in factory_parameters -%} 
	{% if not param.niceprint -%}
		if ( acceptNode(node, {{ param.member }}_) )
		return true;
	{% endif -%}
	{% endfor %}
}

void {{ object }}Attributes::set(const XmlNode& node)
{
	if ( this->accept(node.name()) == false ) 
		return;

	if ( magCompare(node.name(), "{{ tag }}") )
		set(node.attributes());
	else {
		{% for param  in factory_parameters -%} 
		{% if not param.niceprint  -%}
		setMember(node.name(), {{ param.member }}_, node);
		{% endif -%}
		{% endfor %}
	}
	for (XmlNode::ElementIterator elt = node.firstElement(); elt != node.lastElement(); ++elt) {
		{% for param  in factory_parameters -%} 
		{% if not param.niceprint  -%}
		setMember((*elt)->name(), {{ param.member }}_, *(*elt)); 
		{% endif -%}
		{% endfor %}
	}
}

void {{ object }}Attributes::print(ostream& out)  const
{
	out << "{{ name }}Attributes[";
	{% for param  in string_parameters -%} 
 		out << " {{ param.member }} = " <<  {{ param.member }}_;
	{% endfor -%}
	{% for param  in factory_parameters -%} 
	{% if param.enum -%}
		out << " {{ param.member }} = " <<  {{ param.member }}_;
	{% else -%}
		out << " {{ param.member }} = " <<  *{{ param.member }}_;
	{% endif -%}
	{% endfor %}
	out << "]" << "\n";
}

void {{ object }}Attributes::toxml(ostream& out)  const
{
	out <<  "\"{{ tag }}\"";
	{% for param  in string_parameters -%} 
	out << ", \"{{ param.name }}:\":";
	niceprint(out,{{ param.member }}_);
	{% endfor -%}    
	{% for param  in factory_parameters -%} 
	out << ", \"{{ param.name }}\":";
	{% if param.niceprint -%}
	niceprint(out, {{ "*" if not param.enum }}{{ param.member }}_);
	{% else -%} 
	{{ param.member }}_->toxml(out);
	{% endif -%}
	{% endfor %}
}

{% for param  in string_parameters -%} 
static MagicsParameter<{{ param.from }}> {{ param.name }}("{{ param.name }}", {{ param.delimiter }}{{ param.default }}{{ param.delimiter }}, "");
{% endfor -%}  
{% for param  in factory_parameters -%} 
static MagicsParameter<{{ param.from }}> {{ param.name }}("{{ param.name }}", {{ param.delimiter }}{{ param.default }}{{ param.delimiter }}, ""); 
{% endfor  -%}  
{% for include  in include_options -%} 
#include "{{ include }}"
{% endfor -%} 
{% for param  in factory_parameters -%} 
{% if  not param.niceprint -%} 
{% for value  in param.options -%} 
static SimpleObjectMaker<{{ value.object }} , {{ value.parent }}> {{ value.name }}_{{ value.object }}("{{ value.key }}");
{% endfor -%} 
{% endif -%} 
{% endfor -%}   

