37 m_opts.Add({ t, pLabel, pAddress, pDocMsg });
41 lout <<
"[Usage]:" << endl;
43 for (
int i = 0; i <
m_opts.GetNum(); i++)
45 lout <<
"-" <<
m_opts[i].pLabel <<
"\t" <<
m_opts[i].pDocMsg <<
" [default=";
55 lout << *((
bool*)(pAddress));
58 lout << *((
bool*)(pAddress));
61 lout << *((
int*)(pAddress));
64 lout << *((
float*)(pAddress));
67 lout << *((
char**)(pAddress));
73 for (
int i = 0; i <
m_opts.GetNum(); i++)
84 for (
int i = 0; i <
m_opts.GetNum(); i++) {
85 if (0 == strcmp(plabel + 1,
m_opts[i].pLabel)) {
93 if (strcmp(plabel,
"-?") == 0) {
97 else if (strcmp(plabel,
"-log") == 0) {
105 else if (strcmp(plabel,
"--") == 0) {
110 lout_error(
"no configuration file name after --");
120 lout_error(plabel <<
" no corresponding value");
133 *((
int*)(pOpt->
pAddress)) = atoi(pvalue);
136 *((
float*)(pOpt->
pAddress)) = atof(pvalue);
150 lout <<
"press any key to continue..." << endl;
155 register int CommandCur = 0;
156 register char *CommandPtr = NULL;
157 register int nOpt = 0;
160 int nActiveOptNum = 0;
161 for (CommandCur = 1; CommandCur < argc;)
163 char *pLabel = argv[CommandCur];
165 if (CommandCur + 1 < argc) {
166 pValue = argv[CommandCur + 1];
167 if (*pValue ==
'-') {
172 Parse(pLabel, pValue);
184 return nActiveOptNum;
188 ifstream file(optfile);
190 int nActiveOptNum = 0;
191 const int maxlength = 1024 * 4;
192 char strline[maxlength];
193 while (file.getline(strline, maxlength)) {
194 char *pLabel = strtok(strline,
"= \t");
195 char *pContent = strtok(NULL,
"= \t");
198 Parse(pLabel, pContent);
203 lout <<
"press any key to continue..." << endl;
210 return nActiveOptNum;
bool m_bMustCommand
setting 'true' means that, report error when no option input.
void ReFile(const char *path, bool bNew=true)
relocate the log file. The defualt log file is "program name".log
Array< char * > m_allocedBufs
if read from file, we may need to allocate memory for string.
void Parse(const char *plabel, const char *pvalue)
parse a single option, "pvalue" can be NULL
T & End()
Get the value at the tail of array.
void PrintValue()
output values
string m_strOtherHelp
extra help information, which will be output in PrintUsage
void PrintUsage()
output usage
bool m_bOutputValues
if output value after get options from the command line or file
void Clean()
Clean the array. Just set the top of array to -1 and donot release the memory.
int GetNum() const
Get Array number.
void Add(T t)
Add a value to the tail of array.
void Add(ValueType t, const char *pLabel, void *pAddress, const char *pDocMsg=NULL)
Add a option.
Array< Opt_Struct > m_opts
all the options
Log lout
the defination is in wb-log.cpp
void Print(ValueType type, void *pAddress)
output a value
ValueType
define the value type
define all the code written by Bin Wang.
void * pAddress
value memory address