Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
csv.hpp
Go to the documentation of this file.
1 #ifndef STAN__COMMON__RECORDER__CSV_HPP
2 #define STAN__COMMON__RECORDER__CSV_HPP
3 
4 #include <ostream>
5 #include <string>
6 #include <vector>
7 
9 
10 namespace stan {
11 
12  namespace common {
13 
14  namespace recorder {
15 
19  class csv {
20  private:
21  std::ostream *o_;
22  const bool has_stream_;
23  const std::string prefix_;
24 
25  public:
31  csv(std::ostream *o, std::string prefix)
32  : o_(o), has_stream_(o != 0), prefix_(prefix) { }
33 
44  template <class T>
45  void operator()(const std::vector<T>& x) {
46  typedef typename stan::math::index_type<std::vector<T> >::type idx_t;
47  if (!has_stream_)
48  return;
49 
50  if (x.size() != 0) {
51  *o_ << x[0];
52  for (idx_t n = 1; n < x.size(); n++) {
53  *o_ << "," << x[n];
54  }
55  }
56  *o_ << std::endl;
57  }
58 
68  void operator()(const std::string x) {
69  if (!has_stream_)
70  return;
71  *o_ << prefix_ << x << std::endl;
72  }
73 
78  void operator()() {
79  if (!has_stream_)
80  return;
81  *o_ << std::endl;
82  }
83 
89  bool is_recording() const {
90  return has_stream_;
91  }
92  };
93 
94 
95  }
96  }
97 }
98 
99 #endif
void operator()(const std::string x)
Print single string with a prefix.
Definition: csv.hpp:68
void operator()(const std::vector< T > &x)
Print vector as csv.
Definition: csv.hpp:45
Writes out a vector as string.
Definition: csv.hpp:19
bool is_recording() const
Indicator function for whether the instance is recording.
Definition: csv.hpp:89
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:21
csv(std::ostream *o, std::string prefix)
Construct an object.
Definition: csv.hpp:31
void operator()()
Prints a blank line.
Definition: csv.hpp:78

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