ANNA Suite  2020b
Multipurpose development suite for Telco applications
Format.hpp
Go to the documentation of this file.
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
14 
15 #include <anna/config/defines.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 //------------------------------------------------------------------------------
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 
69  const std::string & getName(void) const { return a_name; }
70 
76  const std::string & getParentName(void) const { return a_parentName; }
77 
78  // helpers
79 
85  const Format * getParent(void) const ;
86 
92  bool isDerived(void) const { return (a_parentName != ""); }
93 
100  bool isBasic(void) const { return (!isDerived() && !isReserved()); }
101 
107  codec::Format::_v getBasicType(void) const noexcept(false);
108 
115  bool isRFC3588(void) const { return (codec::Format::isRFC3588(a_name)); }
116 
117  // Reserved
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
125  bool isOctetString() const { return (a_name == codec::Format::asText(codec::Format::OctetString)); }
127  bool isInteger32() const { return (a_name == codec::Format::asText(codec::Format::Integer32)); }
129  bool isInteger64() const { return (a_name == codec::Format::asText(codec::Format::Integer64)); }
131  bool isUnsigned32() const { return (a_name == codec::Format::asText(codec::Format::Unsigned32)); }
133  bool isUnsigned64() const { return (a_name == codec::Format::asText(codec::Format::Unsigned64)); }
135  bool isFloat32() const { return (a_name == codec::Format::asText(codec::Format::Float32)); }
137  bool isFloat64() const { return (a_name == codec::Format::asText(codec::Format::Float64)); }
139  bool isGrouped() const { return (a_name == codec::Format::asText(codec::Format::Grouped)); }
141  bool isAddress() const { return (a_name == codec::Format::asText(codec::Format::Address)); }
143  bool isTime() const { return (a_name == codec::Format::asText(codec::Format::Time)); }
145  bool isUTF8String() const { return (a_name == codec::Format::asText(codec::Format::UTF8String)); }
147  bool isDiameterIdentity() const { return (a_name == codec::Format::asText(codec::Format::DiameterIdentity)); }
149  bool isDiameterURI() const { return (a_name == codec::Format::asText(codec::Format::DiameterURI)); }
151  bool isEnumerated() const { return (a_name == codec::Format::asText(codec::Format::Enumerated)); }
153  bool isIPFilterRule() const { return (a_name == codec::Format::asText(codec::Format::IPFilterRule)); }
155  bool isQoSFilterRule() const { return (a_name == codec::Format::asText(codec::Format::QoSFilterRule)); }
156 
162  bool isApplicationSpecific(void) const { return (!isRFC3588() && !isReserved()); }
163 
169  bool isReserved(void) const { return (codec::Format::isReserved(a_name)); }
170 
176  std::string asString(void) const ;
177 
183  anna::xml::Node* asXML(anna::xml::Node* parent) const ;
184 
185  // operators
186 
190  friend bool operator == (const Format & f1, const Format & f2) { return ((f1.getName() == f2.getName())); }
191 
195  friend bool operator != (const Format & f1, const Format & f2) { return !(f1 == f2); }
196 
197  // set
198 
202  void initialize(const Dictionary *d = NULL) { _initialize(d); }
203 
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 
222  void setRFC3588(codec::Format::_v rfc3588Format) {
223  setName(codec::Format::asText(rfc3588Format));
224  }
225 
231  void setParentName(const std::string & parentName) noexcept(false);
232 };
233 
234 
235 }
236 }
237 }
238 
239 
240 #endif
241 
242 
bool isOctetString() const
Definition: Format.hpp:125
const std::string & getName(void) const
Definition: Format.hpp:69
bool isUTF8String() const
Definition: Format.hpp:145
bool isFloat32() const
Definition: Format.hpp:135
bool isUnsigned32() const
Definition: Format.hpp:131
Definition: Node.hpp:56
bool isInteger32() const
Definition: Format.hpp:127
bool isRFC3588(void) const
Definition: Format.hpp:115
bool isReserved(void) const
Definition: Format.hpp:169
bool isBasic(void) const
Definition: Format.hpp:100
bool isEnumerated() const
Definition: Format.hpp:151
_v
Definition: Format.hpp:30
void initialize(const Dictionary *d=NULL)
Definition: Format.hpp:202
bool isDiameterIdentity() const
Definition: Format.hpp:147
bool isGrouped() const
Definition: Format.hpp:139
bool isInteger64() const
Definition: Format.hpp:129
bool isAny() const
Definition: Format.hpp:119
bool isApplicationSpecific(void) const
Definition: Format.hpp:162
xml::Node Node
Definition: Node.hpp:21
Definition: Dictionary.hpp:50
Definition: app.hpp:12
bool isIPFilterRule() const
Definition: Format.hpp:153
~Format()
Definition: Format.hpp:59
bool isDiameterURI() const
Definition: Format.hpp:149
void setName(const char *name) noexcept(false)
Definition: Format.hpp:209
bool isDerived(void) const
Definition: Format.hpp:92
bool isQoSFilterRule() const
Definition: Format.hpp:155
const std::string & getParentName(void) const
Definition: Format.hpp:76
#define ANNA_FILE_LOCATION
Definition: defines.hpp:23
void setRFC3588(codec::Format::_v rfc3588Format)
Definition: Format.hpp:222
Definition: Format.hpp:45
bool isFloat64() const
Definition: Format.hpp:137
bool isUnsigned64() const
Definition: Format.hpp:133
Format(const Dictionary *d=NULL)
Definition: Format.hpp:58
Definition: RuntimeException.hpp:23
bool isAddress() const
Definition: Format.hpp:141
bool isTime() const
Definition: Format.hpp:143