Remove dynamic exceptions
[anna.git] / include / anna / diameter / stack / Format.hpp
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 #ifndef anna_diameter_stack_Format_hpp
10 #define anna_diameter_stack_Format_hpp
11
12 // Local
13 #include <anna/diameter/codec/Format.hpp>
14
15 #include <anna/config/defines.hpp>
16 #include <anna/core/RuntimeException.hpp>
17
18 // STL
19 #include <string>
20
21
22
23 namespace anna {
24 namespace xml {
25 class Node;
26 }
27 }
28
29
30
31 namespace anna {
32
33 namespace diameter {
34
35 namespace stack {
36
37 class Dictionary;
38
39 //------------------------------------------------------------------------------
40 //----------------------------------------------------------------- class Format
41 //------------------------------------------------------------------------------
42 /**
43 * Format data container
44 */
45 class Format {
46   const Dictionary *a_dictionary;
47   std::string a_name;
48   std::string a_parentName;
49
50   void _initialize(const Dictionary *d) {
51     a_dictionary = d;
52     a_name = "";
53     a_parentName = "";
54   }
55
56 public:
57
58   Format(const Dictionary *d = NULL) { _initialize(d); }
59   ~Format() {};
60
61
62   // get
63
64   /**
65   * Gets the format type name
66   *
67   * @return Format type name
68   */
69   const std::string & getName(void) const { return a_name; }
70
71   /**
72   * Gets the format parent type name
73   *
74   * @return Format parent type name, empty string for diameter basic format types (and reserved like 'Any, Unknown')
75   */
76   const std::string & getParentName(void) const { return a_parentName; }
77
78   // helpers
79
80   /**
81   * Gets the diameter parent type reference
82   *
83   * @return Diameter parent type reference, NULL for diameter basic format types (and reserved like 'Any, Unknown')
84   */
85   const Format * getParent(void) const ;
86
87   /**
88   * The diameter format is a derived type
89   *
90   * @return The format is derived
91   */
92   bool isDerived(void) const { return (a_parentName != ""); }
93
94   /**
95   * The diameter format is a basic type:
96   *  (OctetString, Integer32, Integer64, Unsigned32, Unsigned64, Float32, Float64, Grouped)
97   *
98   * @return The format is basic
99   */
100   bool isBasic(void) const { return (!isDerived() && !isReserved()); }
101
102   /**
103   * Gets the diameter basic format type from which a derived type inherit, or basic type itself for non-derived
104   *
105   * @return Diameter basic format type
106   */
107   codec::Format::_v getBasicType(void) const noexcept(false);
108
109   /**
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)
112   *
113   * @return The format belongs to RFC3588
114   */
115   bool isRFC3588(void) const { return (codec::Format::isRFC3588(a_name)); }
116
117   // Reserved
118   /** @return The format is 'Any' (generic AVP) */
119   bool isAny() const { return (a_name == codec::Format::asText(codec::Format::Any)); }
120 //   /** @return The format is 'Unknown' */
121 //   bool isUnknown() const { return (a_name == codec::Format::asText(codec::Format::Unknown)); }
122
123   // RFC 3588
124   /** @return The format is 'OctetString' */
125   bool isOctetString() const { return (a_name == codec::Format::asText(codec::Format::OctetString)); }
126   /** @return The format is 'Integer32' */
127   bool isInteger32() const { return (a_name == codec::Format::asText(codec::Format::Integer32)); }
128   /** @return The format is 'Integer64' */
129   bool isInteger64() const { return (a_name == codec::Format::asText(codec::Format::Integer64)); }
130   /** @return The format is 'Unsigned32' */
131   bool isUnsigned32() const { return (a_name == codec::Format::asText(codec::Format::Unsigned32)); }
132   /** @return The format is 'Unsigned64' */
133   bool isUnsigned64() const { return (a_name == codec::Format::asText(codec::Format::Unsigned64)); }
134   /** @return The format is 'Float32' */
135   bool isFloat32() const { return (a_name == codec::Format::asText(codec::Format::Float32)); }
136   /** @return The format is 'Float64' */
137   bool isFloat64() const { return (a_name == codec::Format::asText(codec::Format::Float64)); }
138   /** @return The format is 'Grouped' */
139   bool isGrouped() const { return (a_name == codec::Format::asText(codec::Format::Grouped)); }
140   /** @return The format is 'Address' */
141   bool isAddress() const { return (a_name == codec::Format::asText(codec::Format::Address)); }
142   /** @return The format is 'Time' */
143   bool isTime() const { return (a_name == codec::Format::asText(codec::Format::Time)); }
144   /** @return The format is 'UTF8String' */
145   bool isUTF8String() const { return (a_name == codec::Format::asText(codec::Format::UTF8String)); }
146   /** @return The format is 'DiameterIdentity' */
147   bool isDiameterIdentity() const { return (a_name == codec::Format::asText(codec::Format::DiameterIdentity)); }
148   /** @return The format is 'DiameterURI' */
149   bool isDiameterURI() const { return (a_name == codec::Format::asText(codec::Format::DiameterURI)); }
150   /** @return The format is 'Enumerated' */
151   bool isEnumerated() const { return (a_name == codec::Format::asText(codec::Format::Enumerated)); }
152   /** @return The format is 'IPFilterRule' */
153   bool isIPFilterRule() const { return (a_name == codec::Format::asText(codec::Format::IPFilterRule)); }
154   /** @return The format is 'QoSFilterRule' */
155   bool isQoSFilterRule() const { return (a_name == codec::Format::asText(codec::Format::QoSFilterRule)); }
156
157   /**
158   * The diameter format is application-specific or a format type name not registered on dictionary
159   *
160   * @return The format is application-specific
161   */
162   bool isApplicationSpecific(void) const { return (!isRFC3588() && !isReserved()); }
163
164   /**
165   * The diameter format is reserved ('Any' for generic AVP, 'Unknown' for not registered avps)
166   *
167   * @return The format is reserved
168   */
169   bool isReserved(void) const { return (codec::Format::isReserved(a_name)); }
170
171   /**
172   * Class string representation
173   *
174   * @return String with class content
175   */
176   std::string asString(void) const ;
177
178   /**
179   * Class xml representation
180   *
181   * @return XML document with relevant information for this instance.
182   */
183   anna::xml::Node* asXML(anna::xml::Node* parent) const ;
184
185   // operators
186
187   /**
188   * @return Equality between two class instances
189   */
190   friend bool operator == (const Format & f1, const Format & f2) { return ((f1.getName() == f2.getName())); }
191
192   /**
193   * @return Difference between two class instances
194   */
195   friend bool operator != (const Format & f1, const Format & f2) { return !(f1 == f2); }
196
197   // set
198
199   /**
200   * Initializes the class content
201   */
202   void initialize(const Dictionary *d = NULL) { _initialize(d); }
203
204   /**
205   * Sets Avp format type name
206   *
207   * @param type Avp format type name
208   */
209   void setName(const char * name) noexcept(false) {
210     if(name == NULL) throw anna::RuntimeException("Null Format-name not allowed", ANNA_FILE_LOCATION);
211
212     a_name = name;
213
214     if(a_name == "") throw anna::RuntimeException("Empty Format-name not allowed", ANNA_FILE_LOCATION);
215   }
216
217   /**
218   * Sets RFC3588 Avp format type name
219   *
220   * @param rfc3588Format RFC3588 format type
221   */
222   void setRFC3588(codec::Format::_v rfc3588Format) {
223     setName(codec::Format::asText(rfc3588Format));
224   }
225
226   /**
227   * Sets Diameter-basic avp format parent
228   *
229   * @param parent Diameter-basic avp format parent
230   */
231   void setParentName(const std::string & parentName) noexcept(false);
232 };
233
234
235 }
236 }
237 }
238
239
240 #endif
241
242