Commit c0c9c5d0 authored by Ian Bell's avatar Ian Bell
Browse files

DEB_out. Fixed issue with missing "WARNING" and line feed in warning messagss....

DEB_out. Fixed issue with missing "WARNING" and line feed in warning messagss. Made DEB_error text red in HTML, but not BLINKing as such is deprecated HTML sadly. 

 Added DEB_set_double_format() DebController mechanism.

 Renamed two callstack indent() functions get_indent() for clarity.

 Some cosmetic refactoring in accordance with ReForm coding standard (param names).

[git-p4: depot-paths = "//ReForm/ReForm/main/Base/": change = 10527]
parent d7173382
......@@ -31,8 +31,6 @@
#include <string>
namespace ReForm {}
#define DEB_module(SS) static const char * l_g_module = SS;
/* TODO: This should use an atomic thread safe static int
......@@ -49,18 +47,18 @@ namespace ReForm {}
{ deb.stream() << AA << deb.end(); } }
#define DEB_warning(LL, AA ) { if (deb.permission(LL, 1)) \
{ deb.stream(1) << AA << deb.end_lf(); } }
{ deb.stream(1) << "WARNING: " << AA << deb.end_lf(); } }
#define DEB_warning_if( CC, LL, AA ) { if (deb.permission(LL, 1) && (CC)) \
{ deb.stream(1) << AA << deb.end_lf(); } }
{ deb.stream(1) << "WARNING: " << AA << deb.end_lf(); } }
#define DEB_mesh_out_if( CC, LL, FF, MM ){ if (deb.permission(LL, 2) && (CC)) \
{ deb.stream(2) << deb.mesh(FF, MM) ; } }
{ deb.stream(3) << deb.mesh(FF, MM) ; } }
// TODO: implement Deb.mesh() filename and mesh holding class and assocated
// DebStream streamer
#define DEB_error(AA) { if (deb.permission(0, 1) )\
{ deb.stream(1) << "Error:" << AA << deb.end_lf(); } }
{ deb.stream(2) << "ERROR: " << AA << deb.end_err(); } }
#define DEB_error_if(CC, AA) if (CC) DEB_error(AA)
......@@ -80,8 +78,9 @@ class DebCommand
public:
enum CommandType
{
end = 0x01,
end_lf = 0x03
END = 0x01,
END_LF = 0x03,
END_ERR = 0x07
};
CommandType com_;
CommandType com() const
......@@ -114,11 +113,15 @@ public:
DebCommand end()
{
return DebCommand(DebCommand::CommandType::end);
return DebCommand(DebCommand::CommandType::END);
}
DebCommand end_lf()
{
return DebCommand(DebCommand::CommandType::end_lf);
return DebCommand(DebCommand::CommandType::END_LF);
}
DebCommand end_err()
{
return DebCommand(DebCommand::CommandType::END_ERR);
}
};
......@@ -130,10 +133,10 @@ class DebStream
public:
enum StreamType
{
append = 0x01,
html = 0x02,
retain = 0x04,
keep_open = 0x08
APPEND = 0x01,
HTML = 0x02,
RETAIN = 0x04,
KEEP_OPEN = 0x08
};
private:
......@@ -141,12 +144,12 @@ private:
public:
DebFile* dfile() const
{
return dfile_;
return this ? dfile_ : nullptr;
}
//! Constructor.
DebStream(
const char* _file_name = nullptr, //!< [in] File name if file based.
const StreamType _type = append //!< [in] bitsfield enum type identifier
const StreamType _type = APPEND //!< [in] bitsfield enum type identifier
) ;
~DebStream();
......
......@@ -8,7 +8,7 @@
// non-disclosure agreement, expressly prescribing the scope
// and manner of such use.
#include "DebOut.hh"
#include "DebUtils.hh"
#include <string>
#include <fstream>
#include <time.h>
......@@ -109,7 +109,6 @@ public:
_str.append("[");
if (_with_counts)
{
int num = number_calls();
int prev = -2;
int seq_cnt = 0;
......@@ -141,7 +140,7 @@ public:
_str.append("]");
} // endfunc get
void indent(std::string& _str, DebFile* _dfile, bool _is_html);
void get_indent(std::string& _str, DebFile* _dfile, bool _is_html);
}; // endclass FunctionCallSequence
......@@ -206,7 +205,7 @@ public:
return depth_;
}
bool indent(std::string& _str, DebFile* _dfile, const bool is_html);
bool get_indent(std::string& _str, DebFile* _dfile, const bool is_html);
}; // endclass CallStack
......@@ -239,6 +238,8 @@ private:
std::string output_;
std::string file_name_;
std::fstream file_stream_;
std::string double_format_;
//std::string indent_string_;
DebStream* deb_stream_;
CallStack call_stack_;
......@@ -252,19 +253,19 @@ public:
bool is_kept_open() const
{
return 0 != (type_ & DebStream::StreamType::keep_open);
return 0 != (type_ & DebStream::StreamType::KEEP_OPEN);
}
bool is_html() const
{
return 0 != (type_ & DebStream::StreamType::html);
return 0 != (type_ & DebStream::StreamType::HTML);
}
bool is_retained() const
{
return 0 != (type_ & DebStream::StreamType::retain);
return 0 != (type_ & DebStream::StreamType::RETAIN);
}
bool is_appended() const
{
return 0 != (type_ & DebStream::StreamType::append);
return 0 != (type_ & DebStream::StreamType::APPEND);
}
// Only applies to HTML DEB_out
bool is_white_on_black() const
......@@ -319,7 +320,7 @@ public:
void indent(bool _full_text)
{
std::string str;
if (call_stack().indent(str, this, _full_text && is_html()))
if (call_stack().get_indent(str, this, _full_text && is_html()))
current_.append(str);
}
......@@ -410,10 +411,29 @@ public:
print(buffer);
}
const char * double_format() const
{
if (double_format_.empty())
{
return "%.17g";
}
return double_format_.c_str();
}
void set_double_format(const char * const str)
{
if (str==nullptr)
double_format_.clear();
else
double_format_ = str;
}
void print(double _d)
{
char buffer[64];
sprintf_s(buffer, sizeof(buffer), "%.17g", _d);
sprintf_s(buffer, sizeof(buffer), double_format(), _d);
print(buffer);
}
......@@ -421,10 +441,14 @@ public:
{
switch (_co.com())
{
case DebCommand::end :
case DebCommand::END :
if (is_html()) print_direct("</FONT>");
break;
case DebCommand::end_lf :
case DebCommand::END_ERR :
// Powerdown DEB_error font
// if (is_html()) print_direct("</BLINK>");
// fall through
case DebCommand::END_LF :
if (is_html()) print_direct("</FONT>");
line_break();
break;
......@@ -632,18 +656,22 @@ public:
{
file_name_ = _name;
if (is_html_filename(_name))
type_ = (DebStream::StreamType)(type_ | DebStream::StreamType::html);
type_ = (DebStream::StreamType)(type_ | DebStream::StreamType::HTML);
}
void set_module_level(const char* const _module, const int _lev)
{
std::pair<module_map_itr, bool> ins = module_map_.insert(
std::pair<std::string, module_stats>(_module, module_stats(_lev)));
if (!ins.second) ins.first->second.lev_ = _lev;
if (this)
{
std::pair<module_map_itr, bool> ins = module_map_.insert(
std::pair<std::string, module_stats>(_module, module_stats(_lev)));
if (!ins.second) ins.first->second.lev_ = _lev;
}
}
int get_module_level(const char* const _module) const
int module_level(const char* const _module) const
{
if (!this) return -1;
const_module_map_itr it = module_map_.find(std::string(_module));
if (it == module_map_.end()) return lev_;
return it->second.lev_;
......@@ -651,9 +679,13 @@ public:
void set_module_color(const char* const _module, const int _col)
{
std::pair<module_map_itr, bool> ins = module_map_.insert(
std::pair<std::string, module_stats>(_module, module_stats(lev_)));
ins.first->second.col_ = _col;
if (this)
{
std::pair<module_map_itr, bool> ins = module_map_.insert(
std::pair<std::string, module_stats>(_module, module_stats(lev_)));
ins.first->second.col_ = _col;
}
}
int get_module_color(const char* const _module) const
......@@ -670,7 +702,7 @@ public:
int permission(const int _lev, const int _warn, const char* const _module)
{
_warn;
int lev = get_module_level(_module);
int lev = module_level(_module);
lev -= _lev;
if (lev < 0) lev = 0;
if (lev > 0) priority_ = lev;
......@@ -685,7 +717,7 @@ public:
DebFile(
DebStream* _deb_stream,
DebStream::StreamType _type = (DebStream::StreamType)(DebStream::append | DebStream::retain),
DebStream::StreamType _type = (DebStream::StreamType)(DebStream::APPEND | DebStream::RETAIN),
const char* _file_name = nullptr) :
type_(_type), lev_(5), deb_stream_(_deb_stream), num_flush_(0)
{
......@@ -745,7 +777,11 @@ DebStream& DebEnter::stream(const int _warn, const bool _print)
{
if (impl->is_html())
{
bool is_deb_error = (_warn==2);
// DEB_error font powerup goes here. BLINK is deprecated sadly.
// if (is_deb_error) impl->print_direct("<BLINK>");
int col = impl->get_module_color(module_);
if (is_deb_error) col = 0xFF0000; // RED
char buffer[256];
sprintf_s(buffer, sizeof(buffer), "<FONT COLOR=\"#%06X\" SIZE=%i>",
col, impl->priority() + 1);
......@@ -788,7 +824,7 @@ int DebEnter::permission(const int _lev, const int _warn)
}
void FunctionCallSequence::indent(std::string& _str, DebFile* _dfile, bool _is_html)
void FunctionCallSequence::get_indent(std::string& _str, DebFile* _dfile, bool _is_html)
{
int num = number_calls();
for (int i = 0; i < num; ++i)
......@@ -835,7 +871,7 @@ void FunctionCallSequence::indent(std::string& _str, DebFile* _dfile, bool _is_h
}
}
bool CallStack::indent(std::string& _str, DebFile* _dfile, const bool is_html)
bool CallStack::get_indent(std::string& _str, DebFile* _dfile, const bool is_html)
{
if (_dfile->indent_size() == 0) return false;
......@@ -849,7 +885,7 @@ bool CallStack::indent(std::string& _str, DebFile* _dfile, const bool is_html)
int i0 = 0;
if (!is_html) ++i0; // Don't waste whitespace on first level indent if .txt
for (int i = i0; i < num; ++i)
calls_[i].indent(_str, _dfile, is_html);
calls_[i].get_indent(_str, _dfile, is_html);
if (is_html) _str.append(":&nbsp;</FONT>\n");
return true;
}
......@@ -912,48 +948,76 @@ DebStream& DebStream::get_global(int _warn)
{
_warn;
// TODO: Replace with a Singleton?? ThreadArray??
#if 1
static DebStream g_ds__("reform_deb_out.txt");
//static DebStream g_ds__("reform_deb_out.htm");
#else
static DebStream g_ds__("reform_deb_out.htm");
#endif
return g_ds__;
}
DebStream& operator<<(DebStream& ds, const int i)
DebStream& operator<<(DebStream& _ds, const int _i)
{
return _ds.print(_i);
}
DebStream& operator<<(DebStream& _ds, const double _d)
{
return _ds.print(_d);
}
DebStream& operator<<(DebStream& _ds, const char* const _s)
{
return _ds.print(_s);
}
DebStream& operator<<(DebStream& _ds, const char _c)
{
return _ds.print(_c);
}
DebStream& operator<<(DebStream& _ds, const size_t _i)
{
return ds.print(i);
return _ds.print((int)_i);
}
DebStream& operator<<(DebStream& ds, const double d)
DebStream& operator<<(DebStream& _ds, const unsigned int _i)
{
return ds.print(d);
return _ds.print((int)_i);
}
DebStream& operator<<(DebStream& ds, const char* const s)
DebStream& operator<<(DebStream& _ds, const float _f)
{
return ds.print(s);
return _ds.print((double)_f);
}
DebStream& operator<<(DebStream& ds, const char c)
DebStream& operator<<(DebStream& _ds, const std::string& _s)
{
return ds.print(c);
return _ds.print(_s.c_str());
}
DebStream& operator<<(DebStream& ds, const size_t i)
DebStream& operator<<(DebStream& _ds, const DebCommand& _co)
{
return ds.print((int)i);
return _ds.print(_co);
}
DebStream& operator<<(DebStream& ds, const unsigned int i)
// ==================================================
// DebController member funcs (currently all static)
// ==================================================
void DebController::set_module_level(const char * _mod , const int _lev)
{
return ds.print((int)i);
DebStream::get_global().dfile()->set_module_level(_mod, _lev);
}
DebStream& operator<<(DebStream& ds, const float f)
void DebController::set_double_format(const char * _fmt)
{
return ds.print((double)f);
DebStream::get_global().dfile()->set_double_format(_fmt);
}
DebStream& operator<<(DebStream& ds, const std::string& s)
int DebController::module_level(const char * _mod)
{
return ds.print(s.c_str());
return DebStream::get_global().dfile()->module_level(_mod);
}
DebStream& operator<<(DebStream& ds, const DebCommand& co)
std::string DebController::double_format()
{
return ds.print(co);
return DebStream::get_global().dfile()->double_format();
}
......
......@@ -13,10 +13,33 @@
#include <Base/Debug/DebOut.hh>
namespace ReForm {
/*! A currently empty control interface class onto the DebFile class(es)
exploited by DebStream. */
class DebController
{
public:
static void set_module_level(const char * _mod, const int _lev);
static int module_level(const char * _mod);
//! Set printf style format string used for double (and float) numeric print
static void set_double_format(const char * _fmt);
static std::string double_format();
DebController() {}
~DebController() {}
};
} // endnamespace
#ifdef DEB_ON
#define DEB_set_module_level(MM, LL) { DebStream::get_global().set_module_level(MM, LL);}
#define DEB_set_module_level(MM, LL) { DebController::set_module_level(MM, LL); }
#define DEB_set_double_format(FF) { DebController::set_double_format(FF); }
#else
#define DEB_set_module_level(MM, LL) {}
#define DEB_set_double_format(FF) {}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment