8#ifndef INCLUDED_BALCL_COMMANDLINE
9#define INCLUDED_BALCL_COMMANDLINE
1333#include <balscm_version.h>
1350#include <bsl_cstddef.h>
1351#include <bsl_cstring.h>
1352#include <bsl_iosfwd.h>
1353#include <bsl_sstream.h>
1354#include <bsl_string.h>
1355#include <bsl_string_view.h>
1356#include <bsl_vector.h>
1488 mutable bool d_isBindin2Valid;
1494 bool d_envVarsPresent;
1510 void initArgs(
int argc,
const char *
const argv[]);
1518 int parseImp(bsl::ostream& errorStream);
1529 int postParseImp(bsl::ostream& errorStream);
1545 void validateAndInitialize();
1546 void validateAndInitialize(bsl::ostream& errorStream);
1564 int findTag(
char shortTag)
const;
1571 void location(bsl::ostream& errorStream,
1574 int end = -1)
const;
1578 int longestNonFlagNameSize()
const;
1583 int longestTagSize()
const;
1590 int missing(
bool checkAlsoNonOptions =
true)
const;
1606 template <
int LENGTH>
1609 template <
int LENGTH>
1612 template <
int LENGTH>
1615 bsl::ostream& errorStream);
1616 template <
int LENGTH>
1619 bsl::ostream& errorStream);
1635 bsl::ostream& errorStream);
1648 template <
int LENGTH>
1650 bsl::ostream& errorStream,
1652 template <
int LENGTH>
1654 bsl::ostream& errorStream,
1666 template <
int LENGTH>
1670 template <
int LENGTH>
1701 bsl::ostream& errorStream,
1750 int parse(
int argc,
const char *
const argv[]);
1751 int parse(
int argc,
const char *
const argv[], bsl::ostream& errorStream);
2009 bsl::ostream&
print(bsl::ostream& stream,
2011 int spacesPerLevel = 4)
const;
2094 const char *
name(bsl::size_t
index)
const;
2136 template <
class TYPE>
2137 const TYPE&
the(bsl::size_t
index)
const;
2147 template <
class TYPE>
2334 const CommandLine_SchemaData& rhs)
2336 return lhs.d_type == rhs.d_type
2337 && 0 == bsl::strcmp(lhs.d_name_p, rhs.d_name_p);
2342 const CommandLine_SchemaData& rhs)
2344 return lhs.d_type !=
rhs.d_type
2345 || 0 != bsl::strcmp(
lhs.d_name_p,
rhs.d_name_p);
2355template <
int LENGTH>
2363template <
int LENGTH>
2371template <
int LENGTH>
2375 bsl::ostream& errorStream)
2380template <
int LENGTH>
2384 bsl::ostream& errorStream)
2401template <
int LENGTH>
2403 bsl::ostream& errorStream,
2405: d_options(basicAllocator)
2406, d_positions(basicAllocator)
2407, d_nonOptionIndices(basicAllocator)
2409, d_arguments(basicAllocator)
2410, d_schema(basicAllocator)
2411, d_data(basicAllocator)
2412, d_dataFinal(basicAllocator)
2413, d_specifiedOptions(basicAllocator)
2414, d_isBindin2Valid(false)
2415, d_envVarsPresent(false)
2418 for (
int ii = 0; ii < LENGTH; ++ii) {
2421 validateAndInitialize(errorStream);
2422 d_state = e_NOT_PARSED;
2425template <
int LENGTH>
2427 bsl::ostream& errorStream,
2429: d_options(basicAllocator)
2430, d_positions(basicAllocator)
2431, d_nonOptionIndices(basicAllocator)
2433, d_arguments(basicAllocator)
2434, d_schema(basicAllocator)
2435, d_data(basicAllocator)
2436, d_dataFinal(basicAllocator)
2437, d_specifiedOptions(basicAllocator)
2438, d_isBindin2Valid(false)
2439, d_envVarsPresent(false)
2442 for (
int i = 0; i < LENGTH; ++i) {
2445 validateAndInitialize(errorStream);
2446 d_state = e_NOT_PARSED;
2449template <
int LENGTH>
2452: d_options(basicAllocator)
2453, d_positions(basicAllocator)
2454, d_nonOptionIndices(basicAllocator)
2456, d_arguments(basicAllocator)
2457, d_schema(basicAllocator)
2458, d_data(basicAllocator)
2459, d_dataFinal(basicAllocator)
2460, d_specifiedOptions(basicAllocator)
2461, d_isBindin2Valid(false)
2462, d_envVarsPresent(false)
2465 for (
int ii = 0; ii < LENGTH; ++ii) {
2468 validateAndInitialize();
2469 d_state = e_NOT_PARSED;
2472template <
int LENGTH>
2475: d_options(basicAllocator)
2476, d_positions(basicAllocator)
2477, d_nonOptionIndices(basicAllocator)
2479, d_arguments(basicAllocator)
2480, d_schema(basicAllocator)
2481, d_data(basicAllocator)
2482, d_dataFinal(basicAllocator)
2483, d_specifiedOptions(basicAllocator)
2484, d_isBindin2Valid(false)
2485, d_envVarsPresent(false)
2488 for (
int ii = 0; ii < LENGTH; ++ii) {
2491 validateAndInitialize();
2492 d_state = e_NOT_PARSED;
2501CommandLineOptionsHandle::CommandLineOptionsHandle(
2502 const OptionValueList *dataPtr,
2503 const CommandLine_Schema *schemaPtr)
2505, d_schema_p(schemaPtr)
2509 BSLS_ASSERT(dataPtr->size() == schemaPtr->size());
2518 return (*d_schema_p)[
index].d_name_p;
2524 return d_schema_p->
size();
2532 return (*d_schema_p)[
index].d_type;
2544 return (*d_schema_p)[
index].d_type;
2552 return (*d_data_p)[
index];
2564 return (*d_data_p)[
index];
2571template <
class TYPE>
2577 return (*d_data_p)[
index].the<TYPE>();
2580template <
class TYPE>
2589 return the<TYPE>(
index);
2601 return the<OptionType::Bool>(
index);
2613 return the<OptionType::Char>(
index);
2625 return the<OptionType::Int>(
index);
2638 return the<OptionType::Int64>(
index);
2650 return the<OptionType::Double>(
index);
2663 return the<OptionType::String>(
index);
2676 return the<OptionType::Datetime>(
index);
2689 return the<OptionType::Date>(
index);
2702 return the<OptionType::Time>(
index);
2715 return the<OptionType::CharArray>(
index);
2728 return the<OptionType::IntArray>(
index);
2741 return the<OptionType::Int64Array>(
index);
2754 return the<OptionType::DoubleArray>(
index);
2767 return the<OptionType::StringArray>(
index);
2780 return the<OptionType::DatetimeArray>(
index);
2793 return the<OptionType::DateArray>(
index);
2806 return the<OptionType::TimeArray>(
index);
2821 return *lhs.d_data_p == *rhs.d_data_p
2822 && *lhs.d_schema_p == *rhs.d_schema_p;
2832 return *
lhs.d_data_p != *
rhs.d_data_p
2833 || *
lhs.d_schema_p != *
rhs.d_schema_p;
Definition balcl_commandline.h:2055
const TYPE & the(bsl::size_t index) const
Definition balcl_commandline.h:2572
const bdlt::Time & theTime(const bsl::string_view &name) const
Definition balcl_commandline.h:2693
const bsl::string & theString(const bsl::string_view &name) const
Definition balcl_commandline.h:2655
char theChar(const bsl::string_view &name) const
Definition balcl_commandline.h:2605
const bsl::vector< bdlt::Time > & theTimeArray(const bsl::string_view &name) const
Definition balcl_commandline.h:2798
bsls::Types::Int64 theInt64(const bsl::string_view &name) const
Definition balcl_commandline.h:2629
OptionType::Enum type(bsl::size_t index) const
Definition balcl_commandline.h:2528
const bsl::vector< bdlt::Datetime > & theDatetimeArray(const bsl::string_view &name) const
Definition balcl_commandline.h:2772
const bdlt::Date & theDate(const bsl::string_view &name) const
Definition balcl_commandline.h:2681
bsl::size_t numOptions() const
Return the number of parsed options.
Definition balcl_commandline.h:2522
const bsl::vector< char > & theCharArray(const bsl::string_view &name) const
Definition balcl_commandline.h:2707
bool theBool(const bsl::string_view &name) const
Definition balcl_commandline.h:2593
friend bool operator!=(const CommandLineOptionsHandle &, const CommandLineOptionsHandle &)
const OptionValue & value(bsl::size_t index) const
Definition balcl_commandline.h:2548
double theDouble(const bsl::string_view &name) const
Definition balcl_commandline.h:2642
const bsl::vector< bdlt::Date > & theDateArray(const bsl::string_view &name) const
Definition balcl_commandline.h:2785
int index(const bsl::string_view &name) const
const bsl::vector< double > & theDoubleArray(const bsl::string_view &name) const
Definition balcl_commandline.h:2746
const bsl::vector< int > & theIntArray(const bsl::string_view &name) const
Definition balcl_commandline.h:2720
const char * name(bsl::size_t index) const
Definition balcl_commandline.h:2514
int theInt(const bsl::string_view &name) const
Definition balcl_commandline.h:2617
const bdlt::Datetime & theDatetime(const bsl::string_view &name) const
Definition balcl_commandline.h:2668
const bsl::vector< bsl::string > & theStringArray(const bsl::string_view &name) const
Definition balcl_commandline.h:2759
friend bool operator==(const CommandLineOptionsHandle &, const CommandLineOptionsHandle &)
const bsl::vector< bsls::Types::Int64 > & theInt64Array(const bsl::string_view &name) const
Definition balcl_commandline.h:2733
Definition balcl_commandline.h:1423
CommandLine(const OptionInfo(&specTable)[LENGTH], bsl::ostream &errorStream, bslma::Allocator *basicAllocator=0)
Definition balcl_commandline.h:2402
bool hasOption(const bsl::string_view &name) const
OptionType::Enum type(const bsl::string_view &name) const
int theInt(const bsl::string_view &name) const
const bdlt::Date & theDate(const bsl::string_view &name) const
BSLMF_NESTED_TRAIT_DECLARATION(CommandLine, bdlb::HasPrintMethod)
bool hasValue(const bsl::string_view &name) const
CommandLine(const OptionInfo *specTable, int length, bsl::ostream &errorStream, bslma::Allocator *basicAllocator=0)
static bool isValidOptionSpecificationTable(const OptionInfo *specTable, int length, bsl::ostream &errorStream)
bslma::Allocator * allocator() const
const bsl::vector< bdlt::Date > & theDateArray(const bsl::string_view &name) const
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
const bdlt::Time & theTime(const bsl::string_view &name) const
const bdlt::Datetime & theDatetime(const bsl::string_view &name) const
double theDouble(const bsl::string_view &name) const
~CommandLine()
Destroy this command-line object.
const bsl::vector< int > & positions(const bsl::string_view &name) const
CommandLineOptionsHandle specifiedOptions() const
const bsl::vector< bdlt::Time > & theTimeArray(const bsl::string_view &name) const
CommandLineOptionsHandle options() const
const bsl::vector< bdlt::Datetime > & theDatetimeArray(const bsl::string_view &name) const
BSLMF_NESTED_TRAIT_DECLARATION(CommandLine, bslma::UsesBslmaAllocator)
const bsl::vector< char > & theCharArray(const bsl::string_view &name) const
int numSpecified(const bsl::string_view &name) const
int parse(int argc, const char *const argv[], bsl::ostream &errorStream)
CommandLine & operator=(const CommandLine &rhs)
const bsl::vector< bsl::string > & theStringArray(const bsl::string_view &name) const
bool isSpecified(const bsl::string_view &name, int *count) const
static bool isValidOptionSpecificationTable(const OptionInfo(&specTable)[LENGTH])
Definition balcl_commandline.h:2357
void printUsage(const bsl::string_view &programName) const
bool theBool(const bsl::string_view &name) const
char theChar(const bsl::string_view &name) const
void printUsage(bsl::ostream &errorStream) const
bool isSpecified(const bsl::string_view &name) const
CommandLine(const OptionInfo *specTable, int length, bslma::Allocator *basicAllocator=0)
int position(const bsl::string_view &name) const
bsls::Types::Int64 theInt64(const bsl::string_view &name) const
const bsl::vector< double > & theDoubleArray(const bsl::string_view &name) const
CommandLine(const CommandLine &original, bslma::Allocator *basicAllocator=0)
const bsl::vector< bsls::Types::Int64 > & theInt64Array(const bsl::string_view &name) const
void printUsage(bsl::ostream &errorStream, const bsl::string_view &programName) const
const bsl::string & theString(const bsl::string_view &name) const
const bsl::vector< int > & theIntArray(const bsl::string_view &name) const
int parse(int argc, const char *const argv[])
Definition balcl_optionvalue.h:396
Definition balcl_option.h:132
Definition bdlt_date.h:294
Definition bdlt_datetime.h:330
Definition bdlt_time.h:195
Definition bslstl_stringview.h:471
Definition bslstl_string.h:1252
size_type size() const BSLS_KEYWORD_NOEXCEPT
Return the number of elements in this vector.
Definition bslstl_vector.h:3019
Definition bslstl_vector.h:1120
void reserve(size_type newCapacity)
Definition bslstl_vector.h:4263
void push_back(const VALUE_TYPE &value)
Definition bslstl_vector.h:4343
Definition bslma_allocator.h:545
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition balcl_commandline.h:1364
bool operator==(const CommandLine_SchemaData &lhs, const CommandLine_SchemaData &rhs)
bsl::ostream & operator<<(bsl::ostream &stream, const CommandLine &rhs)
bool operator!=(const CommandLine_SchemaData &lhs, const CommandLine_SchemaData &rhs)
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
ALLOCATOR & lhs
Definition bslstl_string.h:3917
basic_ostringstream< char, char_traits< char >, allocator< char > > ostringstream
Definition bslstl_iosfwd.h:97
Definition balcl_commandline.h:1375
const char * d_name_p
Definition balcl_commandline.h:1379
OptionType::Enum d_type
Definition balcl_commandline.h:1378
Definition balcl_optioninfo.h:135
Definition balcl_optiontype.h:288
Enum
Definition balcl_optiontype.h:250
@ e_DOUBLE
Definition balcl_optiontype.h:257
@ e_CHAR_ARRAY
Definition balcl_optiontype.h:262
@ e_STRING
Definition balcl_optiontype.h:258
@ e_INT
Definition balcl_optiontype.h:255
@ e_INT64
Definition balcl_optiontype.h:256
@ e_CHAR
Definition balcl_optiontype.h:254
@ e_DATE_ARRAY
Definition balcl_optiontype.h:268
@ e_DATE
Definition balcl_optiontype.h:260
@ e_BOOL
Definition balcl_optiontype.h:253
@ e_INT64_ARRAY
Definition balcl_optiontype.h:264
@ e_INT_ARRAY
Definition balcl_optiontype.h:263
@ e_STRING_ARRAY
Definition balcl_optiontype.h:266
@ e_TIME
Definition balcl_optiontype.h:261
@ e_DATETIME
Definition balcl_optiontype.h:259
@ e_TIME_ARRAY
Definition balcl_optiontype.h:269
@ e_DATETIME_ARRAY
Definition balcl_optiontype.h:267
@ e_DOUBLE_ARRAY
Definition balcl_optiontype.h:265
Definition bdlb_printmethods.h:306
Definition bslma_usesbslmaallocator.h:344
long long Int64
Definition bsls_types.h:134