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