IOSS  2.0
Ioss_GetLongOpt.h
Go to the documentation of this file.
1 /*
2  * Copyright(C) 1999-2020 National Technology & Engineering Solutions
3  * of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
4  * NTESS, the U.S. Government retains certain rights in this software.
5  *
6  * See packages/seacas/LICENSE for details
7  */
8 /* S Manoharan. Advanced Computer Research Institute. Lyon. France */
9 
10 #ifndef _GetLongOption_h_
11 #define _GetLongOption_h_
12 
13 #include <iostream>
14 
15 namespace Ioss {
16  /** \brief A database of program command line and environment variable options and methods for
17  * manipulating them.
18  *
19  * A collection of long command line option names for a program that uses the Ioss library.
20  */
22  {
23  public:
25 
26  private:
27  struct Cell
28  {
29  const char *option; // option name
30  OptType type; // option type
31  const char *description; // a description of option
32  const char *value; // value of option (string)
33  const char *opt_value; // If optional value and value not entered, assign opt_value to value
34  Cell * next; // pointer to the next cell
35 
36  Cell()
37  {
38  option = description = value = opt_value = nullptr;
39  next = nullptr;
40  type = NoValue;
41  }
42  };
43 
44  private:
45  Cell * table; // option table
46  const char *ustring; // usage message
47  char * pname; // program basename
48  Cell * last; // last entry in option table
49  int enroll_done; // finished enrolling
50  char optmarker; // option marker
51 
52  private:
53  int setcell(Cell *c, char *valtoken, char *nexttoken, const char *name);
54 
55  public:
56  explicit GetLongOption(char optmark = '-');
58 
59  static char *basename(char *pathname);
60 
61  int parse(int argc, char *const *argv);
62  int parse(char *str, char *p);
63 
64  int enroll(const char *opt, OptType t, const char *desc, const char *val,
65  const char *optval = nullptr);
66  const char *retrieve(const char *opt) const;
67  const char *program_name() const;
68 
69  void usage(std::ostream &outfile = std::cout) const;
70 
71  /** \brief Set the program usage string.
72  *
73  * The program usage string should define the command line
74  * syntax for program options and arguments and contain
75  * other helpful usage text.
76  * \param[in] str The usage string.
77  */
78  void usage(const char *str) { ustring = str; }
79  };
80 } // namespace Ioss
81 #endif /* _GetLongOption_h_ */
Ioss::GetLongOption::basename
static char * basename(char *pathname)
Extract the base file name from a full path.
Definition: Ioss_GetLongOpt.C:47
Ioss::GetLongOption::table
Cell * table
Definition: Ioss_GetLongOpt.h:45
Ioss::GetLongOption::MandatoryValue
@ MandatoryValue
Definition: Ioss_GetLongOpt.h:24
Ioss::GetLongOption::Cell::description
const char * description
Definition: Ioss_GetLongOpt.h:31
Ioss::GetLongOption::Cell::opt_value
const char * opt_value
Definition: Ioss_GetLongOpt.h:33
Ioss::GetLongOption::parse
int parse(int argc, char *const *argv)
parse command line arguments
Definition: Ioss_GetLongOpt.C:127
Ioss
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:40
Ioss::GetLongOption::Cell::type
OptType type
Definition: Ioss_GetLongOpt.h:30
Ioss::GetLongOption::ustring
const char * ustring
Definition: Ioss_GetLongOpt.h:46
Ioss::GetLongOption::last
Cell * last
Definition: Ioss_GetLongOpt.h:48
Ioss::GetLongOption::Cell::option
const char * option
Definition: Ioss_GetLongOpt.h:29
Ioss::GetLongOption::Cell::Cell
Cell()
Definition: Ioss_GetLongOpt.h:36
Ioss::GetLongOption::GetLongOption
GetLongOption(char optmark='-')
Create an empty options database.
Definition: Ioss_GetLongOpt.C:17
Ioss::GetLongOption::Cell::value
const char * value
Definition: Ioss_GetLongOpt.h:32
Ioss::GetLongOption::OptionalValue
@ OptionalValue
Definition: Ioss_GetLongOpt.h:24
Ioss::GetLongOption::enroll
int enroll(const char *opt, OptType t, const char *desc, const char *val, const char *optval=nullptr)
Enroll a command line option into the database.
Definition: Ioss_GetLongOpt.C:72
Ioss::GetLongOption::retrieve
const char * retrieve(const char *opt) const
Get a command line option object.
Definition: Ioss_GetLongOpt.C:105
Ioss::GetLongOption::Cell
Definition: Ioss_GetLongOpt.h:28
Ioss::GetLongOption::Cell::next
Cell * next
Definition: Ioss_GetLongOpt.h:34
Ioss::GetLongOption::pname
char * pname
Definition: Ioss_GetLongOpt.h:47
Ioss::GetLongOption::enroll_done
int enroll_done
Definition: Ioss_GetLongOpt.h:49
Ioss::GetLongOption::optmarker
char optmarker
Definition: Ioss_GetLongOpt.h:50
Ioss::GetLongOption::NoValue
@ NoValue
Definition: Ioss_GetLongOpt.h:24
Ioss::GetLongOption::usage
void usage(std::ostream &outfile=std::cout) const
Print the program usage string.
Definition: Ioss_GetLongOpt.C:360
Ioss::GetLongOption
A database of program command line and environment variable options and methods for manipulating them...
Definition: Ioss_GetLongOpt.h:22
Ioss::GetLongOption::OptType
OptType
Definition: Ioss_GetLongOpt.h:24
anonymous_namespace{io_info.C}::name
std::string name(const Ioss::GroupingEntity *entity)
Definition: io_info.C:65
Ioss::GetLongOption::usage
void usage(const char *str)
Set the program usage string.
Definition: Ioss_GetLongOpt.h:78
Ioss::GetLongOption::~GetLongOption
~GetLongOption()
Frees dynamically allocated memory.
Definition: Ioss_GetLongOpt.C:28
Ioss::GetLongOption::setcell
int setcell(Cell *c, char *valtoken, char *nexttoken, const char *name)
Definition: Ioss_GetLongOpt.C:308
Ioss::GetLongOption::program_name
const char * program_name() const
Definition: Ioss_GetLongOpt.C:98