Remove dynamic exceptions
[anna.git] / include / anna / diameter / stack / Command.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_Command_hpp
10 #define anna_diameter_stack_Command_hpp
11
12
13 // Local
14 #include <anna/diameter/defines.hpp>
15 #include <anna/diameter/stack/AvpRule.hpp>
16 #include <anna/diameter/codec/Format.hpp>
17
18 #include <anna/core/RuntimeException.hpp>
19 #include <anna/config/defines.hpp>
20
21 // STL
22 #include <string>
23 #include <map>
24
25
26
27 namespace anna {
28 namespace xml {
29 class Node;
30 }
31 }
32
33
34 namespace anna {
35
36 namespace diameter {
37
38 namespace stack {
39
40 class Dictionary;
41
42 //------------------------------------------------------------------------------
43 //---------------------------------------------------------------- class Command
44 //------------------------------------------------------------------------------
45 /**
46 * Command information
47 */
48 class Command {
49
50 public:
51
52   //typedef std::map<AvpId, AvpRule> avprule_container;
53   typedef std::map < int /*position*/, AvpRule > avprule_container;
54   typedef avprule_container::iterator avprule_iterator;
55   typedef avprule_container::const_iterator const_avprule_iterator;
56
57
58 private:
59
60   const Dictionary *a_dictionary;
61   CommandId a_id;
62   std::string a_name;
63
64   // Children:
65   avprule_container a_avprules;
66   bool a_allowFixedRule;
67   int a_avprulePosition;
68
69   void _initializeRules() {
70     a_avprules.clear();
71     a_allowFixedRule = true;
72     a_avprulePosition = 0;
73   }
74
75   void _initialize(const Dictionary *d) {
76     a_dictionary = d;
77     _initializeRules();
78   }
79
80 public:
81
82   Command(const Dictionary *d = NULL) { _initialize(d); }
83   ~Command() {};
84
85
86   // get
87   const CommandId & getId(void) const { return a_id; }
88   const std::string & getName(void) const { return a_name; }
89
90
91   // containers
92   const_avprule_iterator avprule_begin() const { return a_avprules.begin(); }
93   const_avprule_iterator avprule_end() const { return a_avprules.end(); }
94   int avprule_size() const { return a_avprules.size(); }
95
96
97   // helpers
98   bool isEmpty(void) const { return (!a_avprules.size()); }
99   bool isRequest(void) const { return (a_id.second); }
100   bool isAnswer(void) const { return (!a_id.second); }
101   bool isChild(const AvpId & avp) const ;
102
103   std::string asString(void) const ;
104   anna::xml::Node* asXML(anna::xml::Node* parent) const ;
105
106   // operators
107
108   // set
109   void initialize(const Dictionary *d = NULL) { _initialize(d); }
110   void setCode(const U24 & c) noexcept(false) {
111
112     a_id.first = c;
113   }
114   void setRequest(bool r = true) { a_id.second = r; }
115   void setAnswer(bool a = true) { a_id.second = a; }
116   void setName(const std::string & n) noexcept(false) {
117     if(n == "") throw anna::RuntimeException("Empty command-name string not allowed", ANNA_FILE_LOCATION);
118
119     a_name = n;
120   }
121   void addAvpRule(const AvpRule & avpRule) noexcept(false);
122 };
123
124
125 }
126 }
127 }
128
129
130 #endif