1 #ifndef CORE_OptionsReader_H
2 #define CORE_OptionsReader_H
101 static void ReadOptions(
int argc,
char *argv[],std::map<tString,tString>& options);
116 template<
typename T,std::enable_if_t<std::is_
floating_po
int_v<T>> * =
nullptr>
119 std::istringstream iss;
131 template<
typename T,std::enable_if_t<std::is_
integral_v<T>> * =
nullptr>
134 std::from_chars(strValue.data(), strValue.data() + strValue.size(), var);
144 return ReadNumericValue<tReal>(strValue);
152 return ReadNumericValue<tInteger>(strValue);
160 return ReadNumericValue<tRelativeInteger>(strValue);
168 return ReadNumericValue<tInt>(strValue);
179 if (strValue.length()==0)
return true;
183 if (strValue.compare(
"")==0)
return true;
184 if (strValue.compare(
"true")==0)
return true;
185 if (strValue.compare(
"1")==0)
return true;
193 tIndex lmax=current.length();
197 tIndex indexOB=current.find(
"[");
198 if (indexOB!=tString::npos) {
199 current=current.substr(indexOB+1);
200 lmax=current.length();
207 tIndex indexMax=current.find(
"]");
208 if (indexMax==tString::npos) indexMax=lmax;
210 tIndex indexC=current.find(
",");
213 while (indexC<indexMax) {
215 core_functions::parse<T>(current.substr(0,indexC),value);
217 values.push_back(value);
219 current=current.substr(indexC+1,lmax-indexC-1);
220 lmax=current.length();
221 indexC=current.find(
",");
222 indexMax=current.find(
"]");
223 if (indexMax==tString::npos) {
236 v=current.substr(0,indexMax);
238 current=current.substr(indexMax+1,lmax-indexMax-1);
240 if (current[0]==
',') current=current.substr(1);
247 values.push_back(value);
253 template<
class T,tIndex N>
259 for(
auto& v:values) v=0;
260 T* iValue=values.data();
261 const T* eValue=values.data()+N;
264 tIndex lmax=current.length();
268 tIndex indexOB=current.find(
"[");
269 if (indexOB!=tString::npos) {
270 current=current.substr(indexOB+1);
271 lmax=current.length();
277 tIndex indexMax=current.find(
"]");
278 if (indexMax==tString::npos) indexMax=lmax;
280 tIndex indexC=current.find(
",");
281 while ((indexC<indexMax)&&(iValue!=eValue)) {
284 core_functions::parse<T>(current.substr(0,indexC),(*iValue));
288 current=current.substr(indexC+1,lmax-indexC-1);
289 lmax=current.length();
290 indexC=current.find(
",");
291 indexMax=current.find(
"]");
292 if (indexMax==tString::npos) {
303 v=current.substr(0,indexMax);
305 current=current.substr(indexMax+1,lmax-indexMax-1);
307 if (current[0]==
',') current=current.substr(1);
334 const std::map<tString,tString>& options) {
337 std::stringstream fileName;
338 std::map<tString,tString>::const_iterator iOptions=options.find(
"output-path");
339 if (iOptions!=options.end()) fileName<<
ReadPath(iOptions->second);
341 fileName<<
"/options.txt";
351 const std::map<
tString,std::map<tString,tString> >& manOptions,
352 const std::map<tString,tString>& options);
360 const std::map<tString,tString>& options) {
362 for_each(options.begin(),options.end(),
364 out.println(opt.first+
"="+opt.second);
static tString GetAbsolutePath(const tString &path)
get the absolute path of the path
Definition: CORE_IO.h:341
abstract base class for most classes.
Definition: CORE_Object.h:48
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:259
This class is a Run class for core package.
Definition: CORE_OptionsReader.h:49
static tBoolean ReadArray(tString ¤t, std::array< T, N > &values)
Definition: CORE_OptionsReader.h:254
static tString ReadPath(const tString &value)
read a path from a string
Definition: CORE_OptionsReader.h:322
static void RegisterOption(tString &arg, std::map< tString, tString > &options)
register the option
Definition: CORE_OptionsReader.cpp:131
static tInteger ReadRelativeInteger(const tString &strValue)
read a relative integer
Definition: CORE_OptionsReader.h:159
virtual ~CORE_OptionsReader(void)
destroy
Definition: CORE_OptionsReader.h:66
CORE_OptionsReader(void)
create
Definition: CORE_OptionsReader.h:60
static tBoolean SaveOptionsToFile(const std::map< tString, std::map< tString, tString > > &manOptions, const std::map< tString, tString > &options)
save the options to the file
Definition: CORE_OptionsReader.h:333
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: CORE_OptionsReader.h:84
static tBoolean ReadOption(int nArgs, char *argv[], const tString &optionName, tString &optionValue)
read the only the option with optionName in command line
Definition: CORE_OptionsReader.cpp:169
static tInteger ReadInteger(const tString &strValue)
read a natural integer
Definition: CORE_OptionsReader.h:151
static CORE_Out & PrintOptions(CORE_Out &out, const std::map< tString, tString > &options)
print the options
Definition: CORE_OptionsReader.h:359
static tReal ReadReal(const tString &strValue)
read areal
Definition: CORE_OptionsReader.h:143
static tBoolean ReadOptions(const tString &fileName, std::map< tString, tString > &options)
read the options from a file
Definition: CORE_OptionsReader.cpp:5
static void ReadOptionValue(tString &optionValue)
read the option value
Definition: CORE_OptionsReader.cpp:215
static tBoolean ReadVector(tString ¤t, std::vector< T > &values)
Definition: CORE_OptionsReader.h:191
static T ReadNumericValue(const tString &strValue)
read a numeric value of type T
Definition: CORE_OptionsReader.h:117
static tInt ReadInt(const tString &strValue)
read an int
Definition: CORE_OptionsReader.h:167
static tBoolean ReadBoolean(const tString &strValue)
read the boolean from option
Definition: CORE_OptionsReader.h:178
this class describes the output stream by default write on standart output
Definition: CORE_Out.h:28
tString & trim(tString &s)
remove all the empty characters at the begining and end of the string
Definition: functions.h:349
void parse(const tString &s, T &v)
parse the string
Definition: functions.h:518
void toLower(tString &s)
turn a string to lower value
Definition: functions.h:375
#define tIndex
Definition: types.h:157
#define tString
Definition: types.h:147
#define tInt
Definition: types.h:47
#define tMemSize
Definition: types.h:166
#define tInteger
Definition: types.h:114
#define tBoolean
Definition: types.h:151
#define tReal
Definition: types.h:137