BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsltf_movestate.h
Go to the documentation of this file.
1/// @file bsltf_movestate.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bsltf_movestate.h -*-C++-*-
8#ifndef INCLUDED_BSLTF_MOVESTATE
9#define INCLUDED_BSLTF_MOVESTATE
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bsltf_movestate bsltf_movestate
15/// @brief Provide an enumeration of move-state, including unsupported.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bsltf
19/// @{
20/// @addtogroup bsltf_movestate
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bsltf_movestate-purpose"> Purpose</a>
25/// * <a href="#bsltf_movestate-classes"> Classes </a>
26/// * <a href="#bsltf_movestate-description"> Description </a>
27/// * <a href="#bsltf_movestate-enumerators"> Enumerators </a>
28/// * <a href="#bsltf_movestate-usage"> Usage </a>
29/// * <a href="#bsltf_movestate-example-1-basic-syntax"> Example 1: Basic Syntax </a>
30///
31/// # Purpose {#bsltf_movestate-purpose}
32/// Provide an enumeration of move-state, including unsupported.
33///
34/// # Classes {#bsltf_movestate-classes}
35///
36/// - bsltf::MoveState: namespace for move-state enumeration
37///
38/// @see bsltf_copystate
39///
40/// # Description {#bsltf_movestate-description}
41/// This component provides a `struct`, `bsltf_MoveState`, which
42/// serves as a namespace for enumerating the move-state of an object, including
43/// an unknown value indicating that the test type does not support tracking
44/// of this information. An object is involved in a move operation if that
45/// object was either the source or target of a move construction or move
46/// assignment. It's up to the test type to support moved-into or moved-from
47/// or both using separate instances of this enum.
48///
49/// ## Enumerators {#bsltf_movestate-enumerators}
50///
51///
52/// @code
53/// Name Description
54/// ----------- -------------------------------------------------------------
55/// e_NOT_MOVED The type was not involved in a move operation.
56///
57/// e_MOVED The type was involved in a move operation.
58///
59/// e_UNKNOWN The type does not expose move-state infromation.
60/// @endcode
61/// When converted to `bool`, `e_NOT_MOVED` yields `false` whereas the rest
62/// yield `true`. When `e_UNKNOWN` is not expected, this conversion makes it
63/// easy to check a value for the binary copied/not-copied attribute.
64///
65/// ## Usage {#bsltf_movestate-usage}
66///
67///
68/// This section illustrates intended use of this component.
69///
70/// ### Example 1: Basic Syntax {#bsltf_movestate-example-1-basic-syntax}
71///
72///
73/// The following snippets of code provide a simple illustration of using
74/// `bsltf::MoveState`.
75///
76/// First, we create a variable `value` of type `bsltf::MoveState::Enum`
77/// and initialize it with the enumerator value
78/// `bsltf::MoveState::e_MOVED`:
79/// @code
80/// bsltf::MoveState::Enum value = bsltf::MoveState::e_MOVED;
81/// @endcode
82/// Now, we store the address of its ASCII representation in a pointer variable,
83/// `asciiValue`, of type `const char *`:
84/// @code
85/// const char *asciiValue = bsltf::MoveState::toAscii(value);
86/// @endcode
87/// Finally, we verify the value of `asciiValue`:
88/// @code
89/// assert(0 == strcmp(asciiValue, "MOVED"));
90/// @endcode
91/// @}
92/** @} */
93/** @} */
94
95/** @addtogroup bsl
96 * @{
97 */
98/** @addtogroup bsltf
99 * @{
100 */
101/** @addtogroup bsltf_movestate
102 * @{
103 */
104
105#include <bslscm_version.h>
106
107#include <bsltf_copymovestate.h>
108
109#include <cstdio> // for 'std::printf'
110
111
112namespace bsltf {
113
114struct MoveState {
115 public:
116 // TYPES
117
118 /// Enumeration of move state.
119 enum Enum {
120 e_NOT_MOVED, // The type was not involved in a move operation.
121
122 e_MOVED, // The type was involved in a move operation.
123
124 e_UNKNOWN // The type does not expose move-state information.
125 };
126
127 public:
128 // CLASS METHOD
129
130 /// Return the non-modifiable string representation corresponding to the
131 /// specified enumeration `value`, if it exists, and a unique (error)
132 /// string otherwise. The string representation of `value` matches its
133 /// corresponding enumerator name with the "e_" prefix elided. For
134 /// example:
135 /// @code
136 /// bsl::cout << MoveState::toAscii(MoveState::e_MOVED);
137 /// @endcode
138 /// will print the following on standard output:
139 /// @code
140 /// MOVED
141 /// @endcode
142 /// Note that specifying a `value` that does not match any of the
143 /// enumerators will result in a string representation that is distinct
144 /// from any of those corresponding to the enumerators, but is otherwise
145 /// unspecified.
146 static const char *toAscii(MoveState::Enum value);
147
148};
149
150// FREE FUNCTIONS
151
152/// Print the specified `value` as a string.
153void debugprint(const MoveState::Enum& value);
154
155/// Return the moved-from state of the specified `object` of (template
156/// parameter) `TYPE`. The default implementation of this ADL customization
157/// point calls `CopyMoveState::get` and translates the result into the
158/// correpsonding `MoveState::Enum` (which has been deprecated). Note that
159/// a customization of this function for a specific type will not be
160/// "inherited" by derived classes of that type; new types should customize
161/// `copyMoveState`, not `getMovedFrom`.
162///
163/// @deprecated Use @ref CopyMoveState::isMovedFrom` or `CopyMoveState::get.
164template <class TYPE>
165MoveState::Enum getMovedFrom(const TYPE& object);
166
167/// Return the moved-from state of the specified `object` of (template
168/// parameter) `TYPE`. The default implementation of this ADL customization
169/// point calls `CopyMoveState::get` and translates the result into the
170/// correpsonding `MoveState::Enum`. Note that a customization of this
171/// function for a specific type will not be "inherited" by derived classes
172/// of that type; new types should customize `copyMoveState`, not
173/// `getMovedInto`.
174///
175/// @deprecated Use @ref CopyMoveState::isMovedInto` or `CopyMoveState::get.
176template <class TYPE>
177MoveState::Enum getMovedInto(const TYPE& object);
178
179/// Set the moved-into state of the specified `object` to the specified
180/// `value`. The default implementation of this ADL customization point
181/// calls `CopyMoveState::set` and translates `value` into the correpsonding
182/// `CopyMoveState::Enum`. Note that a customization of this function for a
183/// specific type will not be "inherited" by derived classes of that type;
184/// new types should customize `setCopyMoveState`, not `setMovedInto`.
185///
186/// @deprecated Use @ref CopyMoveState::set instead.
187template <class TYPE>
188void setMovedInto(TYPE *object, MoveState::Enum value);
189
190} // close package namespace
191
192// ============================================================================
193// INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
194// ============================================================================
195
196// FREE FUNCTIONS
197template <class TYPE>
198inline bsltf::MoveState::Enum bsltf::getMovedFrom(const TYPE& object)
199{
200 return (CopyMoveState::isUnknown(object) ? MoveState::e_UNKNOWN :
201 CopyMoveState::isMovedFrom(object) ? MoveState::e_MOVED :
202 MoveState::e_NOT_MOVED);
203}
204
205template <class TYPE>
206inline bsltf::MoveState::Enum bsltf::getMovedInto(const TYPE& object)
207{
208 return (CopyMoveState::isUnknown(object) ? MoveState::e_UNKNOWN :
209 CopyMoveState::isMovedInto(object) ? MoveState::e_MOVED :
210 MoveState::e_NOT_MOVED);
211}
212
213template <class TYPE>
214void bsltf::setMovedInto(TYPE *object, bsltf::MoveState::Enum value)
215{
216 CopyMoveState::Enum cms = CopyMoveState::e_UNKNOWN;
217
218 switch (value)
219 {
220 case MoveState::e_NOT_MOVED: cms = CopyMoveState::e_ORIGINAL; break;
221 case MoveState::e_MOVED: cms = CopyMoveState::e_MOVED_INTO; break;
222 case MoveState::e_UNKNOWN: cms = CopyMoveState::e_UNKNOWN; break;
223 }
224
225 CopyMoveState::set(object, cms);
226}
227
228/// Print the specified `value` as a string.
229inline void bsltf::debugprint(const bsltf::MoveState::Enum& value)
230{
231 std::printf("%s", MoveState::toAscii(value));
232}
233
234
235
236#endif
237
238// ----------------------------------------------------------------------------
239// Copyright 2018 Bloomberg Finance L.P.
240//
241// Licensed under the Apache License, Version 2.0 (the "License");
242// you may not use this file except in compliance with the License.
243// You may obtain a copy of the License at
244//
245// http://www.apache.org/licenses/LICENSE-2.0
246//
247// Unless required by applicable law or agreed to in writing, software
248// distributed under the License is distributed on an "AS IS" BASIS,
249// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
250// See the License for the specific language governing permissions and
251// limitations under the License.
252// ----------------------------- END-OF-FILE ----------------------------------
253
254/** @} */
255/** @} */
256/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bsltf_allocargumenttype.h:92
void debugprint(const ArgumentType< N > &object)
Definition bsltf_argumenttype.h:551
MoveState::Enum getMovedInto(const AllocArgumentType< N > &object)
Return the move-into state of the specified object.
Definition bsltf_allocargumenttype.h:413
void setMovedInto(MovableTestType *object, MoveState::Enum value)
Definition bsltf_movabletesttype.h:306
MoveState::Enum getMovedFrom(const AllocArgumentType< N > &object)
Return the move-from state of the specified object.
Definition bsltf_allocargumenttype.h:406
Definition bsltf_movestate.h:114
static const char * toAscii(MoveState::Enum value)
Enum
Enumeration of move state.
Definition bsltf_movestate.h:119
@ e_UNKNOWN
Definition bsltf_movestate.h:124
@ e_NOT_MOVED
Definition bsltf_movestate.h:120
@ e_MOVED
Definition bsltf_movestate.h:122