Files
integration/luprex/core/cpp/debugcollector.hpp

52 lines
1.3 KiB
C++
Raw Normal View History

2021-11-21 13:35:39 -05:00
#ifndef DEBUGCOLLECTOR_HPP
#define DEBUGCOLLECTOR_HPP
#include "wrap-vector.hpp"
#include "wrap-string.hpp"
#include "wrap-sstream.hpp"
#include <ostream>
#include <memory>
2021-11-21 13:35:39 -05:00
class DebugCollector {
private:
// At any given time, the stringstream may contain one
// extra line that hasn't yet been appended to the list of lines.
// The flag 'need_flush_' is true if the stringstream contains
// an extra line. In that case, is_regular_ indicates whether
// the extra line is a header or a regular line.
eng::vector<eng::string> lines_;
eng::vector<eng::string> targets_;
2021-11-21 13:35:39 -05:00
int n_regular_;
bool need_flush_;
bool is_regular_;
bool active_;
void flush();
bool use(const char *target);
public:
eng::ostringstream oss_;
2021-11-21 13:35:39 -05:00
DebugCollector();
DebugCollector(const eng::string &targets);
2021-11-21 13:35:39 -05:00
bool do_header();
bool do_line();
void dump(std::ostream &os);
2021-11-21 13:35:39 -05:00
friend class DebugBlock;
};
class DebugBlock {
private:
DebugCollector *dbc_;
int n_regular_;
size_t n_lines_;
bool active_;
public:
DebugBlock(DebugCollector *dbc, const char *target);
~DebugBlock();
};
#define DebugHeader(dbc) if (((dbc)!=nullptr) && (dbc)->do_header()) ((dbc)->oss_)
#define DebugLine(dbc) if (((dbc)!=nullptr) && (dbc)->do_line()) ((dbc)->oss_)
#endif // DEBUGCOLLECTOR_HPP