Remove dynamic exceptions
[anna.git] / include / anna / diameter / stack / Vendor.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_Vendor_hpp
10 #define anna_diameter_stack_Vendor_hpp
11
12 // Local
13 #include <anna/config/defines.hpp>
14 #include <anna/diameter/defines.hpp>
15
16 #include <anna/config/defines.hpp>
17 #include <anna/core/RuntimeException.hpp>
18 #include <anna/core/define.autoenum.hpp>
19
20 // STL
21 #include <string>
22
23
24
25 namespace anna {
26 namespace xml {
27 class Node;
28 }
29 }
30
31
32
33 namespace anna {
34
35 namespace diameter {
36
37 namespace stack {
38
39
40 //------------------------------------------------------------------------------
41 //----------------------------------------------------------------- class Vendor
42 //------------------------------------------------------------------------------
43 /**
44 * Vendor data container
45 */
46 class Vendor {
47   S32 a_id;
48   std::string a_name;
49
50 public:
51
52   struct Code {
53     enum _v {
54       None = -1, // Initialized
55       Ietf = 0,
56       Nokia = 94,
57       Ericsson = 193,
58       TresGPP = 10415,
59       Telefonicaid = 5189,
60       Etsi = 13019
61     };
62
63     anna_declare_enum(Code);
64
65     /**
66     * Vendor description
67     * @param v Vendor code
68     * @return Vendor name
69     */
70     static const char* asText(const Code::_v v) noexcept(false) {
71       return asCString(v);
72     }
73   };
74
75
76   Vendor() {};
77   ~Vendor() {};
78
79
80   // get
81   S32 getId(void) const { return a_id; }
82   const S8 * getName(void) const { return a_name.c_str(); }
83
84   // helpers
85   bool isVendorSpecific(void) const { return (a_id > 0); }
86
87
88   std::string asString(void) const ;
89   anna::xml::Node* asXML(anna::xml::Node* parent) const ;
90
91   // operators
92   friend bool operator == (const Vendor & v1, const Vendor & v2) { return ((v1.getId() == v2.getId())); }
93
94   // set
95   void setId(const S32 & id) noexcept(false) {
96     if(id < 0) throw anna::RuntimeException("Negative vendor-id not allowed", ANNA_FILE_LOCATION);
97
98     a_id = id;
99   }
100
101   void setName(const std::string & n) noexcept(false) {
102     if(n == "") throw anna::RuntimeException("Empty vendor-name string not allowed", ANNA_FILE_LOCATION);
103
104     a_name = n;
105   }
106 };
107
108
109 }
110 }
111 }
112
113
114 #endif