Quick Links:

bal | bbl | bdl | bsl

Public Member Functions | Friends

balcl::OptionValue Class Reference

#include <balcl_optionvalue.h>

List of all members.

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 ()
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 Component balcl_optionvalue


Constructor & Destructor Documentation

balcl::OptionValue::OptionValue (  ) 
balcl::OptionValue::OptionValue ( bslma::Allocator basicAllocator  )  [explicit]

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).

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

IMPLICIT: 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.

balcl::OptionValue::OptionValue ( bool  value,
bslma::Allocator basicAllocator = 0 
) [explicit]
balcl::OptionValue::OptionValue ( char  value,
bslma::Allocator basicAllocator = 0 
) [explicit]
balcl::OptionValue::OptionValue ( int  value,
bslma::Allocator basicAllocator = 0 
) [explicit]
balcl::OptionValue::OptionValue ( bsls::Types::Int64  value,
bslma::Allocator basicAllocator = 0 
) [explicit]
balcl::OptionValue::OptionValue ( double  value,
bslma::Allocator basicAllocator = 0 
) [explicit]
balcl::OptionValue::OptionValue ( const bsl::string value,
bslma::Allocator basicAllocator = 0 
) [explicit]
balcl::OptionValue::OptionValue ( bdlt::Datetime  value,
bslma::Allocator basicAllocator = 0 
) [explicit]
balcl::OptionValue::OptionValue ( bdlt::Date  value,
bslma::Allocator basicAllocator = 0 
) [explicit]
balcl::OptionValue::OptionValue ( bdlt::Time  value,
bslma::Allocator basicAllocator = 0 
) [explicit]
balcl::OptionValue::OptionValue ( const bsl::vector< char > &  value,
bslma::Allocator basicAllocator = 0 
) [explicit]
balcl::OptionValue::OptionValue ( const bsl::vector< int > &  value,
bslma::Allocator basicAllocator = 0 
) [explicit]
balcl::OptionValue::OptionValue ( const bsl::vector< bsls::Types::Int64 > &  value,
bslma::Allocator basicAllocator = 0 
) [explicit]
balcl::OptionValue::OptionValue ( const bsl::vector< double > &  value,
bslma::Allocator basicAllocator = 0 
) [explicit]
balcl::OptionValue::OptionValue ( const bsl::vector< bsl::string > &  value,
bslma::Allocator basicAllocator = 0 
) [explicit]
balcl::OptionValue::OptionValue ( const bsl::vector< bdlt::Datetime > &  value,
bslma::Allocator basicAllocator = 0 
) [explicit]
balcl::OptionValue::OptionValue ( const bsl::vector< bdlt::Date > &  value,
bslma::Allocator basicAllocator = 0 
) [explicit]
balcl::OptionValue::OptionValue ( const bsl::vector< bdlt::Time > &  value,
bslma::Allocator basicAllocator = 0 
) [explicit]

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.

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

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.

balcl::OptionValue::~OptionValue (  ) 

Destroy this object.


Member Function Documentation

balcl::OptionValue::BSLMF_NESTED_TRAIT_DECLARATION ( OptionValue  ,
bslma::UsesBslmaAllocator   
)
balcl::OptionValue::BSLMF_NESTED_TRAIT_DECLARATION ( OptionValue  ,
bdlb::HasPrintMethod   
)
OptionValue& balcl::OptionValue::operator= ( const OptionValue rhs  ) 

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

void balcl::OptionValue::reset (  ) 

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

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

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().

void balcl::OptionValue::setNull (  ) 

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.

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

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

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

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().

void balcl::OptionValue::swap ( OptionValue 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 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.

bool balcl::OptionValue::hasNonVoidType (  )  const

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

bool balcl::OptionValue::isNull (  )  const

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

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

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.

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

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.

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.


Friends And Related Function Documentation

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.

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: