Lots of work on debugging diff xmit
This commit is contained in:
50
luprex/core/cpp/debugcollector.hpp
Normal file
50
luprex/core/cpp/debugcollector.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#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
|
||||
|
||||
Reference in New Issue
Block a user