Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
argument.hpp
Go to the documentation of this file.
1 #ifndef STAN__GM__ARGUMENTS__ARGUMENT__BETA
2 #define STAN__GM__ARGUMENTS__ARGUMENT__BETA
3 
4 #include <vector>
5 #include <string>
6 #include <sstream>
7 #include <iomanip>
8 
9 namespace stan {
10  namespace gm {
11 
12  class argument {
13  public:
14 
16  : indent_width(2),
17  help_width(20) { }
18 
19  argument(const std::string name)
20  : _name(name),
21  indent_width(2),
22  help_width(20) { }
23 
24  virtual ~argument() { }
25 
26  std::string name() const {
27  return _name;
28  }
29 
30  std::string description() const {
31  return _description;
32  }
33 
34  virtual void print(std::ostream* s, const int depth, const std::string prefix) = 0;
35  virtual void print_help(std::ostream* s, const int depth, const bool recurse) = 0;
36 
37  virtual bool parse_args(std::vector<std::string>& args,
38  std::ostream* out,
39  std::ostream* err,
40  bool& help_flag) {
41  return true;
42  }
43 
44  virtual void probe_args(argument* base_arg, std::stringstream& s) {};
45 
46  virtual void find_arg(std::string name,
47  std::string prefix,
48  std::vector<std::string>& valid_paths) {
49  if (name == _name) {
50  valid_paths.push_back(prefix + _name);
51  }
52  }
53 
54  static void split_arg(const std::string& arg, std::string& name, std::string& value) {
55  size_t pos = arg.find('=');
56 
57  if (pos != std::string::npos) {
58  name = arg.substr(0, pos);
59  value = arg.substr(pos + 1, arg.size() - pos);
60  }
61  else {
62  name = arg;
63  value = "";
64  }
65  }
66 
67  virtual argument* arg(const std::string name) {
68  return 0;
69  }
70 
71  int compute_indent(const int depth) {
72  return indent_width * depth + 1;
73  }
74 
75  protected:
76  std::string _name;
77  std::string _description;
78 
81  };
82 
83  } // gm
84 } // stan
85 #endif
86 
virtual void probe_args(argument *base_arg, std::stringstream &s)
Definition: argument.hpp:44
std::string description() const
Definition: argument.hpp:30
argument(const std::string name)
Definition: argument.hpp:19
virtual void find_arg(std::string name, std::string prefix, std::vector< std::string > &valid_paths)
Definition: argument.hpp:46
static void split_arg(const std::string &arg, std::string &name, std::string &value)
Definition: argument.hpp:54
int compute_indent(const int depth)
Definition: argument.hpp:71
virtual ~argument()
Definition: argument.hpp:24
std::string _name
Definition: argument.hpp:76
virtual bool parse_args(std::vector< std::string > &args, std::ostream *out, std::ostream *err, bool &help_flag)
Definition: argument.hpp:37
virtual void print_help(std::ostream *s, const int depth, const bool recurse)=0
std::string name() const
Definition: argument.hpp:26
virtual void print(std::ostream *s, const int depth, const std::string prefix)=0
virtual argument * arg(const std::string name)
Definition: argument.hpp:67
std::string _description
Definition: argument.hpp:77

     [ Stan Home Page ] © 2011–2014, Stan Development Team.