1 #ifndef STAN_INTERFACE_CALLBACKS_WRITER_STREAM_WRITER_HPP
2 #define STAN_INTERFACE_CALLBACKS_WRITER_STREAM_WRITER_HPP
10 namespace interface_callbacks {
26 const std::string& key_value_prefix =
""):
27 output__(output), key_value_prefix__(key_value_prefix) {}
30 output__ << key_value_prefix__ << key <<
" = " << value << std::endl;
34 output__ << key_value_prefix__ << key <<
" = " << value << std::endl;
37 void operator()(
const std::string& key,
const std::string& value) {
38 output__ << key_value_prefix__ << key <<
" = " << value << std::endl;
44 if (n_values == 0)
return;
46 output__ << key_value_prefix__ << key <<
": ";
48 output__ << values[0];
49 for (
int n = 1; n < n_values; ++n)
50 output__ <<
"," << values[n];
51 output__ << std::endl;
56 int n_rows,
int n_cols) {
57 if (n_rows == 0 || n_cols == 0)
return;
59 output__ << key_value_prefix__ << key << std::endl;
61 for (
int i = 0; i < n_rows; ++i) {
62 output__ << key_value_prefix__ << values[i * n_cols];
63 for (
int j = 1; j < n_cols; ++j)
64 output__ <<
"," << values[i * n_cols + j];
65 output__ << std::endl;
70 if (names.empty())
return;
72 std::vector<std::string>::const_iterator last = names.end();
75 for (std::vector<std::string>::const_iterator it = names.begin();
77 output__ << *it <<
",";
78 output__ << names.back() << std::endl;
82 if (state.empty())
return;
84 std::vector<double>::const_iterator last = state.end();
87 for (std::vector<double>::const_iterator it = state.begin();
89 output__ << *it <<
",";
90 output__ << state.back() << std::endl;
94 output__ << key_value_prefix__ << std::endl;
98 output__ << key_value_prefix__ << message << std::endl;
102 std::ostream& output__;
103 std::string key_value_prefix__;
stream_writer writes to an std::ostream.
Probability, optimization and sampling library.
void operator()(const std::string &key, double value)
Writes a key, value pair.
void operator()()
Writes blank input.
void operator()(const std::string &key, const double *values, int n_rows, int n_cols)
Writes a key, value pair.
void operator()(const std::vector< std::string > &names)
Writes a set of names.
void operator()(const std::string &key, int value)
Writes a key, value pair.
void operator()(const std::string &key, const double *values, int n_values)
Writes a key, value pair.
base_writer is an abstract base class defining the interface for Stan writer callbacks.
void operator()(const std::vector< double > &state)
Writes a set of values.
stream_writer(std::ostream &output, const std::string &key_value_prefix="")
Constructor.
void operator()(const std::string &key, const std::string &value)
Writes a key, value pair.
void operator()(const std::string &message)
Writes a string.