1 #ifndef STAN_CALLBACKS_TEE_WRITER_HPP
2 #define STAN_CALLBACKS_TEE_WRITER_HPP
3 
4 #include <stan/callbacks/writer.hpp>
5 #include <ostream>
6 #include <vector>
7 #include <string>
8 
9 namespace stan {
10   namespace callbacks {
11 
12     /**
13      * <code>tee_writer</code> is an implementation that writes to
14      * two writers.
15      *
16      * For any call to this writer, it will tee the call to both writers
17      * provided in the constructor.
18      */
19     class tee_writer : public writer {
20     public:
21       /**
22        * Constructor accepting two writers.
23        *
24        * @param[in, out] writer1 first writer
25        * @param[in, out] writer2 second writer
26        */
tee_writer(writer & writer1,writer & writer2)27       tee_writer(writer& writer1,
28                  writer& writer2)
29         : writer1_(writer1), writer2_(writer2) {
30       }
31 
~tee_writer()32       virtual ~tee_writer() {}
33 
operator ()(const std::vector<std::string> & names)34       void operator()(const std::vector<std::string>& names) {
35         writer1_(names);
36         writer2_(names);
37       }
38 
operator ()(const std::vector<double> & state)39       void operator()(const std::vector<double>& state) {
40         writer1_(state);
41         writer2_(state);
42       }
43 
operator ()()44       void operator()() {
45         writer1_();
46         writer2_();
47       }
48 
operator ()(const std::string & message)49       void operator()(const std::string& message) {
50         writer1_(message);
51         writer2_(message);
52       }
53 
54     private:
55       /**
56        * The first writer
57        */
58       writer& writer1_;
59       /**
60        * The second writer
61        */
62       writer& writer2_;
63     };
64 
65   }
66 }
67 #endif
68