BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlar_enumvtableutil.h
Go to the documentation of this file.
1/// @file bdlar_enumvtableutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlar_enumvtableutil.h -*-C++-*-
8#ifndef INCLUDED_BDLAR_ENUMVTABLEUTIL
9#define INCLUDED_BDLAR_ENUMVTABLEUTIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlar_enumvtableutil bdlar_enumvtableutil
15/// @brief Provide ...
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlar
19/// @{
20/// @addtogroup bdlar_enumvtableutil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlar_enumvtableutil-purpose"> Purpose</a>
25/// * <a href="#bdlar_enumvtableutil-classes"> Classes </a>
26/// * <a href="#bdlar_enumvtableutil-description"> Description </a>
27///
28/// # Purpose {#bdlar_enumvtableutil-purpose}
29/// Provide ...
30///
31/// # Classes {#bdlar_enumvtableutil-classes}
32///
33/// - bdlar::EnumVtableUtil: ...
34///
35/// # Description {#bdlar_enumvtableutil-description}
36/// This component provides ...
37///
38/// @}
39/** @} */
40/** @} */
41
42/** @addtogroup bdl
43 * @{
44 */
45/** @addtogroup bdlar
46 * @{
47 */
48/** @addtogroup bdlar_enumvtableutil
49 * @{
50 */
51
52#include <bdlar_enumvtable.h>
53
54#include <bdlat_enumfunctions.h>
55#include <bdlat_typename.h>
57
58
59namespace bdlar {
60
61 // ====================
62 // class EnumVtableUtil
63 // ====================
64
66 // PRIVATE CLASS METHODS
67
68 /// Load into the specified type erased enumerator `result` the enumerator
69 /// matching the specified `number`. Return 0 on success, and a non-zero
70 /// value with no effect on `result` if `number` does not match any
71 /// enumerator.
72 template <class t_ENUM>
73 static int fromInt(void *result, int number);
74
75 /// Load into the specified type erased enumerator `result` the enumerator
76 /// matching the specified `string` of the specified `stringLength`.
77 /// Return 0 on success, and a non-zero value with no effect on `result` if
78 /// `string` and `stringLength` do not match any enumerator.
79 template <class t_ENUM>
80 static int fromString(void *result, const char *string, int stringLength);
81
82 /// Return `true` if the specified type erased enumerator `t_ENUM` supports
83 /// a fallback enumerator, and `false` otherwise.
84 template <class t_ENUM>
85 static bool hasFallback(const void *value);
86
87 /// Return `true` if the specified type erased enumerator `value` is equal
88 /// to a fallback enumerator, and `false` otherwise.
89 template <class t_ENUM>
90 static bool isFallback(const void *value);
91
92 /// Load into the specified type erased enumerator `result` the fallback
93 /// enumerator value. Return 0 on success, and a non-zero value with no
94 /// effect on `result` if it does not have a fallback enumerator.
95 template <class t_ENUM>
96 static int makeFallback(void *result);
97
98 /// Reset the object pointed by the specified `object` to the default
99 /// value.
100 template <class t_ENUM>
101 static void reset(void *object);
102
103 /// Load into the specified `result` the string representation of the
104 /// enumerator value held by the specified type erased enumerator `value`.
105 template <class t_ENUM>
106 static void toInt(int *result, const void *value);
107
108 /// Load into the specified `result` the integer representation of the
109 /// enumerator value held by the specified type erased enumerator `value`.
110 template <class t_ENUM>
111 static void toString(bsl::string *result, const void *value);
112
113 /// Return the `bdlat_TypeName::xsdName` value for `object`.
114 template <class t_ENUM>
115 static const char *xsdName(const void *object, int format);
116
117 public:
118 // TYPES
121
122 // CLASS METHODS
123
124 /// Construct and return a `EnumConstVtable` object with a series of
125 /// function pointers that implement the "enum" type category.
126 template <class t_ENUM>
127 static const EnumConstVtable *getConstVtable();
128
129 /// Construct and return a `EnumVtable` object with a series of function
130 /// pointers that implement the "enum" type category.
131 template <class t_ENUM>
132 static const EnumVtable *getVtable();
133};
134
135// ============================================================================
136// INLINE DEFINITIONS
137// ============================================================================
138
139 // --------------------
140 // class EnumVtableUtil
141 // --------------------
142
143// PRIVATE CLASS METHODS
144template <class t_ENUM>
145int EnumVtableUtil::fromInt(void *result, int number)
146{
147 return bdlat_EnumFunctions::fromInt(static_cast<t_ENUM *>(result), number);
148}
149
150template <class t_ENUM>
151int EnumVtableUtil::fromString(void *result,
152 const char *string,
153 int stringLength)
154{
155 return bdlat_EnumFunctions::fromString(static_cast<t_ENUM *>(result),
156 string,
157 stringLength);
158}
159
160template <class t_ENUM>
161bool EnumVtableUtil::hasFallback(const void *value)
162{
164 *static_cast<const t_ENUM *>(value));
165}
166
167template <class t_ENUM>
168bool EnumVtableUtil::isFallback(const void *value)
169{
171 *static_cast<const t_ENUM *>(value));
172}
173
174template <class t_ENUM>
175int EnumVtableUtil::makeFallback(void *result)
176{
177 return bdlat_EnumFunctions::makeFallback(static_cast<t_ENUM *>(result));
178}
179
180template <class t_ENUM>
181void EnumVtableUtil::reset(void *object)
182{
183 bdlat_ValueTypeFunctions::reset(static_cast<t_ENUM *>(object));
184}
185
186template <class t_ENUM>
187void EnumVtableUtil::toInt(int *result, const void *value)
188{
189 bdlat_EnumFunctions::toInt(result, *static_cast<const t_ENUM *>(value));
190}
191
192template <class t_ENUM>
193void EnumVtableUtil::toString(bsl::string *result, const void *value)
194{
195 bdlat_EnumFunctions::toString(result, *static_cast<const t_ENUM *>(value));
196}
197
198template <class t_ENUM>
199const char *EnumVtableUtil::xsdName(const void *object, int format)
200{
201 return bdlat_TypeName::xsdName(*static_cast<const t_ENUM *>(object),
202 format);
203}
204
205// CLASS METHODS
206template <class t_ENUM>
208{
209 static const EnumConstVtable vtable = {
210 &toInt<t_ENUM>,
211 &toString<t_ENUM>,
212 &hasFallback<t_ENUM>,
213 &isFallback<t_ENUM>,
214 &xsdName<t_ENUM>
215 };
216 return &vtable;
217}
218
219template <class t_ENUM>
221{
222 static const EnumVtable vtable = {
223 {
224 &toInt<t_ENUM>,
225 &toString<t_ENUM>,
226 &hasFallback<t_ENUM>,
227 &isFallback<t_ENUM>,
228 &xsdName<t_ENUM>
229 },
230 &fromInt<t_ENUM>,
231 &fromString<t_ENUM>,
232 &makeFallback<t_ENUM>,
233 &reset<t_ENUM>
234 };
235 return &vtable;
236}
237
238} // close package namespace
239
240
241#endif
242
243// ----------------------------------------------------------------------------
244// Copyright 2024 Bloomberg Finance L.P.
245//
246// Licensed under the Apache License, Version 2.0 (the "License");
247// you may not use this file except in compliance with the License.
248// You may obtain a copy of the License at
249//
250// http://www.apache.org/licenses/LICENSE-2.0
251//
252// Unless required by applicable law or agreed to in writing, software
253// distributed under the License is distributed on an "AS IS" BASIS,
254// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
255// See the License for the specific language governing permissions and
256// limitations under the License.
257// ----------------------------- END-OF-FILE ----------------------------------
258
259/** @} */
260/** @} */
261/** @} */
Definition bdlar_enumvtableutil.h:65
EnumConstVtable ConstVtableType
Definition bdlar_enumvtableutil.h:120
EnumVtable VtableType
Definition bdlar_enumvtableutil.h:119
static const EnumVtable * getVtable()
Definition bdlar_enumvtableutil.h:220
static const EnumConstVtable * getConstVtable()
Definition bdlar_enumvtableutil.h:207
Definition bslstl_string.h:1252
static const char * xsdName(const TYPE &object, int format)
Definition bdlat_typename.h:1047
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlar_accessorref.h:59
void toInt(int *result, const TYPE &value)
int fromString(TYPE *result, const char *string, int stringLength)
int fromInt(TYPE *result, int number)
void toString(bsl::string *result, const TYPE &value)
int makeFallback(TYPE *result)
bool hasFallback(const TYPE &value)
bool isFallback(const TYPE &value)
void reset(TYPE *object)
Reset the value of the specified object to its default value.
Definition bdlar_enumvtable.h:67
Definition bdlar_enumvtable.h:92