Commit 33d3e740 authored by Martin Marinov's avatar Martin Marinov
Browse files

Improved various features in the debugging system; added dump of feature...

Improved various features in the debugging system; added dump of feature edges, and selected faces and vertices. Changed some debugging code in the CrossFieldT.

[git-p4: depot-paths = "//ReForm/ReForm/main/Base/": change = 11424]
parent 3f53978c
......@@ -11,19 +11,19 @@
#ifndef REFORM_DEBOUT_HH_INCLUDED
#define REFORM_DEBOUT_HH_INCLUDED
// DEB_ON is defined, or not, in Cmakelists.txt for primary project
//#define DEB_ON 1
// DEB_ON is defined, or not, in CMakeLists.txt for primary project
#ifndef DEB_ON
#define DEB_module(SS)
#define DEB_enter_func
#define DEB_only( CC )
#define DEB_out(LL, AA ) {}
#define DEB_out_if( CC, LL, AA ) {}
#define DEB_warning( LL, AA ) {}
#define DEB_warning_if( CC, LL, AA ) {}
#define DEB_mesh_if( CC, LL, FF, MM ) {}
#define DEB_only(CC)
#define DEB_out(LL, AA) {}
#define DEB_out_if(CC, LL, AA) {}
#define DEB_line(LL, AA) {}
#define DEB_line_if(CC, LL, AA) {}
#define DEB_warning(LL, AA) {}
#define DEB_warning_if(CC, LL, AA) {}
#define DEB_mesh_if(CC, LL, FF, MM) {}
#define DEB_error(AA) {}
#define DEB_error_if(CC, AA) {}
......@@ -33,43 +33,47 @@
#include <string>
#include <vector>
#define DEB_module(SS) static const char * l_g_module = SS;
#define DEB_module(SS) static const char* l_g_module = SS;
/* TODO: This should use an atomic thread safe static int
*/
#define DEB_enter_func static int deb_enter_count =0; \
ReForm::DebEnter deb(__FUNCTION__, deb_enter_count++, l_g_module);
#define DEB_enter_func static int deb_enter_count = 0; \
Debug::Enter deb(__FUNCTION__, deb_enter_count++, l_g_module);
#define DEB_only( CC ) CC
#define DEB_only(CC) CC
#define DEB_out(LL, AA ) DEB_out_if(true, LL, AA)
#define DEB_out(LL, AA) DEB_out_if(true, LL, AA)
#define DEB_out_if( CC, LL, AA ) { if (deb.permission(LL) && (CC)) \
{ deb.stream() << AA << deb.end(); } }
#define DEB_out_if(CC, LL, AA) { if (deb.permission(LL) && (CC)) \
{ deb.stream() << AA << deb.end(); } }
#define DEB_warning(LL, AA ) DEB_warning_if(true, LL, AA)
#define DEB_line(LL, AA) DEB_line_if(true, LL, AA)
#define DEB_warning_if( CC, LL, AA ) { if (deb.permission(LL, 1) && (CC)) \
{ deb.stream(1) << "WARNING: " << AA << deb.end_lf(); } }
#define DEB_line_if(CC, LL, AA) { if (deb.permission(LL) && (CC)) \
{ deb.stream() << AA << deb.end_lf(); } }
#define DEB_warning(LL, AA) DEB_warning_if(true, LL, AA)
#define DEB_error(AA) { if (deb.permission(0, 1) )\
{ deb.stream(2) << "ERROR: " << AA << deb.end_err(); } }
#define DEB_warning_if(CC, LL, AA) { if (deb.permission(LL, 1) && (CC)) \
{ deb.stream(1) << "WARNING: " << AA << deb.end_lf(); } }
#define DEB_error_if(CC, AA) if (CC) DEB_error(AA)
#define DEB_error(AA) DEB_error_if(true, AA)
#define DEB_error_if(CC, AA) { if (deb.permission(0, 1) && (CC)) \
{ deb.stream(2) << "ERROR: " << AA << deb.end_err(); } }
// DebStream does not fulfill ostream. If you want to exploit an existing
// Stream does not fulfill ostream. If you want to exploit an existing
// ostream streamer to DEB_out a class as text without exploiting any
// numeric processing or custom DebStream streamers then use this macro thus
// numeric processing or custom Stream streamers then use this macro thus
// DEB_out(1, "my_class is " << DEB_os_str(my_c) )
#define DEB_os_str(AA) dynamic_cast<std::ostringstream &>((std::ostringstream() << AA )).str()
#define DEB_os_str(AA) \
dynamic_cast<std::ostringstream &>((std::ostringstream() << AA )).str()
namespace ReForm {
namespace Debug {
class DebStream;
class Stream;
class DebCommand
class Command
{
public:
enum CommandType
......@@ -78,23 +82,25 @@ public:
END_LF = 0x03,
END_ERR = 0x07
};
CommandType com_;
CommandType com() const
{
return com_;
}
DebCommand(CommandType _com) : com_(_com) {}
~DebCommand() {};
Command(CommandType _com) : com_(_com) {}
};
// Class used to maintain DebStream's CallStack
// Class used to maintain Stream's CallStack
// This does not currently contain a pointer to the file streamer used
// but might do in future.
class DebEnter
class Enter
{
public:
int id_; /*!< Unique identifier for this DebEnter (used in ANCHORS) */
int id_; /*!< Unique identifier for this Enter (used in ANCHORS) */
int count_; /*!< deb_enter_count for this function. */
int deb_outs_; /*!< Number of DEB_outs encountered within this function
determining whether a given DEB_out should include or omit
......@@ -102,29 +108,28 @@ public:
int deb_lines_; /*!< Number of call stack indents including this call. */
const char* module_; /*!< Module name for this DEB_enter. */
DebEnter(const char* const _funcname, const int _count, const char* const _module);
~DebEnter();
DebStream& stream(const int _warn = 0, const bool _print = true);
Enter(const char* const _funcname, const int _count, const char* const _module);
~Enter();
Stream& stream(const int _warn = 0, const bool _print = true);
int permission(const int _lev, const int _warn = 0);
DebCommand end()
Command end()
{
return DebCommand(DebCommand::CommandType::END);
return Command(Command::CommandType::END);
}
DebCommand end_lf()
Command end_lf()
{
return DebCommand(DebCommand::CommandType::END_LF);
return Command(Command::CommandType::END_LF);
}
DebCommand end_err()
Command end_err()
{
return DebCommand(DebCommand::CommandType::END_ERR);
return Command(Command::CommandType::END_ERR);
}
};
class File;
class DebFile;
class DebStream
class Stream
{
public:
enum StreamType
......@@ -139,48 +144,48 @@ public:
};
private:
DebFile* dfile_;
File* dfile_;
public:
DebFile* dfile() const
File* dfile() const
{
return this ? dfile_ : nullptr;
}
//! Constructor.
DebStream(
Stream(
const char* _file_name = nullptr, //!< [in] File name if file based.
const StreamType _type = APPEND //!< [in] bitsfield enum type identifier
) ;
~DebStream();
~Stream();
const char* string_out() const;
DebStream& print(const int);
DebStream& print(const double);
DebStream& print(const char* const, bool fork = true);
DebStream& print(const char);
DebStream& print(const DebCommand&);
Stream& print(const int);
Stream& print(const double);
Stream& print(const char* const, bool fork = true);
Stream& print(const char);
Stream& print(const Command&);
//! Get the currently active DebStream
static DebStream& get_global(int _warn = 0);
//! Get the currently active Stream
static Stream& get_global(int _warn = 0);
};
DebStream& operator<<(DebStream& _ds, const int i);
DebStream& operator<<(DebStream& _ds, const double d);
Stream& operator<<(Stream& _ds, const int i);
Stream& operator<<(Stream& _ds, const double d);
DebStream& operator<<(DebStream& _ds, const size_t i);
DebStream& operator<<(DebStream& _ds, const unsigned int i);
DebStream& operator<<(DebStream& _ds, const float d);
Stream& operator<<(Stream& _ds, const size_t i);
Stream& operator<<(Stream& _ds, const unsigned int i);
Stream& operator<<(Stream& _ds, const float d);
DebStream& operator<<(DebStream& _ds, const char c);
DebStream& operator<<(DebStream& _ds, const char* const s);
DebStream& operator<<(DebStream& _ds, const std::string& s);
Stream& operator<<(Stream& _ds, const char c);
Stream& operator<<(Stream& _ds, const char* const s);
Stream& operator<<(Stream& _ds, const std::string& s);
DebStream& operator<<(DebStream& _ds, const DebCommand& co);
Stream& operator<<(Stream& _ds, const Command& co);
// DebStream operator for std::vector<>
// Stream operator for std::vector<>
template< typename ElementT>
DebStream& operator<<(DebStream& _ds, const std::vector<ElementT>& _vec)
Stream& operator<<(Stream& _ds, const std::vector<ElementT>& _vec)
{
_ds << "[ ";
for (const auto el : _vec)
......@@ -189,9 +194,9 @@ DebStream& operator<<(DebStream& _ds, const std::vector<ElementT>& _vec)
return _ds;
}
// DebStream operator for fixed size arrays
// Stream operator for fixed size arrays
template <typename ElementT, size_t _el_nmbr>
DebStream& operator<<(DebStream& _ds, const ElementT (&_arr)[_el_nmbr])
Stream& operator<<(Stream& _ds, const ElementT(&_arr)[_el_nmbr])
{
_ds << "[ ";
for (const auto el : _arr)
......
......@@ -30,22 +30,22 @@ bool is_html_filename(const char* const str)
}
}
namespace ReForm {
namespace Debug {
class FunctionCallSequence
{
std::string func_name_;
std::vector<DebEnter*> debs_; // These may not have sequential counts when multithreaded.
std::vector<Enter*> debs_; // These may not have sequential counts when multithreaded.
public:
FunctionCallSequence(const char* _func_name, DebEnter* _deb)
FunctionCallSequence(const char* _func_name, Enter* _deb)
: func_name_(_func_name)
{
debs_.push_back(_deb);
}
~FunctionCallSequence() {}
bool add(const char* _func_name, DebEnter* _deb)
bool add(const char* _func_name, Enter* _deb)
{
if (func_name_ == _func_name)
{
......@@ -142,7 +142,7 @@ public:
_str.append("]");
} // endfunc get
void get_indent(std::string& _str, DebFile* _dfile, bool _is_html);
void get_indent(std::string& _str, File* _dfile, bool _is_html);
}; // endclass FunctionCallSequence
......@@ -155,7 +155,7 @@ public:
CallStack() : depth_(0) {}
~CallStack() {}
void add(const char* _func_name, DebEnter* _deb)
void add(const char* _func_name, Enter* _deb)
{
if (calls_.empty() || !calls_.back().add(_func_name, _deb))
calls_.push_back(FunctionCallSequence(_func_name, _deb));
......@@ -207,12 +207,12 @@ public:
return depth_;
}
bool get_indent(std::string& _str, DebFile* _dfile, const bool is_html);
bool get_indent(std::string& _str, File* _dfile, const bool is_html);
}; // endclass CallStack
class DebFile
class File
{
private:
class module_stats
......@@ -228,7 +228,7 @@ private:
typedef std::map<std::string, module_stats>::iterator module_map_itr;
typedef std::map<std::string, module_stats>::const_iterator const_module_map_itr;
DebStream::StreamType type_;
Stream::StreamType type_;
int lev_;
int num_flush_;
int priority_; // Last permission granted
......@@ -243,7 +243,7 @@ private:
std::string double_format_;
//std::string indent_string_;
DebStream* deb_stream_;
Stream* deb_stream_;
CallStack call_stack_;
public:
......@@ -255,19 +255,19 @@ public:
bool is_kept_open() const
{
return 0 != (type_ & DebStream::StreamType::KEEP_OPEN);
return 0 != (type_ & Stream::StreamType::KEEP_OPEN);
}
bool is_html() const
{
return 0 != (type_ & DebStream::StreamType::HTML);
return 0 != (type_ & Stream::StreamType::HTML);
}
bool is_retained() const
{
return 0 != (type_ & DebStream::StreamType::RETAIN);
return 0 != (type_ & Stream::StreamType::RETAIN);
}
bool is_appended() const
{
return 0 != (type_ & DebStream::StreamType::APPEND);
return 0 != (type_ & Stream::StreamType::APPEND);
}
// Only applies to HTML DEB_out
bool is_white_on_black() const
......@@ -436,25 +436,25 @@ public:
print(buffer);
}
void print(const DebCommand& _co)
void print(const Command& _co)
{
switch (_co.com())
{
case DebCommand::END :
case Command::END :
if (is_html()) print_direct("</FONT>");
break;
case DebCommand::END_ERR :
case Command::END_ERR :
// Powerdown DEB_error font
// if (is_html()) print_direct("</BLINK>");
// fall through
case DebCommand::END_LF :
case Command::END_LF :
if (is_html()) print_direct("</FONT>");
line_break();
break;
}
}
DebStream& stream()
Stream& stream()
{
return *deb_stream_;
}
......@@ -664,7 +664,7 @@ public:
{
file_name_ = _name ? _name : "";
if (is_html_filename(_name))
type_ = (DebStream::StreamType)(type_ | DebStream::StreamType::HTML);
type_ = (Stream::StreamType)(type_ | Stream::StreamType::HTML);
}
void set_module_level(const char* const _module, const int _lev)
......@@ -723,9 +723,9 @@ public:
}
DebFile(
DebStream* _deb_stream,
DebStream::StreamType _type = (DebStream::StreamType)(DebStream::APPEND | DebStream::RETAIN),
File(
Stream* _deb_stream,
Stream::StreamType _type = (Stream::StreamType)(Stream::APPEND | Stream::RETAIN),
const char* _file_name = nullptr) :
type_(_type), lev_(5), deb_stream_(_deb_stream), num_flush_(0)
{
......@@ -754,12 +754,12 @@ public:
}
~DebFile()
~File()
{
// The closing of the primary DEB_out file is a good place to flush and close
// any subsidary DEB files
#ifdef DEB_SHOW_ON
if (type_ & DebStream::PRIMARY)
if (type_ & Stream::PRIMARY)
{
DebShow::DebShowStream os;
os << file_name_ << " closing";
......@@ -769,13 +769,13 @@ public:
}
}; // endclass DebFile
}; // endclass File
// =====================================
// DebEnter member funcs
// Enter member funcs
// =====================================
DebEnter::DebEnter(const char* const _funcname, const int _count, const char* const _module)
Enter::Enter(const char* const _funcname, const int _count, const char* const _module)
{
// TODO: this might have to be atomic
static int id_cnt = 0;
......@@ -787,9 +787,9 @@ DebEnter::DebEnter(const char* const _funcname, const int _count, const char* co
stream(0, false).dfile()->call_stack().add(_funcname, this);
}
DebEnter::~DebEnter()
Enter::~Enter()
{
DebFile* impl = stream(0, false).dfile();
File* impl = stream(0, false).dfile();
impl->call_stack().pop();
std::string str;
......@@ -800,10 +800,10 @@ DebEnter::~DebEnter()
}
}
DebStream& DebEnter::stream(const int _warn, const bool _print)
Stream& Enter::stream(const int _warn, const bool _print)
{
DebStream& ds = ReForm::DebStream::get_global(_warn);
DebFile* impl = ds.dfile();
Stream& ds = Stream::get_global(_warn);
File* impl = ds.dfile();
if (_print)
{
......@@ -849,19 +849,19 @@ DebStream& DebEnter::stream(const int _warn, const bool _print)
return ds;
}
int DebEnter::permission(const int _lev, const int _warn)
int Enter::permission(const int _lev, const int _warn)
{
int res = ReForm::DebStream::get_global().dfile()->permission(_lev, _warn, module_);
int res = Stream::get_global().dfile()->permission(_lev, _warn, module_);
return res;
}
void FunctionCallSequence::get_indent(std::string& _str, DebFile* _dfile, bool _is_html)
void FunctionCallSequence::get_indent(std::string& _str, File* _dfile, bool _is_html)
{
int num = number_calls();
for (int i = 0; i < num; ++i)
{
DebEnter* deb = debs_[i];
Enter* deb = debs_[i];
if (_is_html)
{
/* HTML indent element is <L> with span title the name and count
......@@ -903,7 +903,7 @@ void FunctionCallSequence::get_indent(std::string& _str, DebFile* _dfile, bool _
}
}
bool CallStack::get_indent(std::string& _str, DebFile* _dfile, const bool is_html)
bool CallStack::get_indent(std::string& _str, File* _dfile, const bool is_html)
{
if (_dfile->indent_size() == 0) return false;
......@@ -924,17 +924,17 @@ bool CallStack::get_indent(std::string& _str, DebFile* _dfile, const bool is_htm
// =====================================
// DebStream member funcs
// Stream member funcs
// =====================================
DebStream::DebStream(const char* _file_name, StreamType _type)
Stream::Stream(const char* _file_name, StreamType _type)
{
// NB. disable DEB_out over this new if new contains DEB_out
dfile_ = new DebFile(this, _type, _file_name);
dfile_ = new File(this, _type, _file_name);
}
DebStream::~DebStream()
Stream::~Stream()
{
if (dfile_ != nullptr)
{
......@@ -946,121 +946,120 @@ DebStream::~DebStream()
}
}
const char * DebStream::string_out() const
const char * Stream::string_out() const
{ return dfile()->string_out();}
DebStream& DebStream::print(const int _i)
Stream& Stream::print(const int _i)
{
dfile_->print(_i);
return *this;
};
DebStream& DebStream::print(const double _d)
Stream& Stream::print(const double _d)
{
dfile_->print(_d);
return *this;
};
DebStream& DebStream::print(const char* _s, bool _fork)
Stream& Stream::print(const char* _s, bool _fork)
{
dfile_->print(_s, _fork);
return *this;
};
DebStream& DebStream::print(const char _c)
Stream& Stream::print(const char _c)
{
dfile_->print(_c);
return *this;
};
DebStream& DebStream::print(const DebCommand& _co)
Stream& Stream::print(const Command& _co)
{
dfile_->print(_co);
return *this;
};
DebStream& DebStream::get_global(int _warn)
Stream& Stream::get_global(int _warn)
{
_warn;
// TODO: Replace with a Singleton?? ThreadArray??
#ifdef DEB_SHOW_ON
static DebStream g_ds__(
static Stream g_ds__(
"../../../../test/logs/reform_deb_out.htm",
(StreamType)(APPEND | PRIMARY) );
#else // DEB_SHOW_ON
static DebStream g_ds__("reform_deb_out.txt");
static Stream g_ds__("reform_deb_out.txt");
#endif // DEB_SHOW_ON
return g_ds__;
}
DebStream& operator<<(DebStream& _ds, const int _i)
Stream& operator<<(Stream& _ds, const int _i)
{
return _ds.print(_i);
}
DebStream& operator<<(DebStream& _ds, const double _d)
Stream& operator<<(Stream& _ds, const double _d)
{
return _ds.print(_d);
}
DebStream& operator<<(DebStream& _ds, const char* const _s)
Stream& operator<<(Stream& _ds, const char* const _s)
{
return _ds.print(_s);
}
DebStream& operator<<(DebStream& _ds, const char _c)
Stream& operator<<(Stream& _ds, const char _c)
{
return _ds.print(_c);
}
DebStream& operator<<(DebStream& _ds, const size_t _i)
Stream& operator<<(Stream& _ds, const size_t _i)
{
return _ds.print((int)_i);
}
DebStream& operator<<(DebStream& _ds, const unsigned int _i)
Stream& operator<<(Stream& _ds, const unsigned int _i)
{
return _ds.print((int)_i);
}
DebStream& operator<<(DebStream& _ds, const float _f)
Stream& operator<<(Stream& _ds, const float _f)
{
return _ds.print((double)_f);
}
DebStream& operator<<(DebStream& _ds, const std::string& _s)
Stream& operator<<(Stream& _ds, const std::string& _s)
{
return _ds.print(_s.c_str());
}
DebStream& operator<<(DebStream& _ds, const DebCommand& _co)
Stream& operator<<(Stream& _ds, const Command& _co)
{
return _ds.print(_co);
}
// ==================================================
// DebController member funcs (currently all static)
// Controller member funcs (currently all static)
// ==================================================
void DebController::set_module_level(const char* _mod , const int _lev)
void Controller::set_module_level(const char* _mod , const int _lev)
{
DebStream::get_global().dfile()->set_module_level(_mod, _lev);
Stream::get_global().dfile()->set_module_level(_mod, _lev);
}