ANNA Suite  2020b
Multipurpose development suite for Telco applications
AvpRule.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_AvpRule_hpp
10 #define anna_diameter_stack_AvpRule_hpp
11 
12 
13 // Local
15 
18 
19 // STL
20 #include <string>
21 #include <map>
22 
23 
24 // Five spaces:
25 #define DICTIONARY_AVPRULE_TAB " "
26 
27 
28 
29 namespace anna {
30 namespace xml {
31 class Node;
32 }
33 }
34 
35 
36 
37 namespace anna {
38 
39 namespace diameter {
40 
41 namespace stack {
42 
43 class Dictionary;
44 
45 //------------------------------------------------------------------------------
46 //---------------------------------------------------------------- class AvpRule
47 //------------------------------------------------------------------------------
51 class AvpRule {
52 
53 public:
54 
55  struct Presence {
56  enum _v {
57  None = -1,
60  Optional
61  };
62 
64 
70  static const char* asText(const Presence::_v v) noexcept(false) {
71  return asCString(v);
72  }
73  };
74 
75 private:
76 
77  const Dictionary *a_dictionary;
78  AvpId a_avpId; // reference
79  Presence::_v a_presence;
80  std::string a_qual;
81 
82  void _initialize(const Dictionary *d) {
83  a_dictionary = d;
84  a_presence = Presence::None;
85  a_qual = "";
86  }
87 
88 public:
89 
90 
91  AvpRule(const Dictionary *d = NULL) { _initialize(d); }
92  ~AvpRule() {};
93 
94 
95  // get
96  std::string getAvpName(void) const ;
97  const Presence::_v & getPresence(void) const { return a_presence; }
98  const std::string & getQual(void) const { return a_qual; }
99 
100  // helpers
101  AvpId getId(void) const { return a_avpId; }
102  bool isAny(void) const ; // generic Avp
103  bool isFixed(void) const { return (a_presence == Presence::Fixed); }
104  bool isMandatory(void) const { return (a_presence == Presence::Mandatory); }
105  bool isOptional(void) const { return (a_presence == Presence::Optional); }
106  int getQualMin(void) const ;
107  int getQualMax(void) const ; // -1 is infinite
108 
109  std::string asString(bool showPair = true) const ;
110  anna::xml::Node* asXML(anna::xml::Node* parent) const ;
111 
112  // operators
113 
114  // set
115  void initialize(const Dictionary *d = NULL) { _initialize(d); }
116  void setAvpId(const AvpId & ai) { a_avpId = ai; }
117  void setPresence(const Presence::_v & p) { a_presence = p; }
118  void setQual(const std::string & q) noexcept(false);
119 };
120 
121 
122 }
123 }
124 }
125 
126 
127 #endif
128 
~AvpRule()
Definition: AvpRule.hpp:92
const std::string & getQual(void) const
Definition: AvpRule.hpp:98
const Presence::_v & getPresence(void) const
Definition: AvpRule.hpp:97
bool isOptional(void) const
Definition: AvpRule.hpp:105
#define anna_declare_enum(name)
Definition: define.autoenum.hpp:48
static const char * asText(const Presence::_v v) noexcept(false)
Definition: AvpRule.hpp:70
Definition: Node.hpp:56
void setAvpId(const AvpId &ai)
Definition: AvpRule.hpp:116
std::pair< S32, S32 > AvpId
Definition: defines.hpp:31
bool isMandatory(void) const
Definition: AvpRule.hpp:104
xml::Node Node
Definition: Node.hpp:21
Definition: Dictionary.hpp:50
Definition: app.hpp:12
AvpId getId(void) const
Definition: AvpRule.hpp:101
void initialize(const Dictionary *d=NULL)
Definition: AvpRule.hpp:115
bool isFixed(void) const
Definition: AvpRule.hpp:103
AvpRule(const Dictionary *d=NULL)
Definition: AvpRule.hpp:91
void setPresence(const Presence::_v &p)
Definition: AvpRule.hpp:117
Definition: AvpRule.hpp:51