IOSS 2.0
Loading...
Searching...
No Matches
Ioss::GetLongOption Class Reference

A database of program command line and environment variable options and methods for manipulating them. More...

#include <Ioss_GetLongOpt.h>

Collaboration diagram for Ioss::GetLongOption:
[legend]

Classes

struct  Cell
 

Public Types

enum  OptType { NoValue , OptionalValue , MandatoryValue }
 

Public Member Functions

 GetLongOption (char optmark='-')
 Create an empty options database.
 
 ~GetLongOption ()
 Frees dynamically allocated memory.
 
int parse (int argc, char *const *argv)
 parse command line arguments
 
int parse (char *str, char *p)
 parse an argument string.
 
bool enroll (const char *opt, OptType t, const char *desc, const char *val, const char *optval=nullptr, bool extra_line=false)
 Enroll a command line option into the database.
 
const char * retrieve (const char *opt) const
 Get a command line option object.
 
const char * program_name () const
 
void usage (std::ostream &outfile=std::cout) const
 Print the program usage string.
 
void usage (const char *str)
 Set the program usage string.
 
template<class INT , typename std::enable_if< std::is_integral< INT >::value, INT >::type * = nullptr>
INT get_option_value (const char *option_txt, INT default_value)
 
template<class DBL , typename std::enable_if< std::is_floating_point< DBL >::value, DBL >::type * = nullptr>
DBL get_option_value (const char *option_txt, DBL default_value)
 
std::string get_option_value (const char *option_txt, const std::string &default_value) const
 

Static Public Member Functions

static char * basename (char *pathname)
 Extract the base file name from a full path.
 

Private Member Functions

int setcell (Cell *c, char *valtoken, char *nexttoken, const char *name)
 

Private Attributes

Celltable {nullptr}
 
const char * ustring {nullptr}
 
char * pname {nullptr}
 
Celllast {nullptr}
 
char optmarker
 
bool options_parsed {false}
 

Detailed Description

A database of program command line and environment variable options and methods for manipulating them.

A collection of long command line option names for a program that uses the Ioss library.

Member Enumeration Documentation

◆ OptType

Enumerator
NoValue 
OptionalValue 
MandatoryValue 

Constructor & Destructor Documentation

◆ GetLongOption()

Ioss::GetLongOption::GetLongOption ( char optmark = '-')
explicit

Create an empty options database.

Parameters
optmarkThe command line symbol designating options.

◆ ~GetLongOption()

Ioss::GetLongOption::~GetLongOption ( )

Frees dynamically allocated memory.

Frees memory for the private struct variables representing the options.

Member Function Documentation

◆ basename()

char * Ioss::GetLongOption::basename ( char * pathname)
static

Extract the base file name from a full path.

Finds the last instance of the '/' character and extracts the part of the string that follows.

Parameters
[in]pathnameThe full path.
Returns
The base file name.

◆ enroll()

bool Ioss::GetLongOption::enroll ( const char * opt,
OptType t,
const char * desc,
const char * val,
const char * optval = nullptr,
bool extra_line = false )

Enroll a command line option into the database.

Dynamically allocates memory for the option, sets its name type, description, value, and default value, and links it to the preceding option.

Parameters
[in]optThe long option name.
[in]tThe option type.
[in]descA short description of the option.
[in]valThe option value.
[in]optvalThe default value.
[in]extra_lineIf true, add a blank line after this description output.
Returns
1 if successful, 0 if unsuccessful.

◆ get_option_value() [1/3]

std::string Ioss::GetLongOption::get_option_value ( const char * option_txt,
const std::string & default_value ) const
inline

◆ get_option_value() [2/3]

template<class DBL , typename std::enable_if< std::is_floating_point< DBL >::value, DBL >::type * = nullptr>
DBL Ioss::GetLongOption::get_option_value ( const char * option_txt,
DBL default_value )
inline

◆ get_option_value() [3/3]

template<class INT , typename std::enable_if< std::is_integral< INT >::value, INT >::type * = nullptr>
INT Ioss::GetLongOption::get_option_value ( const char * option_txt,
INT default_value )
inline

◆ parse() [1/2]

int Ioss::GetLongOption::parse ( char * str,
char * p )

parse an argument string.

Set the values of options in the option table based on the given option string.

Parameters
[in]strThe option string.
[in]pA string to be used in error reporting
Returns
1 if successful, or -1 otherwise.

◆ parse() [2/2]

int Ioss::GetLongOption::parse ( int argc,
char *const * argv )

parse command line arguments

Set the values of options in the option table based on the given command line arguments.

Parameters
[in]argcNumber of command line arguments passed in from main(int argc, char *argv[]).
[in]argvCommand line arguments passed in from main(int argc, char *argv[]).
Returns
Number of options processed, or -1 on failure.

◆ program_name()

const char * Ioss::GetLongOption::program_name ( ) const

◆ retrieve()

const char * Ioss::GetLongOption::retrieve ( const char * opt) const

Get a command line option object.

Parameters
[in]optThe option name.
Returns
The option object.

◆ setcell()

int Ioss::GetLongOption::setcell ( Cell * c,
char * valtoken,
char * nexttoken,
const char * name )
private

◆ usage() [1/2]

void Ioss::GetLongOption::usage ( const char * str)
inline

Set the program usage string.

The program usage string should define the command line syntax for program options and arguments and contain other helpful usage text.

Parameters
[in]strThe usage string.

◆ usage() [2/2]

void Ioss::GetLongOption::usage ( std::ostream & outfile = std::cout) const

Print the program usage string.

Parameters
[in]outfileThe output stream to which the usage string is printed.

Member Data Documentation

◆ last

Cell* Ioss::GetLongOption::last {nullptr}
private

◆ options_parsed

bool Ioss::GetLongOption::options_parsed {false}
private

◆ optmarker

char Ioss::GetLongOption::optmarker
private

◆ pname

char* Ioss::GetLongOption::pname {nullptr}
private

◆ table

Cell* Ioss::GetLongOption::table {nullptr}
private

◆ ustring

const char* Ioss::GetLongOption::ustring {nullptr}
private

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