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 //
9 #ifndef anna_diameter_stack_Format_hpp
10 #define anna_diameter_stack_Format_hpp
13 #include <anna/diameter/codec/Format.hpp>
15 #include <anna/config/defines.hpp>
16 #include <anna/core/RuntimeException.hpp>
39 //------------------------------------------------------------------------------
40 //----------------------------------------------------------------- class Format
41 //------------------------------------------------------------------------------
43 * Format data container
46 const Dictionary *a_dictionary;
48 std::string a_parentName;
50 void _initialize(const Dictionary *d) throw() {
58 Format(const Dictionary *d = NULL) { _initialize(d); }
65 * Gets the format type name
67 * @return Format type name
69 const std::string & getName(void) const throw() { return a_name; }
72 * Gets the format parent type name
74 * @return Format parent type name, empty string for diameter basic format types (and reserved like 'Any, Unknown')
76 const std::string & getParentName(void) const throw() { return a_parentName; }
81 * Gets the diameter parent type reference
83 * @return Diameter parent type reference, NULL for diameter basic format types (and reserved like 'Any, Unknown')
85 const Format * getParent(void) const throw();
88 * The diameter format is a derived type
90 * @return The format is derived
92 bool isDerived(void) const throw() { return (a_parentName != ""); }
95 * The diameter format is a basic type:
96 * (OctetString, Integer32, Integer64, Unsigned32, Unsigned64, Float32, Float64, Grouped)
98 * @return The format is basic
100 bool isBasic(void) const throw() { return (!isDerived() && !isReserved()); }
103 * Gets the diameter basic format type from which a derived type inherit, or basic type itself for non-derived
105 * @return Diameter basic format type
107 codec::Format::_v getBasicType(void) const throw(anna::RuntimeException);
110 * The diameter format belongs to RFC3588 diameter format family:
111 * (OctetString, Integer32, Integer64, Unsigned32, Unsigned64, Float32, Float64, Grouped, Address, Time, UTF8String, DiameterIdentity, DiameterURI, Enumerated, IPFilterRule, QoSFilterRule)
113 * @return The format belongs to RFC3588
115 bool isRFC3588(void) const throw() { return (codec::Format::isRFC3588(a_name)); }
118 /** @return The format is 'Any' (generic AVP) */
119 bool isAny() const throw() { return (a_name == codec::Format::asText(codec::Format::Any)); }
120 // /** @return The format is 'Unknown' */
121 // bool isUnknown() const throw() { return (a_name == codec::Format::asText(codec::Format::Unknown)); }
124 /** @return The format is 'OctetString' */
125 bool isOctetString() const throw() { return (a_name == codec::Format::asText(codec::Format::OctetString)); }
126 /** @return The format is 'Integer32' */
127 bool isInteger32() const throw() { return (a_name == codec::Format::asText(codec::Format::Integer32)); }
128 /** @return The format is 'Integer64' */
129 bool isInteger64() const throw() { return (a_name == codec::Format::asText(codec::Format::Integer64)); }
130 /** @return The format is 'Unsigned32' */
131 bool isUnsigned32() const throw() { return (a_name == codec::Format::asText(codec::Format::Unsigned32)); }
132 /** @return The format is 'Unsigned64' */
133 bool isUnsigned64() const throw() { return (a_name == codec::Format::asText(codec::Format::Unsigned64)); }
134 /** @return The format is 'Float32' */
135 bool isFloat32() const throw() { return (a_name == codec::Format::asText(codec::Format::Float32)); }
136 /** @return The format is 'Float64' */
137 bool isFloat64() const throw() { return (a_name == codec::Format::asText(codec::Format::Float64)); }
138 /** @return The format is 'Grouped' */
139 bool isGrouped() const throw() { return (a_name == codec::Format::asText(codec::Format::Grouped)); }
140 /** @return The format is 'Address' */
141 bool isAddress() const throw() { return (a_name == codec::Format::asText(codec::Format::Address)); }
142 /** @return The format is 'Time' */
143 bool isTime() const throw() { return (a_name == codec::Format::asText(codec::Format::Time)); }
144 /** @return The format is 'UTF8String' */
145 bool isUTF8String() const throw() { return (a_name == codec::Format::asText(codec::Format::UTF8String)); }
146 /** @return The format is 'DiameterIdentity' */
147 bool isDiameterIdentity() const throw() { return (a_name == codec::Format::asText(codec::Format::DiameterIdentity)); }
148 /** @return The format is 'DiameterURI' */
149 bool isDiameterURI() const throw() { return (a_name == codec::Format::asText(codec::Format::DiameterURI)); }
150 /** @return The format is 'Enumerated' */
151 bool isEnumerated() const throw() { return (a_name == codec::Format::asText(codec::Format::Enumerated)); }
152 /** @return The format is 'IPFilterRule' */
153 bool isIPFilterRule() const throw() { return (a_name == codec::Format::asText(codec::Format::IPFilterRule)); }
154 /** @return The format is 'QoSFilterRule' */
155 bool isQoSFilterRule() const throw() { return (a_name == codec::Format::asText(codec::Format::QoSFilterRule)); }
158 * The diameter format is application-specific or a format type name not registered on dictionary
160 * @return The format is application-specific
162 bool isApplicationSpecific(void) const throw() { return (!isRFC3588() && !isReserved()); }
165 * The diameter format is reserved ('Any' for generic AVP, 'Unknown' for not registered avps)
167 * @return The format is reserved
169 bool isReserved(void) const throw() { return (codec::Format::isReserved(a_name)); }
172 * Class string representation
174 * @return String with class content
176 std::string asString(void) const throw();
179 * Class xml representation
181 * @return XML document with relevant information for this instance.
183 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
188 * @return Equality between two class instances
190 friend bool operator == (const Format & f1, const Format & f2) { return ((f1.getName() == f2.getName())); }
193 * @return Difference between two class instances
195 friend bool operator != (const Format & f1, const Format & f2) { return !(f1 == f2); }
200 * Initializes the class content
202 void initialize(const Dictionary *d = NULL) throw() { _initialize(d); }
205 * Sets Avp format type name
207 * @param type Avp format type name
209 void setName(const char * name) throw(anna::RuntimeException) {
210 if(name == NULL) throw anna::RuntimeException("Null Format-name not allowed", ANNA_FILE_LOCATION);
214 if(a_name == "") throw anna::RuntimeException("Empty Format-name not allowed", ANNA_FILE_LOCATION);
218 * Sets RFC3588 Avp format type name
220 * @param rfc3588Format RFC3588 format type
222 void setRFC3588(codec::Format::_v rfc3588Format) throw() {
223 setName(codec::Format::asText(rfc3588Format));
227 * Sets Diameter-basic avp format parent
229 * @param parent Diameter-basic avp format parent
231 void setParentName(const std::string & parentName) throw(anna::RuntimeException);