Stan  2.14.0
probability, sampling & optimization
variable_map_def.hpp
Go to the documentation of this file.
1 #ifndef STAN_LANG_AST_VARIABLE_MAP_DEF_HPP
2 #define STAN_LANG_AST_VARIABLE_MAP_DEF_HPP
3 
4 #include <stan/lang/ast.hpp>
5 #include <string>
6 
7 namespace stan {
8  namespace lang {
9 
10  bool variable_map::exists(const std::string& name) const {
11  return map_.find(name) != map_.end();
12  }
13 
14  base_var_decl variable_map::get(const std::string& name) const {
15  if (!exists(name))
16  throw std::invalid_argument("variable does not exist");
17  return map_.find(name)->second.first;
18  }
19 
20  base_expr_type variable_map::get_base_type(const std::string& name) const {
21  return get(name).base_type_;
22  }
23 
24  size_t variable_map::get_num_dims(const std::string& name) const {
25  return get(name).dims_.size();
26  }
27 
28  var_origin variable_map::get_origin(const std::string& name) const {
29  if (!exists(name))
30  throw std::invalid_argument("variable does not exist");
31  return map_.find(name)->second.second;
32  }
33 
34  void variable_map::add(const std::string& name,
35  const base_var_decl& base_decl,
36  const var_origin& vo) {
37  map_[name] = range_t(base_decl, vo);
38  }
39 
40  void variable_map::remove(const std::string& name) {
41  map_.erase(name);
42  }
43 
44  }
45 }
46 #endif
Probability, optimization and sampling library.
std::pair< base_var_decl, var_origin > range_t
A variable type and the origin of its declaration.
void add(const std::string &name, const base_var_decl &base_decl, const var_origin &vo)
Add the specified declaration for a variable with the specified name originating in the specified blo...
int base_expr_type
The type of a base expression.
void remove(const std::string &name)
Remove the declaraiton for the variable with the specified name.
bool exists(const std::string &name) const
Return true if a variable has been declared with the specified name.
std::size_t get_num_dims(const std::string &name) const
Return the number of dimensions declared for the variable with the specified name.
var_origin get_origin(const std::string &name) const
Return the origin of the variable declaration for the variable with the specified name...
int var_origin
The type of a variable indicating where a variable was declared.
Definition: var_origin.hpp:12
AST base class for variable declarations, which share most of their structure.
std::map< std::string, range_t > map_
The stored map from function names to their declarations and origins.
base_expr_type get_base_type(const std::string &name) const
Return the type declared for the variable with the specified name.
base_var_decl get(const std::string &name) const
Return the type for the variable with the specified name.

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