1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
10 #include <anna/diameter/stack/Format.hpp>
11 #include <anna/diameter/stack/Dictionary.hpp>
13 #include <anna/core/functions.hpp>
14 #include <anna/xml/xml.hpp>
16 //using namespace anna;
18 //------------------------------------------------------------------------------
19 //------------------------------------------------------- Format::getBasicType()
20 //------------------------------------------------------------------------------
21 anna::diameter::codec::Format::_v anna::diameter::stack::Format::getBasicType(void) const throw(anna::RuntimeException) {
22 if(isDerived()) return a_dictionary->getFormat(a_parentName)->getBasicType();
25 throw anna::RuntimeException("Develop error: there is no basic format type for reserved codec::Format", ANNA_FILE_LOCATION);
27 return (anna::diameter::codec::Format::asEnum(a_name));
31 //------------------------------------------------------------------------------
32 //------------------------------------------------------ Format::setParentName()
33 //------------------------------------------------------------------------------
34 void anna::diameter::stack::Format::setParentName(const std::string & parentName) throw(anna::RuntimeException) {
35 const Format * parent = a_dictionary->getFormat(parentName);
37 //if (parent && parent->isDerived()) // actually dtd-verified:
38 if(parent && !parent->isBasic()) // actually dtd-verified (and 'Any' is not allowed):
39 throw anna::RuntimeException("Only basic diameter format allowed for parent type", ANNA_FILE_LOCATION);
41 a_parentName = parentName;
45 //------------------------------------------------------------------------------
46 //----------------------------------------------------------- Format::asString()
47 //------------------------------------------------------------------------------
48 std::string anna::diameter::stack::Format::asString(void) const throw() {
54 const Format * parent = a_dictionary->getFormat(a_parentName);
57 trace += ", derived from ";
58 trace += parent->asString();
65 //------------------------------------------------------------------------------
66 //-------------------------------------------------------------- Format::asXML()
67 //------------------------------------------------------------------------------
68 anna::xml::Node* anna::diameter::stack::Format::asXML(anna::xml::Node* parent) const throw() {
69 // <!ELEMENT format EMPTY>
70 // <!ATTLIST format name CDATA #REQUIRED parent-type ( OctetString | Integer32 | Integer64 | Unsigned32 | Unsigned64 | Float32 | Float64 ) #REQUIRED>
71 anna::xml::Node* result = parent->createChild("format");
72 result->createAttribute("name", a_name);
73 result->createAttribute("parent-type", a_parentName);