Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Manager.h
1 /*
2  * $Id$
3  * Manager class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2004-07, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef ELM_OPTION_MANAGER_H
23 #define ELM_OPTION_MANAGER_H
24 
25 #include <elm/genstruct/Vector.h>
26 #include <elm/option/Option.h>
27 #include <elm/util/Version.h>
28 #include <elm/util/MessageException.h>
29 #include <elm/genstruct/SortedBinMap.h>
30 #include <elm/util/VarArg.h>
31 
32 namespace elm { namespace option {
33 
34 // OptionException exception
36 public:
38 };
39 
40 // configuration tags
41 const int end = 0,
42  program = 1, // const char *
43  version = 2, // Version *
44  author = 3, // const char *
45  copyright = 4, // const char *
46  description = 5, // const char *
47  help = 5, // alias for description
48  free_arg = 6, // const char *
49  cmd = 7, // const char *
50  short_cmd = 8, // char
51  long_cmd = 9, // const char *
52  def = 10, // option dependent
53  require = 12, // none
54  optional = 13, // none
55  arg_desc = 14; // const char *
56 
57 
58 // Manager
59 class Manager {
60  friend class Option;
61 public:
62 
63  class Make {
64  friend class Manager;
65  public:
66  inline Make(void) { }
67  inline Make(cstring program, Version version = Version::ZERO): _program(program), _version(version) { }
68  inline Make& author(cstring s) { _author = s; return *this; }
69  inline Make& copyright(cstring s) { _copyright = s; return *this; }
70  inline Make& description(cstring s) { _description = s; return *this; }
71  inline Make& free_argument(cstring s) { _free_argument_description = s; return *this; }
72  private:
73  cstring _program;
74  Version _version;
75  cstring _author;
76  cstring _copyright;
77  cstring _description;
78  cstring _free_argument_description;
79  };
80 
81  typedef const char * const *argv_t;
82  inline Manager(void) { }
83  Manager(int tag, ...);
84  Manager(const Make& maker);
85  virtual ~Manager(void) { }
86  void addOption(Option *option) throw(OptionException);
87  void removeOption(Option *option);
88  void parse(int argc, argv_t argv) throw(OptionException);
89  void displayHelp(void);
90 
91  // accessors
92  inline cstring getProgram(void) const { return info._program; }
93  inline const Version& getVersion(void) const { return info._version; }
94  inline cstring getAuthor(void) const { return info._author; }
95  inline cstring getCopyright(void) const { return info._copyright; }
96  inline cstring getDescription(void) const { return info._description; }
97  inline cstring getFreeArgumentDescription(void) const { return info._free_argument_description; }
98 
99 protected:
101  /*CString program;
102  Version version;
103  CString author;
104  CString copyright;
105  CString description;
106  CString free_argument_description;*/
107  virtual void process(String arg);
108  virtual void configure(int tag, VarArg& args);
109 
110 private:
112  void processOption(Option *option, int& i, int argc, argv_t argv, const char *earg);
113  void addShort(char cmd, Option *option) throw(OptionException);
114  void addLong(cstring cmd, Option *option) throw(OptionException);
115  void addCommand(string cmd, Option *option) throw(OptionException);
118 };
119 
120 } } //elm::option
121 
122 #endif // ELM_OPTION_MANAGER_H
Make & description(cstring s)
Definition: Manager.h:70
const int program
Definition: Manager.h:42
Definition: CString.h:17
const int free_arg
Definition: Manager.h:48
void addOption(Option *option)
Definition: option_Manager.cpp:429
cstring getProgram(void) const
Definition: Manager.h:92
Definition: Option.h:43
Make & free_argument(cstring s)
Definition: Manager.h:71
const int arg_desc
Definition: Manager.h:55
const Version & getVersion(void) const
Definition: Manager.h:93
const int cmd
Definition: Manager.h:49
Definition: VarArg.h:25
Make & author(cstring s)
Definition: Manager.h:68
virtual void process(String arg)
Definition: option_Manager.cpp:420
Definition: Manager.h:35
Definition: Manager.h:59
virtual void configure(int tag, VarArg &args)
Definition: option_Manager.cpp:334
OptionException(const String &message)
Definition: option_Manager.cpp:291
const int copyright
Definition: Manager.h:45
const int author
Definition: Manager.h:44
const int long_cmd
Definition: Manager.h:51
static const Version ZERO
Definition: Version.h:32
const int end
Definition: Manager.h:41
cstring getFreeArgumentDescription(void) const
Definition: Manager.h:97
const int version
Definition: Manager.h:43
Definition: Manager.h:63
Manager(void)
Definition: Manager.h:82
const int short_cmd
Definition: Manager.h:50
void parse(int argc, argv_t argv)
Definition: option_Manager.cpp:486
cstring getCopyright(void) const
Definition: Manager.h:95
virtual ~Manager(void)
Definition: Manager.h:85
Make info
Definition: Manager.h:100
const int def
Definition: Manager.h:52
Make & copyright(cstring s)
Definition: Manager.h:69
Definition: String.h:31
Make(cstring program, Version version=Version::ZERO)
Definition: Manager.h:67
const int require
Definition: Manager.h:53
Definition: Vector.h:35
cstring getAuthor(void) const
Definition: Manager.h:94
const int description
Definition: Manager.h:46
Definition: SortedBinMap.h:33
virtual String message(void)
Definition: util_MessageException.cpp:50
Definition: Version.h:30
const int help
Definition: Manager.h:47
Make(void)
Definition: Manager.h:66
Definition: MessageException.h:30
void removeOption(Option *option)
Definition: option_Manager.cpp:439
void displayHelp(void)
Definition: option_Manager.cpp:529
const char *const * argv_t
Definition: Manager.h:81
const int optional
Definition: Manager.h:54
cstring getDescription(void) const
Definition: Manager.h:96