Commit cad28c0b authored by Samuel Debionne's avatar Samuel Debionne

Merge branch 'template_deb_proxy' into 'master'

Debug: make DebProxy & DebSink implementations of a single template class

See merge request !107
parents 63d45824 f58c3329
Pipeline #7372 passed with stages
in 10 minutes and 32 seconds
...@@ -132,7 +132,8 @@ inline DebStream& DebStream::SetStream(Selector new_selector) ...@@ -132,7 +132,8 @@ inline DebStream& DebStream::SetStream(Selector new_selector)
*------------------------------------------------------------------*/ *------------------------------------------------------------------*/
class DebObj; class DebObj;
class DebProxy; template <bool active>
class TDebProxy;
class LIMACORE_API DebParams class LIMACORE_API DebParams
{ {
...@@ -195,7 +196,8 @@ class LIMACORE_API DebParams ...@@ -195,7 +196,8 @@ class LIMACORE_API DebParams
static void checkInit(); static void checkInit();
private: private:
friend class DebProxy; template <bool active>
friend class TDebProxy;
friend class DebObj; friend class DebObj;
static void doInit(); static void doInit();
...@@ -231,27 +233,37 @@ std::ostream& operator <<(std::ostream& os, ...@@ -231,27 +233,37 @@ std::ostream& operator <<(std::ostream& os,
/*------------------------------------------------------------------ /*------------------------------------------------------------------
* class DebProxy * class TDebProxy
*------------------------------------------------------------------*/ *------------------------------------------------------------------*/
class LIMACORE_API DebProxy template <bool active>
class LIMACORE_API TDebProxy
{ {
public: public:
DebProxy(); TDebProxy();
DebProxy(DebObj *deb_obj, DebType type, ConstStr funct_name, TDebProxy(DebObj *deb_obj, DebType type, ConstStr funct_name,
ConstStr file_name, int line_nr); ConstStr file_name, int line_nr);
DebProxy(const DebProxy& p); TDebProxy(const TDebProxy& p);
~DebProxy(); ~TDebProxy();
template <class T> template <class T>
const DebProxy& operator <<(const T& o) const; const TDebProxy& operator <<(const T& o) const
{
if (isActive())
*DebParams::s_deb_stream << o;
return *this;
}
bool isActive() const; bool isActive() const
{ return active && !!m_lock; }
private: private:
mutable AutoMutex *m_lock; mutable AutoMutex *m_lock;
}; };
typedef TDebProxy<true> DebProxy;
typedef TDebProxy<false> DebSink;
/*------------------------------------------------------------------ /*------------------------------------------------------------------
* class DebObj * class DebObj
*------------------------------------------------------------------*/ *------------------------------------------------------------------*/
...@@ -278,7 +290,8 @@ class LIMACORE_API DebObj ...@@ -278,7 +290,8 @@ class LIMACORE_API DebObj
ConstStr file_name = NULL, int line_nr = 0); ConstStr file_name = NULL, int line_nr = 0);
private: private:
friend class DebProxy; template <bool active>
friend class TDebProxy;
typedef struct ThreadData { typedef struct ThreadData {
int indent; int indent;
...@@ -388,16 +401,18 @@ inline bool DebParams::checkType(DebType type) const ...@@ -388,16 +401,18 @@ inline bool DebParams::checkType(DebType type) const
} }
/*------------------------------------------------------------------ /*------------------------------------------------------------------
* class DebProxy inline functions * class TDebProxy inline functions
*------------------------------------------------------------------*/ *------------------------------------------------------------------*/
inline DebProxy::DebProxy() template <>
inline TDebProxy<true>::TDebProxy()
: m_lock(NULL) : m_lock(NULL)
{ {
} }
inline DebProxy::DebProxy(DebObj *deb_obj, DebType type, ConstStr funct_name, template <>
ConstStr file_name, int line_nr) inline TDebProxy<true>::TDebProxy(DebObj *deb_obj, DebType type, ConstStr funct_name,
ConstStr file_name, int line_nr)
{ {
#ifdef LIMA_NO_DEBUG #ifdef LIMA_NO_DEBUG
DebParams::checkInit(); DebParams::checkInit();
...@@ -410,13 +425,15 @@ inline DebProxy::DebProxy(DebObj *deb_obj, DebType type, ConstStr funct_name, ...@@ -410,13 +425,15 @@ inline DebProxy::DebProxy(DebObj *deb_obj, DebType type, ConstStr funct_name,
m_lock = new AutoMutex(lock); m_lock = new AutoMutex(lock);
} }
inline DebProxy::DebProxy(const DebProxy& p) template <>
inline TDebProxy<true>::TDebProxy(const TDebProxy& p)
: m_lock(p.m_lock) : m_lock(p.m_lock)
{ {
p.m_lock = NULL; p.m_lock = NULL;
} }
inline DebProxy::~DebProxy() template <>
inline TDebProxy<true>::~TDebProxy()
{ {
if (!m_lock) if (!m_lock)
return; return;
...@@ -425,19 +442,13 @@ inline DebProxy::~DebProxy() ...@@ -425,19 +442,13 @@ inline DebProxy::~DebProxy()
delete m_lock; delete m_lock;
} }
inline bool DebProxy::isActive() const template <>
{ inline TDebProxy<false>::TDebProxy()
return !!m_lock; {}
}
template <class T>
inline const DebProxy& DebProxy::operator <<(const T& o) const
{
if (isActive())
*DebParams::s_deb_stream << o;
return *this;
}
template <>
inline TDebProxy<false>::~TDebProxy()
{}
/*------------------------------------------------------------------ /*------------------------------------------------------------------
* class DebObj inline functions * class DebObj inline functions
...@@ -590,16 +601,6 @@ inline DebProxy DebObj::write(DebType type, ConstStr file_name, int line_nr) ...@@ -590,16 +601,6 @@ inline DebProxy DebObj::write(DebType type, ConstStr file_name, int line_nr)
#else // LIMA_NO_DEBUG #else // LIMA_NO_DEBUG
// Mock implementation of the DebProxy
class LIMACORE_API DebSink
{
public:
DebSink() {};
template <class T>
const DebSink& operator <<(const T&) const {return *this;}
};
#define DEB_GLOBAL_FUNCT() #define DEB_GLOBAL_FUNCT()
#define DEB_CONSTRUCTOR() #define DEB_CONSTRUCTOR()
#define DEB_DESTRUCTOR() #define DEB_DESTRUCTOR()
......
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