Remove dynamic exceptions
[anna.git] / include / anna / diameter / codec / Format.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_codec_Format_hpp
10 #define anna_diameter_codec_Format_hpp
11
12
13 #include <anna/core/RuntimeException.hpp>
14 #include <anna/core/define.autoenum.hpp>
15
16 // STL
17 #include <string>
18
19
20 namespace anna {
21
22 namespace diameter {
23
24 namespace codec {
25
26 /**
27 * Diameter RFC3588 Avp Data Format definition
28 */
29 struct Format {
30   enum _v {
31     None = -1,        // Initialized
32
33 // Reserved
34     Unknown,          // Unregistered at diameter dictionary
35     Any,              // used on generic AVP
36 // RFC 3588
37     OctetString,      // S8*  n (possible zero-padding)
38     Integer32,        // S32  4
39     Integer64,        // S64  8
40     Unsigned32,       // U32  4
41     Unsigned64,       // U64  8
42     Float32,          // F32  4
43     Float64,          // F64  8
44     Grouped,          // U32* 4*n
45     Address,          // S8*  4 (IPv4) or 16 (IPv6)
46     Time,             // S8*  4
47     UTF8String,       // S8*  n (possible zero-padding)
48     DiameterIdentity, // S8*  n (possible zero-padding)
49     DiameterURI,      // S8*  n (possible zero-padding)
50     Enumerated,       // S32  4
51     IPFilterRule,     // S8*  n (possible zero-padding)
52     QoSFilterRule     // S8*  n (possible zero-padding)
53   };
54
55   anna_declare_enum(diameter::codec::Format);
56
57   /**
58   * Format description
59   *
60   * @param v Format type
61   *
62   * @return Format description
63   */
64   static const char* asText(const Format::_v v) noexcept(false) {
65     return asCString(v);
66   }
67
68
69   /**
70   * Boolean about if format type is reserved (API internal use)
71   *
72   * @param formatName Format text name
73   *
74   * @return Boolean 'true' if reserved for internal use, 'false' if is user format type (RFC 3588 or application-specific)
75   */
76   static bool isReserved(const std::string & formatName) {
77     if(formatName == asText(Format::Unknown)) return true;
78
79     if(formatName == asText(Format::Any)) return true;
80
81     return false;
82   }
83
84
85   /**
86   * Boolean about if format type belongs to RFC 3588
87   * @param formatName Format text name
88   * @return Boolean 'true' if belongs to RFC 3588, 'false' if is application-specific)
89   */
90   static bool isRFC3588(const std::string & formatName) {
91     if(isReserved(formatName)) return false;
92
93     return (asEnum(formatName) != None);
94   }
95
96 };
97
98
99 }
100 }
101 }
102
103
104 #endif
105