summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2012-08-24 20:29:40 +0200
committerAndreas Baumann <abaumann@yahoo.com>2012-08-24 20:29:40 +0200
commitaca47165598d479b6bb189e8c7ca05c279f32282 (patch)
tree35764ba55ea425238d81a1eabf9cc526b5303075 /src
parent4459270337fbe742b958c636f81d6babea4f7b35 (diff)
downloadcrawler-aca47165598d479b6bb189e8c7ca05c279f32282.tar.gz
crawler-aca47165598d479b6bb189e8c7ca05c279f32282.tar.bz2
sorted out visibility issues around Logger/Singleton/scoped_ptr
added more logging tests
Diffstat (limited to 'src')
-rwxr-xr-xsrc/Logger.hpp10
-rw-r--r--src/ScopedPtr.hpp2
-rwxr-xr-xsrc/Singleton.hpp11
3 files changed, 17 insertions, 6 deletions
diff --git a/src/Logger.hpp b/src/Logger.hpp
index 341283a..5b2578f 100755
--- a/src/Logger.hpp
+++ b/src/Logger.hpp
@@ -47,24 +47,28 @@ class LogSink;
class Logger : public Singleton< Logger >
{
public:
+ DECLARE_SINGLETON( Logger )
+
void addSink( LogSink *sink );
void removeSink( LogSink *sink );
void log( const LogLevel level, const std::string &msg );
- ~Logger( );
-
static std::string toString( const LogLevel level );
static LogLevel fromString( const std::string &s );
void openConsoleLog( const LogLevel level );
void openFileLog( const LogLevel level, const std::string &filename );
+ protected:
+ Logger( ) { }
+ virtual ~Logger( );
+
private:
typedef std::list< LogSink * > SinkList;
SinkList m_sinks;
};
-SINGLETON_EXTERN template class SINGLETON_EXPORT Singleton< Logger >;
+DEFINE_SINGLETON( Logger )
#define LOG( level ) LogStream( Logger::instance( ), level ).get( )
diff --git a/src/ScopedPtr.hpp b/src/ScopedPtr.hpp
index 8357e85..19a41d2 100644
--- a/src/ScopedPtr.hpp
+++ b/src/ScopedPtr.hpp
@@ -4,7 +4,7 @@
#include "NonCopyable.hpp"
template< typename T >
-class scopedPtr : noncopyable
+class scopedPtr : private noncopyable
{
public:
explicit scopedPtr( T *p = 0 ) : m_p( p ) { }
diff --git a/src/Singleton.hpp b/src/Singleton.hpp
index 2bdf257..4b7e2b4 100755
--- a/src/Singleton.hpp
+++ b/src/Singleton.hpp
@@ -7,6 +7,13 @@
#include <cstdlib>
#include <stdexcept>
+#define DECLARE_SINGLETON( T ) \
+ friend class scopedPtr< T >; \
+ friend class Singleton< T >;
+
+#define DEFINE_SINGLETON( T ) \
+ SINGLETON_EXTERN template class SINGLETON_EXPORT Singleton< T >;
+
template< class T >
class Singleton : private noncopyable
{
@@ -29,7 +36,7 @@ class Singleton : private noncopyable
{
}
- ~Singleton( )
+ virtual ~Singleton( )
{
destroyed = true;
}
@@ -44,7 +51,7 @@ class Singleton : private noncopyable
{
throw std::runtime_error( "singleton has already been destroyed!" );
}
-
+
static scopedPtr<T> t;
static bool destroyed;
};