Remove dynamic exceptions
[anna.git] / include / anna / diameter / stack / AvpRule.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_AvpRule_hpp
10 #define anna_diameter_stack_AvpRule_hpp
11
12
13 // Local
14 #include <anna/diameter/defines.hpp>
15
16 #include <anna/core/RuntimeException.hpp>
17 #include <anna/core/define.autoenum.hpp>
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 //------------------------------------------------------------------------------
48 /**
49 * Avp rule information
50 */
51 class AvpRule {
52
53 public:
54
55   struct Presence {
56     enum _v {
57       None = -1,
58       Fixed,
59       Mandatory,
60       Optional
61     };
62
63     anna_declare_enum(Presence);
64
65     /**
66     * Presence description
67     * @param v Presence type
68     * @return Presence description
69     */
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