BDE 4.14.0 Production release
|
#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. | |
OptionValue & | operator= (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::Allocator * | allocator () 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 &) |
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).
|
inline |
|
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).
|
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.
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
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.
|
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.
|
default |
|
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.
balcl::OptionValue::BSLMF_NESTED_TRAIT_DECLARATION | ( | OptionValue | , |
bdlb::HasPrintMethod | |||
) |
balcl::OptionValue::BSLMF_NESTED_TRAIT_DECLARATION | ( | OptionValue | , |
bslma::UsesBslmaAllocator | |||
) |
|
inline |
Return true
if this object is in the unset state, and false
otherwise. Note that if false == hasNonVoidType()
then OptionType::e_VOID == type()
.
|
inline |
Return true
if the value of this object (irrespective of non-void
type) is null. The behavior is undefined unless true == hasNonVoidType()
.
|
inline |
Assign to this object the value of the specified rhs
object, and return a reference providing modifiable access to this object.
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.
|
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()
.
|
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()
.
|
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.
|
inline |
Set the type of this object to the specified type
and the value to the default value of that type.
|
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
.
|
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()
.
|
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()
.
OptionType::Enum balcl::OptionValue::type | ( | ) | const |
Return the type of this command-line-option value. The type OptionType::e_VOID
represents the unset state.
|
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.
|
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.