TRF Language Model
wb-option.h
Go to the documentation of this file.
1 // You may obtain a copy of the License at
2 //
3 // http://www.apache.org/licenses/LICENSE-2.0
4 //
5 // Unless required by applicable law or agreed to in writing, software
6 // distributed under the License is distributed on an "AS IS" BASIS,
7 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8 // See the License for the specific language governing permissions and
9 // limitations under the License.
10 //
11 // Copyright 2014-2015 Tsinghua University
12 // Author: wb.th08@gmail.com (Bin Wang), ozj@tsinghua.edu.cn (Zhijian Ou)
13 //
14 // All h, cpp, cc, and script files (e.g. bat, sh, pl, py) should include the above
15 // license declaration. Different coding language may use different comment styles.
16 
24 #pragma once
25 #include "wb-log.h"
26 #include "wb-vector.h"
27 #include "wb-win.h"
28 
29 namespace wb
30 {
32  typedef enum {
38  } ValueType;
39 
41  typedef struct {
42  ValueType type;
43  const char* pLabel;
44  void* pAddress;
45  const char* pDocMsg;
46  } Opt_Struct;
47 
48 
54  class Option
55  {
56  public:
58  string m_strOtherHelp;
61 
63  public:
65  Option();
67  /* If the option type is string, then 'strdup' is used to create a new string.
68  As a result, in destructor, we should 'free' these string.
69  */
70  ~Option();
72  void Add(ValueType t, const char* pLabel, void *pAddress, const char* pDocMsg = NULL);
74  void PrintUsage();
76  void Print(ValueType type, void* pAddress);
78  void PrintValue();
80  void Parse(const char *plabel, const char *pvalue);
82 
90  int Parse(int argc, char **argv);
91 
93 
100  int Parse(const char *optfile);
101  };
102 }
bool m_bMustCommand
setting 'true' means that, report error when no option input.
Definition: wb-option.h:60
ValueType type
value type
Definition: wb-option.h:42
is true if exist
Definition: wb-option.h:33
Array< char * > m_allocedBufs
if read from file, we may need to allocate memory for string.
Definition: wb-option.h:62
const char * pDocMsg
value usage docment
Definition: wb-option.h:45
void Parse(const char *plabel, const char *pvalue)
parse a single option, "pvalue" can be NULL
Definition: wb-option.cpp:80
void PrintValue()
output values
Definition: wb-option.cpp:71
~Option()
destructor
Definition: wb-option.cpp:28
a definition of a class Log, which can output to the cmd window and the log file simultaneously. In wb-log.cpp, there are a Log variable "lout", which can be directly used just like "cout". For example:
structure of the value
Definition: wb-option.h:41
Provide the toolkits for cmd window of window platform.
Option()
constructor
Definition: wb-option.cpp:22
set false if exist
Definition: wb-option.h:34
integer
Definition: wb-option.h:35
string m_strOtherHelp
extra help information, which will be output in PrintUsage
Definition: wb-option.h:58
void PrintUsage()
output usage
Definition: wb-option.cpp:39
bool m_bOutputValues
if output value after get options from the command line or file
Definition: wb-option.h:59
const char * pLabel
label content. Donot stroe the flag "-"
Definition: wb-option.h:43
void Add(ValueType t, const char *pLabel, void *pAddress, const char *pDocMsg=NULL)
Add a option.
Definition: wb-option.cpp:35
Array< Opt_Struct > m_opts
all the options
Definition: wb-option.h:57
void Print(ValueType type, void *pAddress)
output a value
Definition: wb-option.cpp:50
ValueType
define the value type
Definition: wb-option.h:32
define all the code written by Bin Wang.
Definition: wb-file.cpp:21
Get the option from command line or command files.
Definition: wb-option.h:54
Dynamic array.
Definition: wb-vector.h:205
void * pAddress
value memory address
Definition: wb-option.h:44
Defination of simple dynamic array/stack/queue and so on.