Fix local server for multiple applications
[anna.git] / stack / Format.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
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 //
7
8
9 // Local
10 #include <anna/diameter/stack/Format.hpp>
11 #include <anna/diameter/stack/Dictionary.hpp>
12
13 #include <anna/core/functions.hpp>
14 #include <anna/xml/xml.hpp>
15
16 //using namespace anna;
17
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();
23
24   if(isReserved())
25     throw anna::RuntimeException("Develop error: there is no basic format type for reserved codec::Format", ANNA_FILE_LOCATION);
26
27   return (anna::diameter::codec::Format::asEnum(a_name));
28 }
29
30
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);
36
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);
40
41   a_parentName = parentName;
42 }
43
44
45 //------------------------------------------------------------------------------
46 //----------------------------------------------------------- Format::asString()
47 //------------------------------------------------------------------------------
48 std::string anna::diameter::stack::Format::asString(void) const throw() {
49   std::string trace;
50   //trace = "Format '";
51   trace = "'";
52   trace += a_name;
53   trace += "'";
54   const Format * parent = a_dictionary->getFormat(a_parentName);
55
56   if(parent) {
57     trace += ", derived from ";
58     trace += parent->asString();
59   }
60
61   return (trace);
62 }
63
64
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);
74   return result;
75 }
76