BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlb::NullableAllocatedValue< TYPE > Class Template Reference

#include <bdlb_nullableallocatedvalue.h>

Public Types

typedef TYPE ValueType
 

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (NullableAllocatedValue, bslma::UsesBslmaAllocator)
 
 BSLMF_NESTED_TRAIT_DECLARATION (NullableAllocatedValue, bslmf::IsBitwiseMoveable)
 
 BSLMF_NESTED_TRAIT_DECLARATION (NullableAllocatedValue, bdlb::HasPrintMethod)
 
 NullableAllocatedValue ()
 
 NullableAllocatedValue (const bsl::allocator< char > &allocator)
 
 NullableAllocatedValue (const bsl::nullopt_t &)
 
 NullableAllocatedValue (const bsl::nullopt_t &, const bsl::allocator< char > &allocator)
 
 NullableAllocatedValue (const NullableAllocatedValue &original)
 
 NullableAllocatedValue (const NullableAllocatedValue &original, const bsl::allocator< char > &allocator)
 
 NullableAllocatedValue (const TYPE &value)
 
 NullableAllocatedValue (const TYPE &value, const bsl::allocator< char > &allocator)
 
 ~NullableAllocatedValue ()
 Destroy this object.
 
NullableAllocatedValue< TYPE > & operator= (const NullableAllocatedValue &rhs)
 
NullableAllocatedValue< TYPE > & operator= (const bsl::nullopt_t &)
 
NullableAllocatedValue< TYPE > & operator= (const TYPE &rhs)
 
TYPE * operator-> ()
 
TYPE & operator* ()
 
template<class... ARGS>
TYPE & emplace (BSLS_COMPILERFEATURES_FORWARD_REF(ARGS)...)
 
template<class STREAM >
STREAM & bdexStreamIn (STREAM &stream, int version)
 
TYPE & makeValue (const TYPE &val)
 
TYPE & makeValue ()
 
void reset ()
 
void swap (NullableAllocatedValue &other)
 
TYPE & value ()
 
template<class STREAM >
STREAM & bdexStreamOut (STREAM &stream, int version) const
 
bsl::allocator< char > get_allocator () const
 
bool has_value () const BSLS_KEYWORD_NOEXCEPT
 
bool isNull () const BSLS_KEYWORD_NOEXCEPT
 
int maxSupportedBdexVersion (int versionSelector) const
 
int maxSupportedBdexVersion () const
 
template<class ANY_TYPE >
TYPE value_or (const ANY_TYPE &default_value) const
 
const TYPE * operator-> () const
 
const TYPE & operator* () const
 
 operator UnspecifiedBool () const BSLS_NOTHROW_SPEC
 
bslma::Allocatorallocator () const
 Return the allocator used by this object to supply memory.
 
