5 #ifndef DYNAMIC_GRAPH_LOGGER_REAL_TIME_DEF_H
6 #define DYNAMIC_GRAPH_LOGGER_REAL_TIME_DEF_H
7 #include <boost/shared_ptr.hpp>
8 #include <boost/thread/mutex.hpp>
9 #include <dynamic-graph/config.hh>
23 virtual void write(
const char *c) = 0;
34 virtual void write(
const char *c) { os_ << c; }
39 typedef boost::shared_ptr<LoggerStream> LoggerStreamPtr_t;
48 class RTLoggerStream {
51 : ok_(logger != NULL), logger_(logger), os_(os) {}
53 inline RTLoggerStream &operator<<(T t) {
57 inline RTLoggerStream &operator<<(std::ostream &(*pf)(std::ostream &)) {
62 inline ~RTLoggerStream();
64 inline bool isNull() {
return !ok_; }
68 RealTimeLogger *logger_;
100 static void destroy();
106 inline void clearOutputStreams() { outputs_.clear(); }
108 inline void addOutputStream(
const LoggerStreamPtr_t &os) {
109 outputs_.push_back(os);
119 RTLoggerStream front();
122 RTLoggerStream
emptyStream() {
return RTLoggerStream(NULL, oss_); }
124 inline void frontReady() {
125 backIdx_ = (backIdx_ + 1) % buffer_.size();
129 inline bool empty()
const {
return frontIdx_ == backIdx_; }
131 inline bool full()
const {
132 return ((backIdx_ + 1) % buffer_.size()) == frontIdx_;
135 inline std::size_t size()
const {
136 if (frontIdx_ <= backIdx_)
137 return backIdx_ - frontIdx_;
139 return backIdx_ + buffer_.size() - frontIdx_;
142 inline std::size_t getBufferSize() {
return buffer_.size(); }
151 std::vector<LoggerStreamPtr_t> outputs_;
152 std::vector<Data *> buffer_;
154 std::size_t frontIdx_;
157 std::size_t backIdx_;
162 std::size_t nbDiscarded_;
166 static RealTimeLogger *instance_;
167 static thread *thread_;
170 RTLoggerStream::~RTLoggerStream() {
173 logger_->frontReady();