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;
36 virtual void write(
const char *c) { os_ << c; }
41 typedef boost::shared_ptr<LoggerStream> LoggerStreamPtr_t;
50 class RTLoggerStream {
53 : ok_(logger != NULL), logger_(logger), os_(os) {}
54 template <
typename T>
inline RTLoggerStream &operator<<(T t) {
59 inline RTLoggerStream &operator<<(std::ostream &(*pf)(std::ostream &)) {
65 inline ~RTLoggerStream();
67 inline bool isNull() {
return !ok_; }
103 static void destroy();
109 inline void clearOutputStreams() { outputs_.clear(); }
111 inline void addOutputStream(
const LoggerStreamPtr_t &os) {
112 outputs_.push_back(os);
122 RTLoggerStream front();
125 RTLoggerStream
emptyStream() {
return RTLoggerStream(NULL, oss_); }
127 inline void frontReady() {
128 backIdx_ = (backIdx_ + 1) % buffer_.size();
132 inline bool empty()
const {
return frontIdx_ == backIdx_; }
134 inline bool full()
const {
135 return ((backIdx_ + 1) % buffer_.size()) == frontIdx_;
138 inline std::size_t size()
const {
139 if (frontIdx_ <= backIdx_)
140 return backIdx_ - frontIdx_;
142 return backIdx_ + buffer_.size() - frontIdx_;
145 inline std::size_t getBufferSize() {
return buffer_.size(); }
154 std::vector<LoggerStreamPtr_t> outputs_;
155 std::vector<Data *> buffer_;
157 std::size_t frontIdx_;
160 std::size_t backIdx_;
165 std::size_t nbDiscarded_;
170 static thread *thread_;
173 RTLoggerStream::~RTLoggerStream() {
176 logger_->frontReady();
Main class of the real-time logger.
Stream for the real-time logger.
RTLoggerStream emptyStream()
Return an empty stream object.