Stan  2.10.0
probability, sampling & optimization
argument.hpp
Go to the documentation of this file.
1 #ifndef STAN_SERVICES_ARGUMENTS_ARGUMENT_HPP
2 #define STAN_SERVICES_ARGUMENTS_ARGUMENT_HPP
3 
5 #include <vector>
6 #include <string>
7 #include <sstream>
8 #include <iomanip>
9 
10 namespace stan {
11  namespace services {
12 
13  class argument {
14  public:
16  : indent_width(2),
17  help_width(20) { }
18 
19  explicit 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 
35  const int depth,
36  const std::string& prefix) = 0;
37 
39  const int depth,
40  const bool recurse) = 0;
41 
42  virtual bool parse_args(std::vector<std::string>& args,
45  bool& help_flag) {
46  return true;
47  }
48 
49  virtual void probe_args(argument* base_arg,
51 
52  virtual void find_arg(const std::string& name,
53  const std::string& prefix,
54  std::vector<std::string>& valid_paths) {
55  if (name == _name) {
56  valid_paths.push_back(prefix + _name);
57  }
58  }
59 
60  static void split_arg(const std::string& arg,
61  std::string& name,
62  std::string& value) {
63  size_t pos = arg.find('=');
64 
65  if (pos != std::string::npos) {
66  name = arg.substr(0, pos);
67  value = arg.substr(pos + 1, arg.size() - pos);
68  } else {
69  name = arg;
70  value = "";
71  }
72  }
73 
74  virtual argument* arg(const std::string& name) {
75  return 0;
76  }
77 
78  int compute_indent(const int depth) {
79  return indent_width * depth;
80  }
81 
82  protected:
83  std::string _name;
84  std::string _description;
85 
88  };
89 
90  } // services
91 } // stan
92 #endif
virtual void print_help(interface_callbacks::writer::base_writer &w, const int depth, const bool recurse)=0
Probability, optimization and sampling library.
virtual argument * arg(const std::string &name)
Definition: argument.hpp:74
static void split_arg(const std::string &arg, std::string &name, std::string &value)
Definition: argument.hpp:60
std::string _description
Definition: argument.hpp:84
virtual void probe_args(argument *base_arg, interface_callbacks::writer::base_writer &w)
Definition: argument.hpp:49
int compute_indent(const int depth)
Definition: argument.hpp:78
base_writer is an abstract base class defining the interface for Stan writer callbacks.
Definition: base_writer.hpp:20
std::string description() const
Definition: argument.hpp:30
virtual void find_arg(const std::string &name, const std::string &prefix, std::vector< std::string > &valid_paths)
Definition: argument.hpp:52
virtual void print(interface_callbacks::writer::base_writer &w, const int depth, const std::string &prefix)=0
virtual bool parse_args(std::vector< std::string > &args, interface_callbacks::writer::base_writer &info, interface_callbacks::writer::base_writer &err, bool &help_flag)
Definition: argument.hpp:42
argument(const std::string &name)
Definition: argument.hpp:19
std::string name() const
Definition: argument.hpp:26

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