Qualia  0.2
CmdOption.h
Go to the documentation of this file.
1 // Copyright (C) 2003--2004 Ronan Collobert (collober@idiap.ch)
2 //
3 // This file is part of Torch 3.1.
4 //
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 // 1. Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 // 3. The name of the author may not be used to endorse or promote products
16 // derived from this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #ifndef CMD_OPTION_INC
30 #define CMD_OPTION_INC
31 
33 
41 class CmdOption
42 {
43  private:
44  // Special flags.
45  bool is_option;
47  bool is_text;
49 
50  public:
52  char *name;
53 
55  char *type_name;
56 
60  char *help;
61 
65  bool needsSave;
66 
70  bool is_setted;
71 
73 
75  CmdOption(const char *name_, const char *type_name_, const char *help_="", bool save_=false);
76 
78  virtual void initValue();
79 
81  virtual void printValue(DiskXFile *file_);
82 
87  virtual void read(int *argc_, char ***argv_);
88 
89  /* Return true if the option is on the command line.
90  Decrements argc_ and increment argv_ if true.
91  */
92  bool isCurrent(int *argc_, char ***argv_);
93 
97  bool isOption(bool set_=false);
98 
102  bool isArgument(bool set_=false);
103 
107  bool isText(bool set_=false);
108 
112  bool isMasterSwitch(bool set_=false);
113 
114  virtual void load(DiskXFile *file) {}
115  virtual void save(DiskXFile *file) {}
116 
117  virtual ~CmdOption();
118 };
119 
125 class IntCmdOption : public CmdOption
126 {
127  public:
128  int *ptr;
130 
132  IntCmdOption(const char *name_, int *ptr_, int init_value_, const char *help_="", bool save_=false);
133 
134  virtual void initValue();
135  virtual void printValue(DiskXFile *file_);
136  virtual void read(int *argc_, char ***argv_);
137  virtual void load(DiskXFile *file);
138  virtual void save(DiskXFile *file);
139  ~IntCmdOption();
140 };
141 
147 class RealCmdOption : public CmdOption
148 {
149  public:
152 
154  RealCmdOption(const char *name_, real *ptr_, real init_value_, const char *help_="", bool save_=false);
155 
156  virtual void initValue();
157  virtual void printValue(DiskXFile *file_);
158  virtual void read(int *argc_, char ***argv_);
159  virtual void load(DiskXFile *file);
160  virtual void save(DiskXFile *file);
161  ~RealCmdOption();
162 };
163 
169 class BoolCmdOption : public CmdOption
170 {
171  public:
172  bool *ptr;
174 
176  BoolCmdOption(const char *name_, bool *ptr_, bool init_value_, const char *help_="", bool save_=false);
177 
178  virtual void initValue();
179  virtual void read(int *argc_, char ***argv_);
180  virtual void load(DiskXFile *file);
181  virtual void save(DiskXFile *file);
182  ~BoolCmdOption();
183 };
184 
191 {
192  public:
193  char **ptr;
194  char *init_value;
195 
197  StringCmdOption(const char *name_, char **ptr_, const char *init_value_, const char *help_="", bool save_=false);
198 
199  virtual void initValue();
200  virtual void printValue(DiskXFile *file_);
201  virtual void read(int *argc_, char ***argv_);
202  virtual void load(DiskXFile *file);
203  virtual void save(DiskXFile *file);
205 };
206 
207 #endif