diff --git a/ejson/Value.cpp b/ejson/Value.cpp index e51447a..e02ea98 100644 --- a/ejson/Value.cpp +++ b/ejson/Value.cpp @@ -19,7 +19,7 @@ ejson::Value::~Value(void) { clear(); } -etk::CCout& ejson::operator <<(etk::CCout& _os, const ejson::filePos& _obj) { +std::ostream& ejson::operator <<(std::ostream& _os, const ejson::filePos& _obj) { _os << "(l="; _os << _obj.getLine(); _os << ",c="; diff --git a/ejson/Value.h b/ejson/Value.h index 2f2507d..b9c415d 100755 --- a/ejson/Value.h +++ b/ejson/Value.h @@ -102,7 +102,7 @@ namespace ejson { return m_line; }; }; - etk::CCout& operator <<(etk::CCout& _os, const filePos& _obj); + std::ostream& operator <<(std::ostream& _os, const filePos& _obj); class Value { public: diff --git a/ejson/debug.cpp b/ejson/debug.cpp index 944158f..d90febf 100644 --- a/ejson/debug.cpp +++ b/ejson/debug.cpp @@ -8,4 +8,8 @@ #include -const char * g_ejsonLibName = "ejson "; +int32_t ejson::getLogId(void) { + static int32_t g_val = etk::log::registerInstance("ejson"); + return g_val; +} + diff --git a/ejson/debug.h b/ejson/debug.h index c7de2eb..838d3c1 100644 --- a/ejson/debug.h +++ b/ejson/debug.h @@ -9,19 +9,43 @@ #ifndef __EJSON_DEBUG_H__ #define __EJSON_DEBUG_H__ -#include -#include +#include -extern const char * g_ejsonLibName; +namespace ejson { + int32_t getLogId(void); +}; +// TODO : Review this problem of multiple intanciation of "std::stringbuf sb" +#define JSON_BASE(info,data) \ + do { \ + if (info <= etk::log::getLevel(ejson::getLogId())) { \ + std::stringbuf sb; \ + std::ostream tmpStream(&sb); \ + tmpStream << data; \ + etk::log::logStream(ejson::getLogId(), info, __LINE__, __class__, __func__, tmpStream); \ + } \ + } while(0) -#define JSON_CRITICAL(data) ETK_CRITICAL(g_ejsonLibName, data) -#define JSON_WARNING(data) ETK_WARNING(g_ejsonLibName, data) -#define JSON_ERROR(data) ETK_ERROR(g_ejsonLibName, data) -#define JSON_INFO(data) ETK_INFO(g_ejsonLibName, data) -#define JSON_DEBUG(data) ETK_DEBUG(g_ejsonLibName, data) -#define JSON_VERBOSE(data) ETK_VERBOSE(g_ejsonLibName, data) -#define JSON_ASSERT(cond, data) ETK_ASSERT(g_ejsonLibName, cond, data) -#define JSON_CHECK_INOUT(cond) ETK_CHECK_INOUT(g_ejsonLibName, cond) -#define JSON_TODO(cond) ETK_TODO(g_ejsonLibName, cond) +#define JSON_CRITICAL(data) JSON_BASE(1, data) +#define JSON_ERROR(data) JSON_BASE(2, data) +#define JSON_WARNING(data) JSON_BASE(3, data) +#ifdef DEBUG + #define JSON_INFO(data) JSON_BASE(4, data) + #define JSON_DEBUG(data) JSON_BASE(5, data) + #define JSON_VERBOSE(data) JSON_BASE(6, data) + #define JSON_TODO(data) JSON_BASE(4, "TODO : " << data) +#else + #define JSON_INFO(data) do { } while(false) + #define JSON_DEBUG(data) do { } while(false) + #define JSON_VERBOSE(data) do { } while(false) + #define JSON_TODO(data) do { } while(false) +#endif + +#define JSON_ASSERT(cond,data) \ + do { \ + if (!(cond)) { \ + JSON_CRITICAL(data); \ + assert(!#cond); \ + } \ + } while (0) #endif