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

51 lines
1.3 KiB
C++
Raw Normal View History

2021-11-21 13:35:39 -05:00
#ifndef DEBUGCOLLECTOR_HPP
#define DEBUGCOLLECTOR_HPP
#include <vector>
#include <string>
#include <memory>
#include <ostream>
#include <sstream>
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.
std::vector<std::string> lines_;
std::vector<std::string> targets_;
int n_regular_;
bool need_flush_;
bool is_regular_;
bool active_;
void flush();
bool use(const char *target);
public:
std::ostringstream oss_;
DebugCollector();
DebugCollector(const std::string &targets);
bool do_header();
bool do_line();
void dump(std::ostream &os);
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