BDE 4.14.0 Production release
Loading...
Searching...
No Matches
balcl::OptionValue Class Reference

#include <balcl_optionvalue.h>

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (OptionValue, bslma::UsesBslmaAllocator)
 
 BSLMF_NESTED_TRAIT_DECLARATION (OptionValue, bdlb::HasPrintMethod)
 
 OptionValue ()
 
 OptionValue (bslma::Allocator *basicAllocator)
 
 OptionValue (OptionType::Enum type, bslma::Allocator *basicAllocator=0)
 
 OptionValue (bool value, bslma::Allocator *basicAllocator=0)
 
 OptionValue (char value, bslma::Allocator *basicAllocator=0)
 
 OptionValue (int value, bslma::Allocator *basicAllocator=0)
 
 OptionValue (bsls::Types::Int64 value, bslma::Allocator *basicAllocator=0)
 
 OptionValue (double value, bslma::Allocator *basicAllocator=0)
 
 OptionValue (const bsl::string &value, bslma::Allocator *basicAllocator=0)
 
 OptionValue (bdlt::Datetime value, bslma::Allocator *basicAllocator=0)
 
 OptionValue (bdlt::Date value, bslma::Allocator *basicAllocator=0)
 
 OptionValue (bdlt::Time value, bslma::Allocator *basicAllocator=0)
 
 OptionValue (const bsl::vector< char > &value, bslma::Allocator *basicAllocator=0)
 
 OptionValue (const bsl::vector< int > &value, bslma::Allocator *basicAllocator=0)
 
 OptionValue (const bsl::vector< bsls::Types::Int64 > &value, bslma::Allocator *basicAllocator=0)
 
 OptionValue (const bsl::vector< double > &value, bslma::Allocator *basicAllocator=0)
 
 OptionValue (const bsl::vector< bsl::string > &value, bslma::Allocator *basicAllocator=0)
 
 OptionValue (const bsl::vector< bdlt::Datetime > &value, bslma::Allocator *basicAllocator=0)
 
 OptionValue (const bsl::vector< bdlt::Date > &value, bslma::Allocator *basicAllocator=0)
 
 OptionValue (const bsl::vector< bdlt::Time > &value, bslma::Allocator *basicAllocator=0)
 
 OptionValue (const OptionValue &original, bslma::Allocator *basicAllocator=0)
 
 ~OptionValue ()=default
 Destroy this object.
 
OptionValueoperator= (const OptionValue &rhs)
 
void reset ()
 
template<class TYPE >
void set (const TYPE &value)
 
void setNull ()
 
void setType (OptionType::Enum type)
 
template<class TYPE >
TYPE & the ()
 
void swap (OptionValue &other)
 
bool hasNonVoidType () const
 
bool isNull () const
 
template<class TYPE >
const TYPE & the () const
 
OptionType::Enum type () const
 
bslma::Allocatorallocator () const
 
