Line |
Branch |
Exec |
Source |
1 |
|
|
// ______ ______ _ _ _____ ______ |
2 |
|
|
// | ____| ____| | (_)/ ____| | ____| |
3 |
|
|
// | |__ | |__ | | _| (___ ___| |__ |
4 |
|
|
// | __| | __| | | | |\___ \ / __| __| |
5 |
|
|
// | | | |____| |____| |____) | (__| |____ |
6 |
|
|
// |_| |______|______|_|_____/ \___|______| |
7 |
|
|
// Finite Elements for Life Sciences and Engineering |
8 |
|
|
// |
9 |
|
|
// License: LGL2.1 License |
10 |
|
|
// FELiScE default license: LICENSE in root folder |
11 |
|
|
// |
12 |
|
|
// Main authors: David Froger |
13 |
|
|
// |
14 |
|
|
|
15 |
|
|
#ifndef COMMANDLINEOPTION_HPP |
16 |
|
|
#define COMMANDLINEOPTION_HPP |
17 |
|
|
|
18 |
|
|
// System includes |
19 |
|
|
#include <iostream> |
20 |
|
|
#include <vector> |
21 |
|
|
|
22 |
|
|
// External includes |
23 |
|
|
#include "GetPot" |
24 |
|
|
|
25 |
|
|
// Project includes |
26 |
|
|
#include "Core/util_string.hpp" |
27 |
|
|
#include "Core/felisce.hpp" |
28 |
|
|
|
29 |
|
|
/*! \namespace felisce */ |
30 |
|
|
namespace felisce |
31 |
|
|
{ |
32 |
|
|
/** |
33 |
|
|
* \brief Preprocess command line options to send it to the appropriate library. |
34 |
|
|
* |
35 |
|
|
* It is necessary to split the command line options std::string list into separate lists, |
36 |
|
|
* that are each passed to the appropriate function (Petsc initialisation, Felisce |
37 |
|
|
* data parsing function, ...). |
38 |
|
|
* |
39 |
|
|
* Indeed, a Petsc command line option passed the Felisce data parser would |
40 |
|
|
* be detected as a wrong option and cause a error. |
41 |
|
|
* |
42 |
|
|
* Similary, passing Felisce data option to the Petsc intialization function |
43 |
|
|
* would make Petsc print warning. |
44 |
|
|
* |
45 |
|
|
* \authors David Froger |
46 |
|
|
* \date 07/02/2012 |
47 |
|
|
*/ |
48 |
|
|
class CommandLineOption |
49 |
|
|
{ |
50 |
|
|
public: |
51 |
|
|
|
52 |
|
|
CommandLineOption(); |
53 |
|
|
|
54 |
|
|
CommandLineOption(const int argc, const char** argv, const std::size_t instanceIndex = 0); |
55 |
|
|
|
56 |
|
|
FELISCE_DEPRECATED_MESSAGE("WARNING:: This constructor is deprecated, please use constructor with const argc and argv") |
57 |
|
|
CommandLineOption(int argc, char** argv); |
58 |
|
|
|
59 |
|
|
CommandLineOption(const CommandLineOption& opt); |
60 |
|
|
|
61 |
|
|
~CommandLineOption(); |
62 |
|
|
|
63 |
|
|
//------------------------------------------------------------------------- |
64 |
|
|
// Main functions |
65 |
|
|
//------------------------------------------------------------------------- |
66 |
|
|
/*! |
67 |
|
|
* \brief Preprocess command line options to send it to the appropriate library. |
68 |
|
|
* |
69 |
|
|
* \param[in] argc Number of command line options. |
70 |
|
|
* \param[in] argv Command line options strings. |
71 |
|
|
* |
72 |
|
|
* Initialize class attribute: |
73 |
|
|
* m_argcSpecial, m_argvSpecial, |
74 |
|
|
* m_argcFelisce, m_argvFelisce, |
75 |
|
|
* m_argcPetsc, m_argvPetsc, |
76 |
|
|
* m_dataFileName, |
77 |
|
|
* m_printHelp. |
78 |
|
|
*/ |
79 |
|
|
void initialize(const int argc, const char **argv); |
80 |
|
|
|
81 |
|
|
//------------------------------------------------------------------------- |
82 |
|
|
// Access functions |
83 |
|
|
//------------------------------------------------------------------------- |
84 |
|
|
// Instance Index |
85 |
|
923 |
std::size_t& instanceIndex() { |
86 |
|
923 |
return mInstanceIndex; |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
// data file |
90 |
|
481 |
std::string& dataFileName() { |
91 |
|
481 |
return m_dataFileName; |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
// help printing |
95 |
|
465 |
bool printHelp() const { |
96 |
|
465 |
return m_printHelp; |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
// felisce opt |
100 |
|
465 |
int& argcFelisce() { |
101 |
|
465 |
return m_argcFelisce; |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
const int& argcFelisce() const { |
105 |
|
|
return m_argcFelisce; |
106 |
|
|
} |
107 |
|
|
|
108 |
|
465 |
char**& argvFelisce() { |
109 |
|
465 |
return m_argvFelisce; |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
char** argvFelisce() const { |
113 |
|
|
return m_argvFelisce; |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
void optFelisce(int &argcFelisce, char**& argvFelisce); |
117 |
|
|
|
118 |
|
|
// petsc opt |
119 |
|
462 |
int& argcPetsc() { |
120 |
|
462 |
return m_argcPetsc; |
121 |
|
|
} |
122 |
|
462 |
char**& argvPetsc() { |
123 |
|
462 |
return m_argvPetsc; |
124 |
|
|
} |
125 |
|
|
void optPetsc(int &argcPetsc, char **&argvPetsc); |
126 |
|
|
|
127 |
|
|
/*! |
128 |
|
|
* \brief Transfert options from argv to argvSpecial. |
129 |
|
|
* |
130 |
|
|
* For the moment, only --help, --file and -f are special options. |
131 |
|
|
* |
132 |
|
|
* \return True if a option has been transfered. |
133 |
|
|
*/ |
134 |
|
|
bool transferSpecialOption( |
135 |
|
|
std::vector<std::string>& argvec, |
136 |
|
|
std::vector<std::string>& argvecSpecial |
137 |
|
|
); |
138 |
|
|
|
139 |
|
|
/*! |
140 |
|
|
* \brief Transfert options from argv to argvFelisce. |
141 |
|
|
* |
142 |
|
|
* Felisce data options have the syntax: --felisce-section-variable=value |
143 |
|
|
* |
144 |
|
|
* \return True if a option has been transfered. |
145 |
|
|
*/ |
146 |
|
|
bool transferFelisceOption( |
147 |
|
|
std::vector<std::string>& argvec, |
148 |
|
|
std::vector<std::string>& argvecFelisce); |
149 |
|
|
|
150 |
|
|
/*! |
151 |
|
|
* \brief Transfert options from argv to argvFelisce. |
152 |
|
|
* |
153 |
|
|
* For the moment, we consider that every options that is not special nor |
154 |
|
|
* a Felisce data is for Petsc. |
155 |
|
|
* |
156 |
|
|
* In the future, if more libraries need to have options passed, we may want to |
157 |
|
|
* to have a more constraining method (for example, like the g++ -Wl, option): |
158 |
|
|
* -P,--petsc-an-options=value,--petsc-another-options=value,petsc-flag |
159 |
|
|
* instead of: |
160 |
|
|
* --petsc-an-option=value --petsc-another-option=value -petsc-flag |
161 |
|
|
* |
162 |
|
|
* Both of them can be anyway preprocessed to create: |
163 |
|
|
* argvPetsc = ['--petsc-an-option=value', |
164 |
|
|
* '--petsc-an-otheroption=value', |
165 |
|
|
* 'petsc-flag'] |
166 |
|
|
* and to pass argvPetsc to the Petsc intialization function. |
167 |
|
|
* |
168 |
|
|
* \return True if a option has been transfered. |
169 |
|
|
*/ |
170 |
|
|
bool transferPetscOption( |
171 |
|
|
std::vector<std::string>& argvec, |
172 |
|
|
std::vector<std::string>& argvecPetsc); |
173 |
|
|
|
174 |
|
|
/*! |
175 |
|
|
* \brief Parses special options (--help, --file, -f). |
176 |
|
|
*/ |
177 |
|
|
void parseSpecialOptions( |
178 |
|
|
int argcSpecial, |
179 |
|
|
char** argvSpecial, |
180 |
|
|
bool& printHelp, |
181 |
|
|
std::string& dataFileName); |
182 |
|
|
|
183 |
|
|
|
184 |
|
|
void print(int verbose = 0, std::ostream& outstr = std::cout) const; |
185 |
|
|
|
186 |
|
|
private: |
187 |
|
|
|
188 |
|
|
std::size_t mInstanceIndex = 0; // The current instance index |
189 |
|
|
|
190 |
|
|
// data file |
191 |
|
|
std::string m_dataFileName = ""; |
192 |
|
|
|
193 |
|
|
// help printing |
194 |
|
|
bool m_printHelp = false; |
195 |
|
|
|
196 |
|
|
// special opt |
197 |
|
|
int m_argcSpecial = 0; |
198 |
|
|
char** m_argvSpecial = nullptr; |
199 |
|
|
|
200 |
|
|
// felisce opt |
201 |
|
|
int m_argcFelisce = 0; |
202 |
|
|
char** m_argvFelisce = nullptr; |
203 |
|
|
|
204 |
|
|
// petsc opt |
205 |
|
|
int m_argcPetsc = 0; |
206 |
|
|
char** m_argvPetsc = nullptr; |
207 |
|
|
}; |
208 |
|
|
} |
209 |
|
|
|
210 |
|
|
#endif |
211 |
|
|
|