IOSS 2.0

Ioss_GetLongOpt.h
Go to the documentation of this file.
1 /*
2 * Copyright(C) 1999-2017 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 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 *
18 * * Neither the name of NTESS nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34 /* S Manoharan. Advanced Computer Research Institute. Lyon. France */
35
36 #ifndef _GetLongOption_h_
37 #define _GetLongOption_h_
38
39 #include <iostream>
40
41 namespace Ioss {
42 /** \brief A database of program command line and environment variable options and methods for
43 * manipulating them.
44 *
45 * A collection of long command line option names for a program that uses the Ioss library.
46 */
47 class GetLongOption
48 {
49 public:
50 enum OptType { NoValue, OptionalValue, MandatoryValue };
51
52 private:
53 struct Cell
54 {
55 const char *option; // option name
56 OptType type; // option type
57 const char *description; // a description of option
58 const char *value; // value of option (string)
59 const char *opt_value; // If optional value and value not entered, assign opt_value to value
60 Cell * next; // pointer to the next cell
61
62 Cell()
63 {
64 option = description = value = opt_value = nullptr;
65 next = nullptr;
66 type = NoValue;
67 }
68 };
69
70 private:
71 Cell * table; // option table
72 const char *ustring; // usage message
73 char * pname; // program basename
74 Cell * last; // last entry in option table
75 int enroll_done; // finished enrolling
76 char optmarker; // option marker
77
78 private:
79 int setcell(Cell *c, char *valtoken, char *nexttoken, const char *name);
80
81 public:
82 explicit GetLongOption(char optmark = '-');
83 ~GetLongOption();
84
85 static char *basename(char *pathname);
86
87 int parse(int argc, char *const *argv);
88 int parse(char *str, char *p);
89
90 int enroll(const char *opt, OptType t, const char *desc, const char *val,
91 const char *optval = nullptr);
92 const char *retrieve(const char *opt) const;
93
94 void usage(std::ostream &outfile = std::cout) const;
95
96 /** \brief Set the program usage string.
97 *
98 * The program usage string should define the command line
99 * syntax for program options and arguments and contain
100 * other helpful usage text.
101 * \param[in] str The usage string.
102 */
103 void usage(const char *str) { ustring = str; }
104 };
105 } // namespace Ioss
106 #endif /* _GetLongOption_h_ */
Ioss::GetLongOption::OptionalValue
Definition: Ioss_GetLongOpt.h:50
Ioss::GetLongOption::optmarker
char optmarker
Definition: Ioss_GetLongOpt.h:76
Ioss::GetLongOption::MandatoryValue
Definition: Ioss_GetLongOpt.h:50
Ioss::GetLongOption::ustring
const char * ustring
Definition: Ioss_GetLongOpt.h:72
Ioss::GetLongOption::Cell::description
const char * description
Definition: Ioss_GetLongOpt.h:57
Ioss
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:66
Ioss::GetLongOption::parse
int parse(int argc, char *const *argv)
parse command line arguments
Definition: Ioss_GetLongOpt.C:151
Ioss::GetLongOption::Cell
Definition: Ioss_GetLongOpt.h:53
Ioss::GetLongOption::basename
static char * basename(char *pathname)
Extract the base file name from a full path.
Definition: Ioss_GetLongOpt.C:73
Ioss::GetLongOption::Cell::next
Cell * next
Definition: Ioss_GetLongOpt.h:60
Ioss::GetLongOption::enroll_done
int enroll_done
Definition: Ioss_GetLongOpt.h:75
Ioss::GetLongOption::setcell
int setcell(Cell *c, char *valtoken, char *nexttoken, const char *name)
Definition: Ioss_GetLongOpt.C:332
Ioss::GetLongOption::pname
char * pname
Definition: Ioss_GetLongOpt.h:73
Ioss::GetLongOption::Cell::option
const char * option
Definition: Ioss_GetLongOpt.h:55
Ioss::GetLongOption::usage
void usage(const char *str)
Set the program usage string.
Definition: Ioss_GetLongOpt.h:103
Ioss::GetLongOption::Cell::type
OptType type
Definition: Ioss_GetLongOpt.h:56
Ioss::GetLongOption::Cell::value
const char * value
Definition: Ioss_GetLongOpt.h:58
Ioss::GetLongOption::GetLongOption
GetLongOption(char optmark='-')
Create an empty options database.
Definition: Ioss_GetLongOpt.C:43
Ioss::GetLongOption::retrieve
const char * retrieve(const char *opt) const
Get a command line option object.
Definition: Ioss_GetLongOpt.C:129
Ioss::GetLongOption::NoValue
Definition: Ioss_GetLongOpt.h:50
Ioss::GetLongOption
A database of program command line and environment variable options and methods for manipulating them...
Definition: Ioss_GetLongOpt.h:47
Ioss::GetLongOption::~GetLongOption
~GetLongOption()
Frees dynamically allocated memory.
Definition: Ioss_GetLongOpt.C:54
Ioss::GetLongOption::OptType
OptType
Definition: Ioss_GetLongOpt.h:50
anonymous_namespace{io_info.C}::name
std::string name(Ioss::GroupingEntity *entity)
Definition: io_info.C:87
Ioss::GetLongOption::Cell::opt_value
const char * opt_value
Definition: Ioss_GetLongOpt.h:59
Ioss::GetLongOption::table
Cell * table
Definition: Ioss_GetLongOpt.h:71
Ioss::GetLongOption::last
Cell * last
Definition: Ioss_GetLongOpt.h:74
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:98
Ioss::GetLongOption::Cell::Cell
Cell()
Definition: Ioss_GetLongOpt.h:62
Ioss::GetLongOption::usage
void usage(std::ostream &outfile=std::cout) const
Print the program usage string.
Definition: Ioss_GetLongOpt.C:384