OpenM++ runtime library (libopenm)
argReader.h
Go to the documentation of this file.
1 
5 // Copyright (c) 2013-2015 OpenM++
6 // This code is licensed under the MIT license (see LICENSE.txt for details)
7 
8 #ifndef OM_H_ARG_READER_H
9 #define OM_H_ARG_READER_H
10 
11 #include "omHelper.h"
12 
13 using namespace std;
14 
15 namespace openm
16 {
18  struct ArgKey
19  {
21  static const char * iniFile;
22 
24  static const char * runStamp;
25 
27  static const char * logToConsole;
28 
30  static const char * logToFile;
31 
33  static const char * logFilePath;
34 
36  static const char * logToStamped;
37 
39  static const char * logUseTs;
40 
42  static const char * logUsePid;
43 
45  static const char * logNoMsgTime;
46 
48  static const char * logSql;
49  };
50 
52  struct ArgReader
53  {
55  ArgReader(void) { }
56 
58  ArgReader(
59  int argc,
60  char ** argv,
61  const size_t i_keyArrSize,
62  const char ** i_keyArr,
63  const size_t i_shortArrSize = 0,
64  const pair<const char *, const char *> * i_shortPairArr = nullptr
65  );
66 
68  ~ArgReader(void) noexcept { }
69 
72 
74  bool isOptionExist(const char * i_key) const noexcept;
75 
77  string strOption(const char * i_key, const string & i_default = "") const noexcept;
78 
80  bool boolOption(const char * i_key) const noexcept;
81 
83  int intOption(const char * i_key, int i_default) const noexcept { return (int)longOption(i_key, i_default); }
84 
86  long long longOption(const char * i_key, long long i_default) const noexcept;
87 
89  double doubleOption(const char * i_key, double i_default) const noexcept;
90 
92  void parseCommandLine(
93  int argc,
94  char ** argv,
95  bool i_isThrowUnknown,
96  bool i_isStoreUnknown,
97  const size_t i_keyArrSize,
98  const char ** i_keyArr,
99  const size_t i_shortArrSize = 0,
100  const pair<const char *, const char *> * i_shortPairArr = nullptr,
101  const size_t i_prefixToCopySize = 0,
102  const char ** i_prefixToCopyArr = nullptr
103  );
104 
106  void loadIniFile(
107  const char * i_filePath,
108  const size_t i_keyArrSize,
109  const char ** i_keyArr,
110  const size_t i_sectionToMergeSize = 0,
111  const char ** i_sectionToMergeArr = nullptr
112  );
113 
115  void adjustLogSettings(int argc, char ** argv);
116  };
117 }
118 
119 #endif // OM_H_ARG_READER_H
static const char * logToFile
log to file
Definition: argReader.h:30
NoCaseMap args
arguments as key-value string pairs with case-neutral search
Definition: argReader.h:71
static const char * runStamp
process run stamp, usually time stamp
Definition: argReader.h:24
static const char * logFilePath
log file path
Definition: argReader.h:33
static const char * logSql
log sql
Definition: argReader.h:48
static const char * logNoMsgTime
do not prefix log messages with date-time
Definition: argReader.h:45
~ArgReader(void) noexcept
cleanup argument holder resources
Definition: argReader.h:68
openM++ namespace
Definition: argReader.cpp:16
ArgReader(void)
initialize empty list of run arguments.
Definition: argReader.h:55
static const char * logUsePid
use pid-stamp in log "stamped" file name
Definition: argReader.h:42
static const char * logToStamped
log to "stamped" file
Definition: argReader.h:36
arguments reader to get runtime arguments from command line and ini-file.
Definition: argReader.h:52
static const char * logUseTs
use time-stamp in log "stamped" file name
Definition: argReader.h:39
map< string, string, LessNoCase > NoCaseMap
map of key-value strings with case neutral key search
Definition: omHelper.h:175
static const char * iniFile
run ini file name, ie: model.ini
Definition: argReader.h:21
static const char * logToConsole
log to console
Definition: argReader.h:27
common openM++ keys for runtime arguments
Definition: argReader.h:18
OpenM++ common helper utilities.