5 #ifndef DYNAMIC_GRAPH_LOGGER_REAL_TIME_DEF_H 6 #define DYNAMIC_GRAPH_LOGGER_REAL_TIME_DEF_H 10 #include <boost/shared_ptr.hpp> 11 #include <boost/thread/mutex.hpp> 13 #include <dynamic-graph/config.hh> 25 virtual void write(
const char *c) = 0;
35 virtual void write(
const char *c) { os_ << c; }
40 typedef boost::shared_ptr<LoggerStream> LoggerStreamPtr_t;
49 class RTLoggerStream {
52 : ok_(logger != NULL), logger_(logger), os_(os) {}
53 template <
typename T>
inline RTLoggerStream &operator<<(T t) {
58 inline RTLoggerStream &operator<<(std::ostream &(*pf)(std::ostream &)) {
64 inline ~RTLoggerStream();
66 inline bool isNull() {
return !ok_; }
102 static void destroy();
108 inline void clearOutputStreams() { outputs_.clear(); }
110 inline void addOutputStream(
const LoggerStreamPtr_t &os) {
111 outputs_.push_back(os);
121 RTLoggerStream front();
124 RTLoggerStream
emptyStream() {
return RTLoggerStream(NULL, oss_); }
126 inline void frontReady() {
127 backIdx_ = (backIdx_ + 1) % buffer_.size();
131 inline bool empty()
const {
return frontIdx_ == backIdx_; }
133 inline bool full()
const {
134 return ((backIdx_ + 1) % buffer_.size()) == frontIdx_;
137 inline std::size_t size()
const {
138 if (frontIdx_ <= backIdx_)
139 return backIdx_ - frontIdx_;
141 return backIdx_ + buffer_.size() - frontIdx_;
144 inline std::size_t getBufferSize() {
return buffer_.size(); }
153 std::vector<LoggerStreamPtr_t> outputs_;
154 std::vector<Data *> buffer_;
156 std::size_t frontIdx_;
159 std::size_t backIdx_;
164 std::size_t nbDiscarded_;
169 static thread *thread_;
172 RTLoggerStream::~RTLoggerStream() {
175 logger_->frontReady();
Main class of the real-time logger.
Stream for the real-time logger.
RTLoggerStream emptyStream()
Return an empty stream object.