bsl::ostream & print (bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
 
const TYPE & value () const
 
 BSLS_DEPRECATE_FEATURE ("bdl", "NullableAllocatedValue::addressOr", "Use 'has_value() ? &value() : address' instead") const TYPE *addressOr(const TYPE *address) const
 
template<class... ARGS>
 BSLS_DEPRECATE_FEATURE ("bdl", "NullableAllocatedValue::makeValueInplace", "Use 'emplace' instead") TYPE &makeValueInplace(ARGS &&... args)
 
 BSLS_DEPRECATE_FEATURE ("bdl", "NullableAllocatedValue::valueOr", "Use 'value_or' instead") TYPE valueOr(const TYPE &otherValue) const
 
 BSLS_DEPRECATE_FEATURE ("bdl", "NullableAllocatedValue::valueOrNull", "Use 'has_value() ? &value() : NULL' instead") const TYPE *valueOrNull() const
 
template<class... ARGS>
TYPE & emplace (BSLS_COMPILERFEATURES_FORWARD_REF(ARGS)... args)
 

Detailed Description

template<class TYPE>
class bdlb::NullableAllocatedValue< TYPE >

This template class extends the set of values of its value-semantic TYPE parameter to include the notion of a "null" value. If TYPE is fully value-semantic, then the augmented type NullableAllocatedValue<TYPE> will be as well. In addition to supporting all homogeneous value-semantic operations, conversions between comparable underlying value types is also supported. Two nullable objects with different underlying types compare equal if their underlying types are comparable and either (1) both objects are null or (2) the non-null values compare equal. Attempts to copy construct, copy assign, or compare incompatible values types will fail to compile. The NullableAllocatedValue template can be instantiated on an incomplete type, but it cannot be instantiated on a type that overloads operator&.

See bdlb_nullableallocatedvalue

Member Typedef Documentation

◆ ValueType

template<class TYPE >
typedef TYPE bdlb::NullableAllocatedValue< TYPE >::ValueType

ValueType is an alias for the underlying TYPE upon which this template class is instantiated, and represents the type of the managed object.

Constructor & Destructor Documentation

◆ NullableAllocatedValue() [1/8]

template<class TYPE >
bdlb::NullableAllocatedValue< TYPE >::NullableAllocatedValue ( )
inline

Create a nullable object having the null value. Use the currently installed default allocator to supply memory.

◆ NullableAllocatedValue() [2/8]

template<class TYPE >
bdlb::NullableAllocatedValue< TYPE >::NullableAllocatedValue ( const bsl::allocator< char > &  allocator)
inlineexplicit

Create a nullable object that has the null value and that uses the mechanism of the specified allocator to supply memory.

◆ NullableAllocatedValue() [3/8]

template<class TYPE >
bdlb::NullableAllocatedValue< TYPE >::NullableAllocatedValue ( const bsl::nullopt_t )
inline

Create a nullable object having the null value. Use the currently installed default allocator to supply memory.

◆ NullableAllocatedValue() [4/8]

template<class TYPE >
bdlb::NullableAllocatedValue< TYPE >::NullableAllocatedValue ( const bsl::nullopt_t ,
const bsl::allocator< char > &  allocator 
)
inline

Create a nullable object that has the null value and that uses the mechanism of the specified allocator to supply memory.

◆ NullableAllocatedValue() [5/8]

template<class TYPE >
bdlb::NullableAllocatedValue< TYPE >::NullableAllocatedValue ( const NullableAllocatedValue< TYPE > &  original)
inline

Create a nullable object having the value of the specified original object. Use the currently installed default allocator to supply memory.

◆ NullableAllocatedValue() [6/8]

template<class TYPE >
bdlb::NullableAllocatedValue< TYPE >::NullableAllocatedValue ( const NullableAllocatedValue< TYPE > &  original,
const bsl::allocator< char > &  allocator 
)
inline

Create a nullable object having the value of the specified original object and that uses the mechanism of the specified allocator to supply memory.

◆ NullableAllocatedValue() [7/8]

template<class TYPE >
bdlb::NullableAllocatedValue< TYPE >::NullableAllocatedValue ( const TYPE &  value)
inline

Create a nullable object having the specified value. Use the currently installed default allocator to supply memory.

◆ NullableAllocatedValue() [8/8]

template<class TYPE >
bdlb::NullableAllocatedValue< TYPE >::NullableAllocatedValue ( const TYPE &  value,
const bsl::allocator< char > &  allocator 
)
inline

Create a nullable object having the specified value and that uses the mechanism of specified allocator to supply memory.

◆ ~NullableAllocatedValue()

template<class TYPE >
bdlb::NullableAllocatedValue< TYPE >::~NullableAllocatedValue ( )
inline

Member Function Documentation

◆ allocator()

template<class TYPE >
bslma::Allocator * bdlb::NullableAllocatedValue< TYPE >::allocator ( ) const
inline

◆ bdexStreamIn()

template<class TYPE >
template<class STREAM >
STREAM & bdlb::NullableAllocatedValue< TYPE >::bdexStreamIn ( STREAM &  stream,
int  version 
)

Assign to this object the value read from the specified input stream using the specified version format, and return a reference to stream. If stream is initially invalid, this operation has no effect. If version is not supported, this object is unaltered and stream is invalidated, but otherwise unmodified. If version is supported but stream becomes invalid during this operation, this object has an undefined, but valid, state. Note that no version is read from stream. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.

◆ bdexStreamOut()

template<class TYPE >
template<class STREAM >
STREAM & bdlb::NullableAllocatedValue< TYPE >::bdexStreamOut ( STREAM &  stream,
int  version 
) const

Write the value of this object, using the specified version format, to the specified output stream, and return a reference to stream. If stream is initially invalid, this operation has no effect. If version is not supported, stream is invalidated, but otherwise unmodified. Note that version is not written to stream. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.

◆ BSLMF_NESTED_TRAIT_DECLARATION() [1/3]

template<class TYPE >
bdlb::NullableAllocatedValue< TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( NullableAllocatedValue< TYPE >  ,
bdlb::HasPrintMethod   
)

◆ BSLMF_NESTED_TRAIT_DECLARATION() [2/3]

template<class TYPE >
bdlb::NullableAllocatedValue< TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( NullableAllocatedValue< TYPE >  ,
bslma::UsesBslmaAllocator   
)

◆ BSLMF_NESTED_TRAIT_DECLARATION() [3/3]

template<class TYPE >
bdlb::NullableAllocatedValue< TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( NullableAllocatedValue< TYPE >  ,
bslmf::IsBitwiseMoveable   
)

◆ BSLS_DEPRECATE_FEATURE() [1/4]

template<class TYPE >
bdlb::NullableAllocatedValue< TYPE >::BSLS_DEPRECATE_FEATURE ( "bdl"  ,
"NullableAllocatedValue< TYPE >::addressOr"  ,
"Use 'has_value() ? &value() : address' instead"   
) const

Return an address providing non-modifiable access to the underlying object of a (template parameter) TYPE if this object is non-null, and the specified address otherwise.

◆ BSLS_DEPRECATE_FEATURE() [2/4]

template<class TYPE >
template<class... ARGS>
bdlb::NullableAllocatedValue< TYPE >::BSLS_DEPRECATE_FEATURE ( "bdl"  ,
"NullableAllocatedValue< TYPE >::makeValueInplace"  ,
"Use 'emplace' instead"   
) &&

Assign to this nullable object the value of the (template parameter) TYPE created in place using the specified args. Return a reference providing modifiable access to the created (value) object. The object is also accessible via the value method. If this nullable object already contains an object (false == isNull()), that object is destroyed before the new object is created. If TYPE has the trait bslma::UsesBslmaAllocator (TYPE is allocator-enabled) the allocator specified at the construction of this nullable object is used to supply memory to the value object. Attempts to explicitly specify via args another allocator to supply memory to the created (value) object are disallowed by the compiler. Note that if the constructor of TYPE throws an exception this object is left in the null state.

◆ BSLS_DEPRECATE_FEATURE() [3/4]

template<class TYPE >
bdlb::NullableAllocatedValue< TYPE >::BSLS_DEPRECATE_FEATURE ( "bdl"  ,
"NullableAllocatedValue< TYPE >::valueOr"  ,
"Use 'value_or' instead"   
) const &

Return the value of the underlying object of a (template parameter) TYPE if this object is non-null, and the specified otherValue otherwise. Note that this method returns by value, so may be inefficient in some contexts.

◆ BSLS_DEPRECATE_FEATURE() [4/4]

template<class TYPE >
bdlb::NullableAllocatedValue< TYPE >::BSLS_DEPRECATE_FEATURE ( "bdl"  ,
"NullableAllocatedValue< TYPE >::valueOrNull"  ,
"Use 'has_value() ? &value() : NULL' instead"   
) const

Return an address providing non-modifiable access to the underlying object of a (template parameter) TYPE if this object is non-null, and 0 otherwise.

◆ emplace() [1/2]

template<class TYPE >
template<class... ARGS>
TYPE & bdlb::NullableAllocatedValue< TYPE >::emplace ( BSLS_COMPILERFEATURES_FORWARD_REF(ARGS)...  args)
inline

◆ emplace() [2/2]

template<class TYPE >
template<class... ARGS>
TYPE & bdlb::NullableAllocatedValue< TYPE >::emplace ( BSLS_COMPILERFEATURES_FORWARD_REF(ARGS)  ...)

Assign to this object the value of the (template parameter) TYPE created in place using the specified args and return a reference providing modifiable access to the underlying TYPE object. If this optional object already contains an object (true == hasValue()), that object is destroyed before the new object is created. Note that if the constructor of TYPE throws an exception this object is left in a disengaged state.

◆ get_allocator()

template<class TYPE >
bsl::allocator< char > bdlb::NullableAllocatedValue< TYPE >::get_allocator ( ) const
inline

Return a bsl::allocator constructed from the bslma::Allocator used by this object to supply memory. Note that if no allocator was supplied at construction the default allocator in effect at construction is used.

◆ has_value()

template<class TYPE >
bool bdlb::NullableAllocatedValue< TYPE >::has_value ( ) const
inline

Return true if this object contains a value, and false otherwise.

◆ isNull()

template<class TYPE >
bool bdlb::NullableAllocatedValue< TYPE >::isNull ( ) const
inline

Return false if this object contains a value, and true otherwise. Note that this is the opposite of has_value .

◆ makeValue() [1/2]

template<class TYPE >
TYPE & bdlb::NullableAllocatedValue< TYPE >::makeValue ( )
inline

Assign to this object the default value for TYPE, and return a reference providing modifiable access to the underlying TYPE object.

◆ makeValue() [2/2]

template<class TYPE >
TYPE & bdlb::NullableAllocatedValue< TYPE >::makeValue ( const TYPE &  val)
inline

Assign to this object the specified val, and return a reference providing modifiable access to the underlying TYPE object.

◆ maxSupportedBdexVersion() [1/2]

template<class TYPE >
int bdlb::NullableAllocatedValue< TYPE >::maxSupportedBdexVersion ( ) const
inline

Return the most current BDEX streaming version number supported by this class. (See the package-group-level documentation for more information on BDEX streaming of container types.)

◆ maxSupportedBdexVersion() [2/2]

template<class TYPE >
int bdlb::NullableAllocatedValue< TYPE >::maxSupportedBdexVersion ( int  versionSelector) const
inline

Return the maximum valid BDEX format version, as indicated by the specified versionSelector, to be passed to the bdexStreamOut method. Note that it is highly recommended that versionSelector be formatted as "YYYYMMDD", a date representation. Also note that versionSelector should be a compile-time-chosen value that selects a format version supported by both externalizer and unexternalizer. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.

◆ operator UnspecifiedBool()

template<class TYPE >
bdlb::NullableAllocatedValue< TYPE >::operator UnspecifiedBool ( ) const
inline

Simulation of explicit conversion to bool. Inlined to work around xlC bug when out-of-line.

◆ operator*() [1/2]

template<class TYPE >
TYPE & bdlb::NullableAllocatedValue< TYPE >::operator* ( )
inline

Return a reference providing modifiable access to the underlying TYPE object. The behavior is undefined if the object has no value.

◆ operator*() [2/2]

template<class TYPE >
const TYPE & bdlb::NullableAllocatedValue< TYPE >::operator* ( ) const
inline

Return a reference providing non-modifiable access to the underlying TYPE object. The behavior is undefined if the object has no value.

◆ operator->() [1/2]

template<class TYPE >
TYPE * bdlb::NullableAllocatedValue< TYPE >::operator-> ( )
inline

Return a pointer providing modifiable access to the underlying TYPE object. The behavior is undefined if the object has no value.

◆ operator->() [2/2]

template<class TYPE >
const TYPE * bdlb::NullableAllocatedValue< TYPE >::operator-> ( ) const
inline

Return a pointer providing non-modifiable access to the underlying TYPE object. The behavior is undefined if the object has no value.

◆ operator=() [1/3]

template<class TYPE >
NullableAllocatedValue< TYPE > & bdlb::NullableAllocatedValue< TYPE >::operator= ( const bsl::nullopt_t )
inline

Reset this object to the default constructed state (i.e., to have the null value).

◆ operator=() [2/3]

template<class TYPE >
NullableAllocatedValue< TYPE > & bdlb::NullableAllocatedValue< TYPE >::operator= ( const NullableAllocatedValue< TYPE > &  rhs)
inline

Assign to this object the value of the specified rhs, and return a reference providing modifiable access to this object.

◆ operator=() [3/3]

template<class TYPE >
NullableAllocatedValue< TYPE > & bdlb::NullableAllocatedValue< TYPE >::operator= ( const TYPE &  rhs)
inline

Assign to this object the value of the specified rhs, and return a reference providing modifiable access to the underlying TYPE object.

◆ print()

template<class TYPE >
bsl::ostream & bdlb::NullableAllocatedValue< TYPE >::print ( bsl::ostream &  stream,
int  level = 0,
int  spacesPerLevel = 4 
) const
inline

Format this object to the specified output stream at the (absolute value of) the optionally specified indentation level and return a reference to stream. If level is specified, optionally specify spacesPerLevel, the number of spaces per indentation level for this and all of its nested objects. If level is negative, suppress indentation of the first line. If spacesPerLevel is negative, format the entire output on one line, suppressing all but the initial indentation (as governed by level). If stream is not valid on entry, this operation has no effect.

◆ reset()

template<class TYPE >
void bdlb::NullableAllocatedValue< TYPE >::reset ( )
inline

Reset this object to the default constructed state (i.e., to have the null value).

◆ swap()

template<class TYPE >
void bdlb::NullableAllocatedValue< TYPE >::swap ( NullableAllocatedValue< TYPE > &  other)

Efficiently exchange the value of this object with the value of the specified other object. This method provides the no-throw exception-safety guarantee. The behavior is undefined unless this object was created with the same allocator as other.

◆ value() [1/2]

template<class TYPE >
TYPE & bdlb::NullableAllocatedValue< TYPE >::value ( )
inline

Return a reference providing modifiable access to the underlying TYPE object. The behavior is undefined unless this object is non-null.

◆ value() [2/2]

template<class TYPE >
const TYPE & bdlb::NullableAllocatedValue< TYPE >::value ( ) const
inline

Return a reference providing non-modifiable access to the underlying TYPE object. The behavior is undefined unless this object is non-null.

◆ value_or()

template<class TYPE >
template<class ANY_TYPE >
TYPE bdlb::NullableAllocatedValue< TYPE >::value_or ( const ANY_TYPE &  default_value) const
inline

Return the value of the underlying object of a (template parameter) TYPE if this object is non-null, and the specified default_value otherwise. Note that this method returns by value, so may be inefficient in some contexts.

Member Data Documentation

◆ d_buffer

template<class TYPE >
char bdlb::NullableAllocatedValue< TYPE >::d_buffer[sizeof(TYPE *)]

◆ d_pointer_p

template<class TYPE >
TYPE* bdlb::NullableAllocatedValue< TYPE >::d_pointer_p

The documentation for this class was generated from the following file: