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

#include <balcl_option.h>

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (Option, bslma::UsesBslmaAllocator)
 
 BSLMF_NESTED_TRAIT_DECLARATION (Option, bdlb::HasPrintMethod)
 
 Option ()
 
 Option (bslma::Allocator *basicAllocator)
 
 Option (const OptionInfo &optionInfo, bslma::Allocator *basicAllocator=0)
 
 Option (const Option &original, bslma::Allocator *basicAllocator=0)
 
 ~Option ()
 Destroy this command-line option object.
 
Optionoperator= (const Option &rhs)
 
Optionoperator= (const OptionInfo &rhs)
 
 operator const OptionInfo & () const
 
OptionInfo::ArgType argType () const
 
const bsl::stringdescription () const
 Return the description of this option.
 
const bsl::stringenvironmentVariableName () const
 Return the environment variable name of this option.
 
bool isArray () const
 
const char * longTag () const
 
const bsl::stringname () const
 Return the name of this option.
 
const OccurrenceInfooccurrenceInfo () const
 
char shortTag () const
 
const bsl::stringtagString () const
 
const TypeInfotypeInfo () const
 
bool isDescriptionValid (bsl::ostream &stream) const
 
bool isLongTagValid (const char *longTag, bsl::ostream &stream) const
 
bool isNameValid (bsl::ostream &stream) const
 
bool isTagValid (bsl::ostream &stream) const
 
bslma::Allocatorallocator () const
 
bsl::ostream & print (bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
 

Detailed Description

This class, constructible from and implicitly convertible to OptionInfo, provides the same attributes, but also uses a bslma::Allocator and thus can be stored in a container. A minor subtlety arises in the name attribute, whereby any suffix starting with an = sign in the name attribute of a OptionInfo is removed in order to derive the name of the Option.

See balcl_option

Constructor & Destructor Documentation

◆ Option() [1/4]

balcl::Option::Option ( )

◆ Option() [2/4]

balcl::Option::Option ( bslma::Allocator basicAllocator)
explicit

Create a default (empty) command-line option. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

◆ Option() [3/4]

balcl::Option::Option ( const OptionInfo optionInfo,
bslma::Allocator basicAllocator = 0 
)
explicit

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

◆ Option() [4/4]

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

Create a Option 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.

◆ ~Option()

balcl::Option::~Option ( )

Member Function Documentation

◆ allocator()

bslma::Allocator * balcl::Option::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 at construction is used.

◆ argType()

OptionInfo::ArgType balcl::Option::argType ( ) const

Return the ArgType enumerator identifying whether this option is a flag (i.e., a tag not followed by a value), or whether it is an option (i.e., a tag followed by a value), or a non-option argument (i.e., a value not preceded by a short or long tag).

◆ BSLMF_NESTED_TRAIT_DECLARATION() [1/2]

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

◆ BSLMF_NESTED_TRAIT_DECLARATION() [2/2]

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

◆ description()

const bsl::string & balcl::Option::description ( ) const

◆ environmentVariableName()

const bsl::string & balcl::Option::environmentVariableName ( ) const

◆ isArray()

bool balcl::Option::isArray ( ) const

Return true if the value of this option is of array type, and false otherwise.

◆ isDescriptionValid()

bool balcl::Option::isDescriptionValid ( bsl::ostream &  stream) const

Return true if the description is valid for this option, leaving the specified stream unaffected; otherwise, write a diagnostic message to stream and return false.

◆ isLongTagValid()

bool balcl::Option::isLongTagValid ( const char *  longTag,
bsl::ostream &  stream 
) const

Return true if the specified longTag is valid for this option, leaving the specified stream unaffected; otherwise, write a diagnostic message to stream and return false.

◆ isNameValid()

bool balcl::Option::isNameValid ( bsl::ostream &  stream) const

Return true if the name is valid for this option, leaving the specified stream unaffected; otherwise, write a diagnostic message to stream and return false.

◆ isTagValid()

bool balcl::Option::isTagValid ( bsl::ostream &  stream) const

Return true if the tag is valid for this option, leaving the specified stream unaffected; otherwise, write a diagnostic message to stream and return false.

◆ longTag()

const char * balcl::Option::longTag ( ) const

Return the string used to identify this option on a command line preceded with --, or 0 if there is no long tag associated with this option. The behavior is undefined if this option is a non-option argument (i.e., has no tag).

◆ name()

const bsl::string & balcl::Option::name ( ) const

◆ occurrenceInfo()

const OccurrenceInfo & balcl::Option::occurrenceInfo ( ) const

Return a const reference to the occurrence info for this option (i.e., whether the option is required, optional, or hidden, and its default value, if any).

◆ operator const OptionInfo &()

balcl::Option::operator const OptionInfo & ( ) const

Return a const reference to the OptionInfo object having the value of this option.

◆ operator=() [1/2]

Option & balcl::Option::operator= ( const Option rhs)

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

◆ operator=() [2/2]

Option & balcl::Option::operator= ( const OptionInfo rhs)

◆ print()

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

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 object. If level is negative, suppress indentation of the first line. If stream is not valid on entry, this operation has no effect. The behavior is undefined if spacesPerLevel is negative.

◆ shortTag()

char balcl::Option::shortTag ( ) const

Return the single character used to identify this option on a command line preceded with a single -, or 0 if this option only has a long tag. The behavior is undefined if this option is a non-option argument (i.e., has no tag).

◆ tagString()

const bsl::string & balcl::Option::tagString ( ) const

Return the tag string provided to this object at construction. Note that this string is empty if this is a non-option argument.

◆ typeInfo()

const TypeInfo & balcl::Option::typeInfo ( ) const

Return a const reference to the type info for this option (i.e., the type of the option, whether the option is linked to a variable, and whether it has a constraint).


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