COPASI API  4.16.103
COptionParser.h
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/commandline/COptionParser.h,v $
3 // $Revision: 1.26 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/06/01 17:25:01 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 /*
15  * This file was automaticly generated by clo++ version 0.6.4 (REL-0_6_4)
16  * http://pmade.org/pjones/software/clo++/
17  *
18  * Template enhancements by Stefan Hoops mailto:shoops@vt.edu
19  */
20 
21 /**
22  * This is the main header file (COptionParser.h).
23  * You can control the name of this header file using the
24  * cxx_header_file variable.
25  */
26 
27 // you can control the include guard
28 // name with the cxx_header_def variable
29 #ifndef COPASI_COptionParser
30 #define COPASI_COptionParser
31 
32 // standard includes
33 #include <stdexcept>
34 #include <string>
35 #include <vector>
36 
37 /// the namespace can be controlled using the cxx_namespace variable
38 namespace copasi
39 {
40 /**
41  * a list of autothrow ids for the autoexcept exception class
42  * so that you know which option caused the exception.
43  */
45 {
47 };
48 
50 {
58 };
59 
60 /**
61  * the following struct is used to hold the values of
62  * the options. It has a constructor that sets all the option
63  * values to their default value.
64  */
65 struct options
66 {
67  options(void) :
68  License(false),
69  MaxTime(0),
70  NoLogo(false),
72  Validate(false),
73  Verbose(false)
74  {}
75  std::string ConfigDir;
76  std::string ConfigFile;
77  std::string CopasiDir;
78  std::string ExportBerkeleyMadonna;
79  std::string ExportC;
80  std::string ExportSBML;
81  std::string ExportXPPAUT;
82  std::string Home;
83  std::string ImportSBML;
84  bool License;
85  int MaxTime;
86  bool NoLogo;
88  std::string Save;
89  std::string Tmp;
90  bool Validate;
91  bool Verbose;
92 #ifdef COPASI_SEDML
93  std::string ImportSEDML;
94 #endif
95 }; // end options struct
96 
97 /**
98  * the following struct is used to record the location
99  * on the command line where the option was found.
100  */
102 {
103  typedef int size_type;
121 #ifdef COPASI_SEDML
122  size_type ImportSEDML;
123 #endif
124 }; // end option location struct
125 
126 /**
127  * if there are any errors while parsing the command
128  * line, the following class will be thrown.
129  */
130 class option_error : public std::runtime_error
131 {
132 public:
133  option_error(const std::string &what_arg)
134  : runtime_error(what_arg) {}
135 
136  const char* get_help_comment(void) const;
137 };
138 
139 /**
140  * if any option that is a autothrow option is present
141  * on the command line, this exception class will be
142  * thrown when that option is parsed.
143  */
144 class autoexcept : public option_error
145 {
146 public:
147  // constructor
148  autoexcept(autothrow id, const std::string &message)
149  : option_error(message), autothrow_(id) {}
150 
151  /**
152  * get the autothrow enum member for the autothrow
153  * option that caused the exception.
154  */
156  {return autothrow_;}
157 private:
159 };
160 
161 /**
162  * the COptionParser class is the main command
163  * line parsing class. You can control the name of it
164  * using the cxx_class variable.
165  */
167 {
168 public:
169  /// default constructor
170  COptionParser(void);
171 
172  /// parse the command line
173  void parse(int argc, char *argv[], bool call_finalize = true);
174 
175  /// parse a file
176  void parse(const char * fileName);
177 
178  /// finalize all parsing (eg. check for mandatory options)
179  void finalize(void);
180 
181  /// get a list of nonoptions from the command line
182  const std::vector<std::string>& get_non_options(void) const
183  {return non_options_;}
184 
185  /// get the main options
186  const options& get_options(void) const
187  {return options_;}
188 
189  /// get the main option locations
190  const option_locations& get_locations(void) const
191  {return locations_;}
192 private:
195 
197  {
215 
216 #ifdef COPASI_SEDML
217  , option_ImportSEDML
218 #endif
219  } openum_;
220 
222  std::vector<std::string> non_options_;
223 
224  enum opsource
225  {
228  };
229  void parse_element(const char *element, int position, opsource source);
230  void parse_short_option(char option, int position, opsource source);
231  void parse_long_option(const char *option, int position, opsource source);
232  void parse_value(const char *value);
233 }; // end copasi::COptionParser class
234 } // end copasi namespace
235 #endif // COPASI_COptionParser
void parse_short_option(char option, int position, opsource source)
autothrow get_autothrow_id(void) const
option_error(const std::string &what_arg)
std::string ExportXPPAUT
Definition: COptionParser.h:81
std::string CopasiDir
Definition: COptionParser.h:77
void parse_element(const char *element, int position, opsource source)
std::vector< std::string > non_options_
enum copasi::COptionParser::options_enum openum_
std::string ExportSBML
Definition: COptionParser.h:80
const char * get_help_comment(void) const
autoexcept(autothrow id, const std::string &message)
std::string Save
Definition: COptionParser.h:88
std::string ConfigDir
Definition: COptionParser.h:75
SBMLSchema_enum SBMLSchema
Definition: COptionParser.h:87
option_locations locations_
std::string ConfigFile
Definition: COptionParser.h:76
const option_locations & get_locations(void) const
get the main option locations
enum copasi::COptionParser::parser_state state_
const std::vector< std::string > & get_non_options(void) const
get a list of nonoptions from the command line
std::string ExportC
Definition: COptionParser.h:79
std::string ExportBerkeleyMadonna
Definition: COptionParser.h:78
std::string ImportSBML
Definition: COptionParser.h:83
const options & get_options(void) const
get the main options
void parse_long_option(const char *option, int position, opsource source)
std::string Tmp
Definition: COptionParser.h:89
void parse_value(const char *value)
void parse(int argc, char *argv[], bool call_finalize=true)
parse the command line
std::string Home
Definition: COptionParser.h:82
COptionParser(void)
default constructor
void finalize(void)
finalize all parsing (eg. check for mandatory options)