bsl::ostream & print (bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
 

Friends

bool operator== (const OptionValue &, const OptionValue &)
 
void swap (OptionValue &, OptionValue &)
 

Detailed Description

This class implements a special-use value-semantic variant type used to represent values parsed from process command lines. Accordingly, this class can represent values of any of the types defined in balcl_optiontype . Furthermore, that value can also be in a null state (defined type but no defined value) to represent allowed options that do not appear among the command-line arguments (and for which no default value has been configured).

See balcl_optionvalue

Constructor & Destructor Documentation

◆ OptionValue() [1/21]

balcl::OptionValue::OptionValue ( )
inline

◆ OptionValue() [2/21]

balcl::OptionValue::OptionValue ( bslma::Allocator basicAllocator)
inlineexplicit

Create a command-line-option value object in the unset state (i.e., OptionType::e_VOID == type()). Optionally specify a basicAllocator used to supply memory. If basicAllocator is not specified, the currently installed default allocator is used. Note that (atypically) this constructor disallows 0 for basicAllocator; invoking the constructor with 0 dispatches to the constructor overload that explicitly accepts an int value for its first argument (see below).

◆ OptionValue() [3/21]

balcl::OptionValue::OptionValue ( OptionType::Enum  type,
bslma::Allocator basicAllocator = 0 
)
inline

Create a command-line-option value object having the type corresponding to the specified type and, if OptionType::e_VOID != type, having the default value of that type. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

◆ OptionValue() [4/21]

balcl::OptionValue::OptionValue ( bool  value,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ OptionValue() [5/21]

balcl::OptionValue::OptionValue ( char  value,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ OptionValue() [6/21]

balcl::OptionValue::OptionValue ( int  value,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ OptionValue() [7/21]

balcl::OptionValue::OptionValue ( bsls::Types::Int64  value,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ OptionValue() [8/21]

balcl::OptionValue::OptionValue ( double  value,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ OptionValue() [9/21]

balcl::OptionValue::OptionValue ( const bsl::string value,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ OptionValue() [10/21]

balcl::OptionValue::OptionValue ( bdlt::Datetime  value,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ OptionValue() [11/21]

balcl::OptionValue::OptionValue ( bdlt::Date  value,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ OptionValue() [12/21]

balcl::OptionValue::OptionValue ( bdlt::Time  value,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ OptionValue() [13/21]

balcl::OptionValue::OptionValue ( const bsl::vector< char > &  value,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ OptionValue() [14/21]

balcl::OptionValue::OptionValue ( const bsl::vector< int > &  value,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ OptionValue() [15/21]

balcl::OptionValue::OptionValue ( const bsl::vector< bsls::Types::Int64 > &  value,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ OptionValue() [16/21]

balcl::OptionValue::OptionValue ( const bsl::vector< double > &  value,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ OptionValue() [17/21]

balcl::OptionValue::OptionValue ( const bsl::vector< bsl::string > &  value,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ OptionValue() [18/21]

balcl::OptionValue::OptionValue ( const bsl::vector< bdlt::Datetime > &  value,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ OptionValue() [19/21]

balcl::OptionValue::OptionValue ( const bsl::vector< bdlt::Date > &  value,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ OptionValue() [20/21]

balcl::OptionValue::OptionValue ( const bsl::vector< bdlt::Time > &  value,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

Create a command-line-option value object having the type and value of the specified value. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

◆ OptionValue() [21/21]

balcl::OptionValue::OptionValue ( const OptionValue original,
bslma::Allocator basicAllocator = 0 
)
inline

Create a OptionValue object having the same value as the specified original object. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

◆ ~OptionValue()

balcl::OptionValue::~OptionValue ( )
default

Member Function Documentation

◆ allocator()

bslma::Allocator * balcl::OptionValue::allocator ( ) const
inline

Return the allocator used by this object to supply memory. Note that if no allocator was supplied at construction the currently installed default allocator is used.

◆ BSLMF_NESTED_TRAIT_DECLARATION() [1/2]

balcl::OptionValue::BSLMF_NESTED_TRAIT_DECLARATION ( OptionValue  ,
bdlb::HasPrintMethod   
)

◆ BSLMF_NESTED_TRAIT_DECLARATION() [2/2]

balcl::OptionValue::BSLMF_NESTED_TRAIT_DECLARATION ( OptionValue  ,
bslma::UsesBslmaAllocator   
)

◆ hasNonVoidType()

bool balcl::OptionValue::hasNonVoidType ( ) const
inline

Return true if this object is in the unset state, and false otherwise. Note that if false == hasNonVoidType() then OptionType::e_VOID == type().

◆ isNull()

bool balcl::OptionValue::isNull ( ) const
inline

Return true if the value of this object (irrespective of non-void type) is null. The behavior is undefined unless true == hasNonVoidType().

◆ operator=()

OptionValue & balcl::OptionValue::operator= ( const OptionValue rhs)
inline

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

◆ print()

bsl::ostream & balcl::OptionValue::print ( bsl::ostream &  stream,
int  level = 0,
int  spacesPerLevel = 4 
) const

Write the value of this object to the specified output stream in a human-readable format, and return a reference to stream. Optionally specify an initial indentation level, whose absolute value is incremented recursively for nested objects. If level is specified, optionally specify spacesPerLevel, whose absolute value indicates 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. Note that the format is not fully specified, and can change without notice.

◆ reset()

void balcl::OptionValue::reset ( )
inline

Reset this object to its default constructed (unset) state. The existing value, if any, is destroyed. Note that on return OptionType::e_VOID == type().

◆ set()

template<class TYPE >
void balcl::OptionValue::set ( const TYPE &  value)
inline

Set the value of this object to the specified value. The behavior is undefined unless OptionType::TypeToEnum<TYPE>::value == type() for the (template parameter) TYPE and OptionType::e_VOID != type().

◆ setNull()

void balcl::OptionValue::setNull ( )
inline

Set the value of this object, irrespective of that value's type, to its null state. The behavior is undefined unless true == hasNonVoidType(). Note that type() is not changed.

◆ setType()

void balcl::OptionValue::setType ( OptionType::Enum  type)
inline

Set the type of this object to the specified type and the value to the default value of that type.

◆ swap()

void balcl::OptionValue::swap ( OptionValue other)
inline

Efficiently exchange the value of this object with the value of the specified other object. This method provides the no-throw exception-safety guarantee if either type() is the same as other.type(), or neither type() nor other.type() is a type that requires allocation; otherwise, it provides the basic guarantee. The behavior is undefined unless this object was created with the same allocator as other.

◆ the() [1/2]

template<class TYPE >
TYPE & balcl::OptionValue::the ( )
inline

Return a reference providing modifiable access to the underlying variant object of this command-line-option value object. The behavior is undefined unless OptionType::e_VOID != type(), OptionType::TypeToEnum<TYPE>::value == type(), and false == isNull().

◆ the() [2/2]

template<class TYPE >
const TYPE & balcl::OptionValue::the ( ) const
inline

Return a const reference to the value of this command line option. The behavior is undefined unless OptionType::e_VOID != type(), OptionType::typeToEnum<TYPE>::value == type(), and false == isNull().

◆ type()

OptionType::Enum balcl::OptionValue::type ( ) const

Return the type of this command-line-option value. The type OptionType::e_VOID represents the unset state.

Friends And Related Symbol Documentation

◆ operator==

bool operator== ( const OptionValue ,
const OptionValue  
)
friend

Return true if the specified lhs and rhs objects have the same value, and false otherwise. Two OptionValue objects have the same value if they have the same type, and (if the type is not e_VOID) the value of that type (as accessed through the* methods) is the same.

◆ swap

void swap ( OptionValue ,
OptionValue  
)
friend

Swap the value of the specified a object with the value of the specified b object. This method provides the no-throw exception-safety guarantee if either a.type() is the same as b.type() and a and b were created with the same allocator, or neither a.type() nor b.type() is a type that requires allocation; otherwise, it provides the basic guarantee.


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