Changed LICENSE. Now referenced to web site and file on project root directory
[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) throw(anna::RuntimeException) {
71       return asCString(v);
72     }
73   };
74
75 private:
76
77   const Dictionary *a_dictionary;
78   std::string a_avpName; // reference
79   Presence::_v a_presence;
80   std::string a_qual;
81
82   void _initialize(const Dictionary *d) throw() {
83     a_dictionary = d;
84     a_avpName = "";
85     a_presence = Presence::None;
86     a_qual = "";
87   }
88
89 public:
90
91
92   AvpRule(const Dictionary *d = NULL) { _initialize(d); }
93   ~AvpRule() {};
94
95
96   // get
97   const std::string & getAvpName(void) const throw() { return a_avpName; }
98   const Presence::_v & getPresence(void) const throw() { return a_presence; }
99   const std::string & getQual(void) const throw() { return a_qual; }
100
101   // helpers
102   AvpId getId(void) const throw();
103   bool isAny(void) const throw(); // generic Avp
104   bool isFixed(void) const throw() { return (a_presence == Presence::Fixed); }
105   bool isMandatory(void) const throw() { return (a_presence == Presence::Mandatory); }
106   bool isOptional(void) const throw() { return (a_presence == Presence::Optional); }
107   int getQualMin(void) const throw();
108   int getQualMax(void) const throw(); // -1 is infinite
109
110   std::string asString(bool showPair = true) const throw();
111   anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
112
113   // operators
114
115   // set
116   void initialize(const Dictionary *d = NULL) throw() { _initialize(d); }
117   void setAvpName(const std::string & an) throw() { a_avpName = an; }
118   void setPresence(const Presence::_v & p) throw() { a_presence = p; }
119   void setQual(const std::string & q) throw(anna::RuntimeException);
120 };
121
122
123 }
124 }
125 }
126
127
128 #endif
129