Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
values.hpp
Go to the documentation of this file.
1 #ifndef STAN__COMMON__RECORDER__VALUES_HPP
2 #define STAN__COMMON__RECORDER__VALUES_HPP
3 
4 #include <ostream>
5 #include <string>
6 #include <stdexcept>
7 #include <vector>
8 
9 namespace stan {
10  namespace common {
11  namespace recorder {
12 
13  template <class InternalVector>
14  class values {
15  private:
16  size_t m_;
17  size_t N_;
18  size_t M_;
19  std::vector<InternalVector> x_;
20 
21  public:
22 
23  values(const size_t N,
24  const size_t M)
25  : m_(0), N_(N), M_(M) {
26  x_.reserve(N_);
27  for (size_t n = 0; n < N_; n++)
28  x_.push_back(InternalVector(M_));
29  }
30 
31  values(const std::vector<InternalVector>& x)
32  : m_(0), N_(x.size()), M_(0),
33  x_(x) {
34  if (N_ > 0)
35  M_ = x_[0].size();
36  }
37 
38  void operator()(const std::vector<std::string>& x) { }
39 
40  template <class T>
41  void operator()(const std::vector<T>& x) {
42  if (N_ != x.size())
43  throw std::length_error("vector provided does not match the parameter length");
44  if (m_ == M_)
45  throw std::out_of_range("");
46  for (size_t n = 0; n < N_; n++)
47  x_[n][m_] = x[n];
48  m_++;
49  }
50 
51  void operator()(const std::string x) { }
52 
53  void operator()() { }
54 
55  bool is_recording() const {
56  if (m_ < M_)
57  return true;
58  return false;
59  }
60 
61  const std::vector<InternalVector>& x() const {
62  return x_;
63  }
64  };
65 
66  }
67  }
68 }
69 
70 #endif
values(const size_t N, const size_t M)
Definition: values.hpp:23
void operator()(const std::string x)
Definition: values.hpp:51
bool is_recording() const
Definition: values.hpp:55
void operator()(const std::vector< T > &x)
Definition: values.hpp:41
const std::vector< InternalVector > & x() const
Definition: values.hpp:61
values(const std::vector< InternalVector > &x)
Definition: values.hpp:31
int size(const std::vector< T > &x)
Definition: size.hpp:11
void operator()(const std::vector< std::string > &x)
Definition: values.hpp:38

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