BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlat_choicefunctions.h
Go to the documentation of this file.
1/// @file bdlat_choicefunctions.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlat_choicefunctions.h -*-C++-*-
8#ifndef INCLUDED_BDLAT_CHOICEFUNCTIONS
9#define INCLUDED_BDLAT_CHOICEFUNCTIONS
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlat_choicefunctions bdlat_choicefunctions
15/// @brief Provide a namespace defining choice functions.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlat
19/// @{
20/// @addtogroup bdlat_choicefunctions
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlat_choicefunctions-purpose"> Purpose</a>
25/// * <a href="#bdlat_choicefunctions-classes"> Classes </a>
26/// * <a href="#bdlat_choicefunctions-description"> Description </a>
27/// * <a href="#bdlat_choicefunctions-usage"> Usage </a>
28/// * <a href="#bdlat_choicefunctions-example-1-basic-usage"> Example 1: Basic Usage </a>
29///
30/// # Purpose {#bdlat_choicefunctions-purpose}
31/// Provide a namespace defining choice functions.
32///
33/// # Classes {#bdlat_choicefunctions-classes}
34///
35/// - bdlat_ChoiceFunctions: namespace for calling choice functions
36///
37/// @see bdlat_selectioninfo
38///
39/// # Description {#bdlat_choicefunctions-description}
40/// The `bdlat_ChoiceFunctions` `namespace` provided in this
41/// component defines parameterized functions that expose "choice" behavior for
42/// "choice" types. See the {`bdlat`} package-level documentation for a full
43/// description of "choice" types.
44///
45/// The functions in this namespace allow users to:
46/// * make a selection using either a selection id or a selection name
47/// (`makeSelection`),
48/// * manipulate the current selection using a parameterized manipulator
49/// (`manipulateSelection`),
50/// * access the current selection using a parameterized accessor
51/// (`accessSelection`), and
52/// * obtain the id for the current selection (`selectionId`).
53///
54/// Also, the meta-function `IsChoice` contains a compile-time constant `value`
55/// that is non-zero if the parameterized `TYPE` exposes "choice" behavior
56/// through the `bdlat_ChoiceFunctions` `namespace`.
57///
58/// This component specializes all of these functions for types that have the
59/// `bdlat_TypeTraitBasicChoice` trait.
60///
61/// Types that do not have the `bdlat_TypeTraitBasicChoice` trait can be plugged
62/// into the `bdlat` framework. This is done by overloading the `bdlat_choice*`
63/// functions inside the namespace of the plugged in type. For example, suppose
64/// there is a type called `mine::MyChoice`. In order to plug this type into
65/// the `bdlat` framework as a "Choice", the following functions must be
66/// declared and implemented in the `mine` namespace:
67/// @code
68/// namespace mine {
69///
70/// // MANIPULATORS
71/// int bdlat_choiceMakeSelection(MyChoice *object, int selectionId);
72/// // Set the value of the specified 'object' to be the default for
73/// // the selection indicated by the specified 'selectionId'. Return
74/// // 0 on success, and non-zero value otherwise (i.e., the selection
75/// // is not found).
76///
77/// int bdlat_choiceMakeSelection(MyChoice *object,
78/// const char *selectionName,
79/// int selectionNameLength);
80/// // Set the value of the specified 'object' to be the default for
81/// // the selection indicated by the specified 'selectionName' of the
82/// // specified 'selectionNameLength'. Return 0 on success, and
83/// // non-zero value otherwise (i.e., the selection is not found).
84///
85/// template <typename MANIPULATOR>
86/// int bdlat_choiceManipulateSelection(MyChoice *object,
87/// MANIPULATOR& manipulator);
88/// // Invoke the specified 'manipulator' on the address of the
89/// // (modifiable) selection of the specified 'object', supplying
90/// // 'manipulator' with the corresponding selection information
91/// // structure. Return -1 if the selection is undefined, and the
92/// // value returned from the invocation of 'manipulator' otherwise.
93///
94/// // ACCESSORS
95/// template <typename ACCESSOR>
96/// int bdlat_choiceAccessSelection(const MyChoice& object,
97/// ACCESSOR& accessor);
98/// // Invoke the specified 'accessor' on the (non-modifiable)
99/// // selection of the specified 'object', supplying 'accessor' with
100/// // the corresponding selection information structure. Return -1 if
101/// // the selection is undefined, and the value returned from the
102/// // invocation of 'accessor' otherwise.
103///
104/// int bdlat_choiceSelectionId(const MyChoice& object);
105/// // Return the id of the current selection if the selection is
106/// // defined, and 0 otherwise.
107///
108/// } // close namespace 'mine'
109/// @endcode
110/// Also, the `IsChoice` meta-function must be specialized for the
111/// `mine::MyChoice` type in the `bdlat_ChoiceFunctions` namespace.
112///
113/// ## Usage {#bdlat_choicefunctions-usage}
114///
115///
116/// This section illustrates intended use of this component.
117///
118/// ### Example 1: Basic Usage {#bdlat_choicefunctions-example-1-basic-usage}
119///
120///
121/// Suppose you had a `union` embedded inside a `struct`. The `struct` also
122/// contains a `d_selectionId` member that specifies which member of the `union`
123/// is selected. The default constructor of the `struct` makes the selection
124/// undefined:
125/// @code
126/// namespace BloombergLP {
127///
128/// namespace mine {
129///
130/// struct MyChoice {
131/// // This struct represents a choice between a 'char' value, an 'int'
132/// // value, and a 'float' value.
133///
134/// // CONSTANTS
135/// enum {
136/// UNDEFINED_SELECTION_ID = -1,
137/// CHAR_SELECTION_ID = 0,
138/// INT_SELECTION_ID = 1,
139/// FLOAT_SELECTION_ID = 2
140/// };
141///
142/// // DATA MEMBERS
143/// union {
144/// char d_charValue;
145/// int d_intValue;
146/// float d_floatValue;
147/// };
148/// int d_selectionId;
149///
150/// // CREATORS
151/// MyChoice()
152/// : d_selectionId(UNDEFINED_SELECTION_ID)
153/// {
154/// }
155/// };
156/// @endcode
157/// We can now make `MyChoice` expose "choice" behavior by implementing
158/// `bdlat_ChoiceFunctions` for `MyChoice`. First, we should forward declare
159/// all the functions that we will implement inside the `mine` namespace:
160/// @code
161/// // MANIPULATORS
162/// int bdlat_choiceMakeSelection(MyChoice *object, int selectionId);
163/// // Set the value of the specified 'object' to be the default for the
164/// // selection indicated by the specified 'selectionId'. Return 0 on
165/// // success, and non-zero value otherwise (i.e., the selection is not
166/// // found).
167///
168/// int bdlat_choiceMakeSelection(MyChoice *object,
169/// const char *selectionName,
170/// int selectionNameLength);
171/// // Set the value of the specified 'object' to be the default for the
172/// // selection indicated by the specified 'selectionName' of the
173/// // specified 'selectionNameLength'. Return 0 on success, and non-zero
174/// // value otherwise (i.e., the selection is not found).
175///
176/// template <class MANIPULATOR>
177/// int bdlat_choiceManipulateSelection(MyChoice *object,
178/// MANIPULATOR& manipulator);
179/// // Invoke the specified 'manipulator' on the address of the
180/// // (modifiable) selection of the specified 'object', supplying
181/// // 'manipulator' with the corresponding selection information
182/// // structure. Return -1 if the selection is undefined, and the value
183/// // returned from the invocation of 'manipulator' otherwise.
184///
185/// // ACCESSORS
186/// template <class ACCESSOR>
187/// int bdlat_choiceAccessSelection(const MyChoice& object,
188/// ACCESSOR& accessor);
189/// // Invoke the specified 'accessor' on the (non-modifiable) selection of
190/// // the specified 'object', supplying 'accessor' with the corresponding
191/// // selection information structure. Return -1 if the selection is
192/// // undefined, and the value returned from the invocation of 'accessor'
193/// // otherwise.
194///
195/// int bdlat_choiceSelectionId(const MyChoice& object);
196/// // Return the id of the current selection if the selection is defined,
197/// // and 0 otherwise.
198///
199/// } // close namespace mine
200/// @endcode
201/// Now, we provide the definitions for each of these functions:
202/// @code
203/// // MANIPULATORS
204/// int mine::bdlat_choiceMakeSelection(MyChoice *object,
205/// int selectionId)
206/// {
207/// enum { SUCCESS = 0, NOT_FOUND = -1 };
208///
209/// switch (selectionId) {
210/// case MyChoice::CHAR_SELECTION_ID: {
211/// object->d_selectionId = selectionId;
212/// object->d_charValue = 0;
213///
214/// return SUCCESS; // RETURN
215/// }
216/// case MyChoice::INT_SELECTION_ID: {
217/// object->d_selectionId = selectionId;
218/// object->d_intValue = 0;
219///
220/// return SUCCESS; // RETURN
221/// }
222/// case MyChoice::FLOAT_SELECTION_ID: {
223/// object->d_selectionId = selectionId;
224/// object->d_floatValue = 0;
225///
226/// return SUCCESS; // RETURN
227/// }
228/// case MyChoice::UNDEFINED_SELECTION_ID: {
229/// object->d_selectionId = selectionId;
230///
231/// return SUCCESS; // RETURN
232/// }
233/// default: {
234/// return NOT_FOUND; // RETURN
235/// }
236/// }
237/// }
238///
239/// int mine::bdlat_choiceMakeSelection(MyChoice *object,
240/// const char *selectionName,
241/// int selectionNameLength)
242/// {
243/// enum { NOT_FOUND = -1 };
244///
245/// if (bdlb::String::areEqualCaseless("charValue",
246/// selectionName,
247/// selectionNameLength)) {
248/// return bdlat_choiceMakeSelection(object,
249/// MyChoice::CHAR_SELECTION_ID);
250/// // RETURN
251/// }
252///
253/// if (bdlb::String::areEqualCaseless("intValue",
254/// selectionName,
255/// selectionNameLength)) {
256/// return bdlat_choiceMakeSelection(object,
257/// MyChoice::INT_SELECTION_ID);
258/// // RETURN
259/// }
260///
261/// if (bdlb::String::areEqualCaseless("floatValue",
262/// selectionName,
263/// selectionNameLength)) {
264/// return bdlat_choiceMakeSelection(object,
265/// MyChoice::FLOAT_SELECTION_ID);
266/// // RETURN
267/// }
268///
269/// return NOT_FOUND;
270/// }
271/// @endcode
272/// For the `manipulateSelection` and `accessSelection` functions, we need to
273/// create a temporary `bdlat_SelectionInfo` object and pass it along when
274/// invoking the manipulator or accessor. See the @ref bdlat_selectioninfo
275/// component-level documentation for more information. The implementation of
276/// the remaining functions are as follows:
277/// @code
278/// template <class MANIPULATOR>
279/// int mine::bdlat_choiceManipulateSelection(MyChoice *object,
280/// MANIPULATOR& manipulator)
281/// {
282/// switch (object->d_selectionId) {
283/// case MyChoice::CHAR_SELECTION_ID: {
284/// bdlat_SelectionInfo info;
285///
286/// info.annotation() = "Char Selection";
287/// info.formattingMode() = bdlat_FormattingMode::e_DEFAULT;
288/// info.id() = MyChoice::CHAR_SELECTION_ID;
289/// info.name() = "charValue";
290/// info.nameLength() = 9;
291///
292/// return manipulator(&object->d_charValue, info); // RETURN
293/// }
294/// case MyChoice::INT_SELECTION_ID: {
295/// bdlat_SelectionInfo info;
296///
297/// info.annotation() = "Int Selection";
298/// info.formattingMode() = bdlat_FormattingMode::e_DEFAULT;
299/// info.id() = MyChoice::INT_SELECTION_ID;
300/// info.name() = "intValue";
301/// info.nameLength() = 8;
302///
303/// return manipulator(&object->d_intValue, info); // RETURN
304/// }
305/// case MyChoice::FLOAT_SELECTION_ID: {
306/// bdlat_SelectionInfo info;
307///
308/// info.annotation() = "Float Selection";
309/// info.formattingMode() = bdlat_FormattingMode::e_DEFAULT;
310/// info.id() = MyChoice::FLOAT_SELECTION_ID;
311/// info.name() = "floatValue";
312/// info.nameLength() = 10;
313///
314/// return manipulator(&object->d_floatValue, info); // RETURN
315/// }
316/// default:
317/// BSLS_ASSERT_SAFE(0 == "Invalid selection!");
318/// }
319/// return 0;
320/// }
321///
322/// // ACCESSORS
323///
324/// template <class ACCESSOR>
325/// int mine::bdlat_choiceAccessSelection(const MyChoice& object,
326/// ACCESSOR& accessor)
327/// {
328/// switch (object.d_selectionId) {
329/// case MyChoice::CHAR_SELECTION_ID: {
330/// bdlat_SelectionInfo info;
331///
332/// info.annotation() = "Char Selection";
333/// info.formattingMode() = bdlat_FormattingMode::e_DEFAULT;
334/// info.id() = MyChoice::CHAR_SELECTION_ID;
335/// info.name() = "charValue";
336/// info.nameLength() = 9;
337///
338/// return accessor(object.d_charValue, info); // RETURN
339/// }
340/// case MyChoice::INT_SELECTION_ID: {
341/// bdlat_SelectionInfo info;
342///
343/// info.annotation() = "Int Selection";
344/// info.formattingMode() = bdlat_FormattingMode::e_DEFAULT;
345/// info.id() = MyChoice::INT_SELECTION_ID;
346/// info.name() = "intValue";
347/// info.nameLength() = 8;
348///
349/// return accessor(object.d_intValue, info); // RETURN
350/// }
351/// case MyChoice::FLOAT_SELECTION_ID: {
352/// bdlat_SelectionInfo info;
353///
354/// info.annotation() = "Float Selection";
355/// info.formattingMode() = bdlat_FormattingMode::e_DEFAULT;
356/// info.id() = MyChoice::FLOAT_SELECTION_ID;
357/// info.name() = "floatValue";
358/// info.nameLength() = 10;
359///
360/// return accessor(object.d_floatValue, info); // RETURN
361/// }
362/// default:
363/// BSLS_ASSERT_SAFE(0 == "Invalid selection!");
364/// }
365/// return 0;
366/// }
367///
368/// int mine::bdlat_choiceSelectionId(const MyChoice& object)
369/// {
370/// return object.d_selectionId;
371/// }
372/// @endcode
373/// Finally, we need to specialize the `IsChoice` meta-function in the
374/// `bdlat_ChoiceFunctions` namespace for the `mine::MyChoice` type. This makes
375/// the `bdlat` infrastructure recognize `mine::MyChoice` as a choice
376/// abstraction:
377/// @code
378/// namespace bdlat_ChoiceFunctions {
379///
380/// template <>
381/// struct IsChoice<mine::MyChoice> : bsl::true_type {
382/// };
383///
384/// } // close namespace bdlat_ChoiceFunctions
385/// } // close enterprise namespace
386/// @endcode
387/// The `bdlat` infrastructure (and any component that uses this infrastructure)
388/// will now recognize `MyChoice` as a "choice" type. For example, suppose we
389/// have the following XML data:
390/// @code
391/// <?xml version='1.0' encoding='UTF-8' ?>
392/// <MyChoice>
393/// <intValue>321</intValue>
394/// </MyChoice>
395/// @endcode
396/// Using the @ref balxml_decoder component, we can load this XML data into a
397/// `MyChoice` object:
398/// @code
399/// void usageExample(bsl::istream& inputData)
400/// {
401/// using namespace BloombergLP;
402///
403/// MyChoice object;
404///
405/// assert(MyChoice::UNDEFINED_SELECTION_ID == object.d_selectionId);
406///
407/// balxml::DecoderOptions options;
408/// balxml::MiniReader reader;
409/// balxml::ErrorInfo errInfo;
410///
411/// balxml::Decoder decoder(&options, &reader, &errInfo);
412/// int result = decoder.decode(inputData, &object);
413///
414/// assert(0 == result);
415/// assert(MyChoice::INT_SELECTION_ID == object.d_selectionId);
416/// assert(321 == object.d_intValue);
417/// }
418/// @endcode
419/// Note that the `bdlat` framework can be used for functionality other than
420/// encoding/decoding into XML. When `mine::MyChoice` is plugged into the
421/// framework, then it will be automatically usable within the framework. For
422/// example, the following snippets of code will print out the selection value
423/// of a choice object:
424/// @code
425/// struct PrintSelection {
426/// // Print each visited object to the bound 'd_stream_p' object.
427///
428/// // DATA MEMBERS
429/// bsl::ostream *d_stream_p;
430///
431/// template <class TYPE, class INFO>
432/// int operator()(const TYPE& object, const INFO& info)
433/// {
434/// (*d_stream_p) << info.name() << ": " << object << bsl::endl;
435/// return 0; // RETURN
436/// }
437/// };
438///
439/// template <class TYPE>
440/// void printChoiceSelection(bsl::ostream& stream, const TYPE& object)
441/// {
442/// using namespace BloombergLP;
443///
444/// PrintSelection accessor;
445/// accessor.d_stream_p = &stream;
446///
447/// bdlat_choiceAccessSelection(object, accessor);
448/// }
449/// @endcode
450/// Now we have a generic function that takes an output stream and a choice
451/// object, and prints out each choice seletion with its name and value. We can
452/// use this generic function as follows:
453/// @code
454/// void printMyChoice(bsl::ostream& stream)
455/// {
456/// using namespace BloombergLP;
457///
458/// mine::MyChoice object;
459///
460/// object.d_selectionId = mine::MyChoice::INT_SELECTION_ID;
461/// object.d_intValue = 321;
462///
463/// printChoiceSelection(stream, object);
464/// }
465/// @endcode
466/// The function above will print the following to provided stream:
467/// @code
468/// intValue: 321
469/// @endcode
470/// @}
471/** @} */
472/** @} */
473
474/** @addtogroup bdl
475 * @{
476 */
477/** @addtogroup bdlat
478 * @{
479 */
480/** @addtogroup bdlat_choicefunctions
481 * @{
482 */
483
484#include <bdlscm_version.h>
485
486#include <bdlat_bdeatoverrides.h>
487#include <bdlat_selectioninfo.h>
488#include <bdlat_typetraits.h>
489
490#include <bslalg_hastrait.h>
491
492#include <bslmf_assert.h>
494
495#include <bsls_assert.h>
496#include <bsls_platform.h>
497
498
499
500 // ===============================
501 // namespace bdlat_ChoiceFunctions
502 // ===============================
503
505 // This 'namespace' provides functions that expose "choice" behavior for
506 // "choice" types. See the component-level documentation for more
507 // information.
508
509 // CONSTANTS
510 enum {
511 k_UNDEFINED_SELECTION_ID = -1 // indicates selection not made
512
513#ifndef BDE_OMIT_INTERNAL_DEPRECATED
516#endif // BDE_OMIT_INTERNAL_DEPRECATED
517 };
518
519 // META-FUNCTIONS
520
521 /// This `struct` should be specialized for third-party types that need
522 /// to expose "choice" behavior. See the component-level documentation
523 /// for further information.
524 template <class TYPE>
525 struct IsChoice
526 : public bsl::integral_constant<
527 bool,
528 bslalg::HasTrait<TYPE, bdlat_TypeTraitBasicChoice>::value> {
529 };
530
531 // MANIPULATORS
532
533 /// Set the value of the specified `object` to be the default for the
534 /// selection indicated by the specified `selectionId`. Return 0 on
535 /// success, and non-zero value otherwise (i.e., the selection is not
536 /// found).
537 template <class TYPE>
538 int makeSelection(TYPE *object, int selectionId);
539
540 /// Set the value of the specified `object` to be the default for the
541 /// selection indicated by the specified `selectionName` of the
542 /// specified `selectionNameLength`. Return 0 on success, and non-zero
543 /// value otherwise (i.e., the selection is not found).
544 template <class TYPE>
545 int makeSelection(TYPE *object,
546 const char *selectionName,
547 int selectionNameLength);
548
549 /// Invoke the specified `manipulator` on the address of the
550 /// (modifiable) selection of the specified `object`, supplying
551 /// `manipulator` with the corresponding selection information
552 /// structure. Return the value returned from the invocation of
553 /// `manipulator`. The behavior is undefined unless
554 /// `k_UNDEFINED_SELECTION_ID != selectionId(*object)`.
555 template <class TYPE, class MANIPULATOR>
556 int manipulateSelection(TYPE *object, MANIPULATOR& manipulator);
557
558 // ACCESSORS
559
560 /// Invoke the specified `accessor` on the (non-modifiable) selection of
561 /// the specified `object`, supplying `accessor` with the corresponding
562 /// selection information structure. Return the value returned from the
563 /// invocation of `accessor`. The behavior is undefined unless
564 /// `k_UNDEFINED_SELECTION_ID != selectionId(object)`.
565 template <class TYPE, class ACCESSOR>
566 int accessSelection(const TYPE& object, ACCESSOR& accessor);
567
568 /// Return true if the specified `object` has a selection with the
569 /// specified `selectionName` of the specified `selectionNameLength`,
570 /// and false otherwise.
571 template <class TYPE>
572 bool hasSelection(const TYPE& object,
573 const char *selectionName,
574 int selectionNameLength);
575
576 /// Return true if the specified `object` has a selection with the
577 /// specified `selectionId`, and false otherwise.
578 template <class TYPE>
579 bool hasSelection(const TYPE& object,
580 int selectionId);
581
582 /// Return the id of the current selection if the selection is defined,
583 /// and k_UNDEFINED_SELECTION_ID otherwise.
584 template <class TYPE>
585 int selectionId(const TYPE& object);
586
587} // close namespace bdlat_ChoiceFunctions
588
589 // ====================
590 // default declarations
591 // ====================
592
593namespace bdlat_ChoiceFunctions {
594 // This namespace declaration adds the default implementations of the
595 // "choice" customization-point functions to 'bdlat_ChoiceFunctions'. These
596 // default implementations assume the type of the acted-upon object is a
597 // basic-choice type. For more information about basic-choice types, see
598 // @ref bdlat_typetraits .
599
600 // MANIPULATORS
601 template <class TYPE>
603
604 template <class TYPE>
606 const char *selectionName,
607 int selectionNameLength);
608
609 template <class TYPE, class MANIPULATOR>
611 MANIPULATOR& manipulator);
612
613 // ACCESSORS
614 template <class TYPE, class ACCESSOR>
615 int bdlat_choiceAccessSelection(const TYPE& object, ACCESSOR& accessor);
616
617 template <class TYPE>
618 bool bdlat_choiceHasSelection(const TYPE& object,
619 const char *selectionName,
620 int selectionNameLength);
621
622 template <class TYPE>
623 bool bdlat_choiceHasSelection(const TYPE& object,
624 int selectionId);
625
626 template <class TYPE>
627 int bdlat_choiceSelectionId(const TYPE& object);
628
629} // close namespace bdlat_ChoiceFunctions
630
631// ============================================================================
632// INLINE FUNCTION DEFINITIONS
633// ============================================================================
634
635 // -------------------------------
636 // namespace bdlat_ChoiceFunctions
637 // -------------------------------
638
639// MANIPULATORS
640template <class TYPE>
641inline
642int bdlat_ChoiceFunctions::makeSelection(TYPE *object, int selectionId)
643{
644 return bdlat_choiceMakeSelection(object, selectionId);
645}
646
647template <class TYPE>
648inline
650 const char *selectionName,
651 int selectionNameLength)
652{
653 return bdlat_choiceMakeSelection(object,
654 selectionName,
655 selectionNameLength);
656}
657
658template <class TYPE, class MANIPULATOR>
659inline
661 MANIPULATOR& manipulator)
662{
663 BSLS_ASSERT_SAFE(k_UNDEFINED_SELECTION_ID
664 != bdlat_choiceSelectionId(*object));
665
666 return bdlat_choiceManipulateSelection(object, manipulator);
667}
668
669// ACCESSORS
670template <class TYPE, class ACCESSOR>
671inline
672int bdlat_ChoiceFunctions::accessSelection(const TYPE& object,
673 ACCESSOR& accessor)
674{
675 BSLS_ASSERT_SAFE(k_UNDEFINED_SELECTION_ID
676 != bdlat_choiceSelectionId(object));
677
678 return bdlat_choiceAccessSelection(object, accessor);
679}
680
681template <class TYPE>
682inline
683bool bdlat_ChoiceFunctions::hasSelection(const TYPE& object,
684 const char *selectionName,
685 int selectionNameLength)
686{
687 return bdlat_choiceHasSelection(object,
688 selectionName,
689 selectionNameLength);
690}
691
692template <class TYPE>
693inline
694bool bdlat_ChoiceFunctions::hasSelection(const TYPE& object,
695 int selectionId)
696{
697 return bdlat_choiceHasSelection(object, selectionId);
698}
699
700template <class TYPE>
701inline
702int bdlat_ChoiceFunctions::selectionId(const TYPE& object)
703{
704 return bdlat_choiceSelectionId(object);
705}
706
707 // -------------------
708 // default definitions
709 // -------------------
710
711// MANIPULATORS
712template <class TYPE>
713inline
715 int selectionId)
716{
718
719 return object->makeSelection(selectionId);
720}
721
722template <class TYPE>
723inline
725 TYPE *object,
726 const char *selectionName,
727 int selectionNameLength)
728{
730
731 return object->makeSelection(selectionName, selectionNameLength);
732}
733
734template <class TYPE, class MANIPULATOR>
735inline
737 TYPE *object,
738 MANIPULATOR& manipulator)
739{
741
742 return object->manipulateSelection(manipulator);
743}
744
745// ACCESSORS
746template <class TYPE, class ACCESSOR>
747inline
749 ACCESSOR& accessor)
750{
752
753 return object.accessSelection(accessor);
754}
755
756template <class TYPE>
757inline
759 const TYPE& object,
760 const char *selectionName,
761 int selectionNameLength)
762{
764
765 return 0 != object.lookupSelectionInfo(selectionName, selectionNameLength);
766}
767
768template <class TYPE>
769inline
771 int selectionId)
772{
774
775 return 0 != object.lookupSelectionInfo(selectionId);
776}
777
778template <class TYPE>
779inline
781{
783
784 return object.selectionId();
785}
786
787
788
789#endif
790
791// ----------------------------------------------------------------------------
792// Copyright 2015 Bloomberg Finance L.P.
793//
794// Licensed under the Apache License, Version 2.0 (the "License");
795// you may not use this file except in compliance with the License.
796// You may obtain a copy of the License at
797//
798// http://www.apache.org/licenses/LICENSE-2.0
799//
800// Unless required by applicable law or agreed to in writing, software
801// distributed under the License is distributed on an "AS IS" BASIS,
802// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
803// See the License for the specific language governing permissions and
804// limitations under the License.
805// ----------------------------- END-OF-FILE ----------------------------------
806
807/** @} */
808/** @} */
809/** @} */
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:229
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlat_choicefunctions.h:504
int bdlat_choiceSelectionId(const TYPE &object)
bool hasSelection(const TYPE &object, const char *selectionName, int selectionNameLength)
int bdlat_choiceManipulateSelection(TYPE *object, MANIPULATOR &manipulator)
int manipulateSelection(TYPE *object, MANIPULATOR &manipulator)
bool bdlat_choiceHasSelection(const TYPE &object, const char *selectionName, int selectionNameLength)
int bdlat_choiceMakeSelection(TYPE *object, int selectionId)
int makeSelection(TYPE *object, int selectionId)
int accessSelection(const TYPE &object, ACCESSOR &accessor)
@ BDEAT_UNDEFINED_SELECTION_ID
Definition bdlat_choicefunctions.h:515
@ k_UNDEFINED_SELECTION_ID
Definition bdlat_choicefunctions.h:511
@ UNDEFINED_SELECTION_ID
Definition bdlat_choicefunctions.h:514
int bdlat_choiceAccessSelection(const TYPE &object, ACCESSOR &accessor)
int selectionId(const TYPE &object)
Definition bdlat_choicefunctions.h:528
Definition bslmf_integralconstant.h:244
Definition bslalg_hastrait.h:117