summaryrefslogtreecommitdiff
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
parent4459270337fbe742b958c636f81d6babea4f7b35 (diff)
downloadcrawler-aca47165598d479b6bb189e8c7ca05c279f32282.tar.gz
crawler-aca47165598d479b6bb189e8c7ca05c279f32282.tar.bz2
sorted out visibility issues around Logger/Singleton/scoped_ptr
added more logging tests
-rwxr-xr-xdocs/LINKS3
-rwxr-xr-xsrc/Logger.hpp10
-rw-r--r--src/ScopedPtr.hpp2
-rwxr-xr-xsrc/Singleton.hpp11
-rw-r--r--tests/logger/test1.cpp10
5 files changed, 29 insertions, 7 deletions
diff --git a/docs/LINKS b/docs/LINKS
index c27648f..7600d3a 100755
--- a/docs/LINKS
+++ b/docs/LINKS
@@ -84,5 +84,8 @@ DLL and shared globals (for Singleton):
- http://www.ogre3d.org/forums/viewtopic.php?p=75622&sid=ce193664e1d3d7c4af509e6f4e2718c6
- http://www.lurklurk.org/linkers/linkers.html#wincircular
+Singleton design:
+- http://www.oop-trainer.de/Themen/Singleton.html
+
Linking with gcc and visibility:
- http://gcc.gnu.org/wiki/Visibility
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;
};
diff --git a/tests/logger/test1.cpp b/tests/logger/test1.cpp
index 5940d60..eea3ff9 100644
--- a/tests/logger/test1.cpp
+++ b/tests/logger/test1.cpp
@@ -2,11 +2,15 @@
#include "ConsoleLogSink.hpp"
#include "FileLogSink.hpp"
+#include <string>
+
+using namespace std;
+
int main( void )
{
LogSink *sink = new ConsoleLogSink( logNOTICE );
Logger::instance( ).addSink( sink );
- Logger::instance( ).addSink( new FileLogSink( logNOTICE, "test1.log" ) );
+ Logger::instance( ).openFileLog( logNOTICE, "test1.log" );
LOG( logFATAL ) << "fatal error";
LOG( logCRITICAL ) << "critical error";
@@ -48,5 +52,9 @@ int main( void )
LOG( logDEBUG3 ) << "debug level 3";
LOG( logDEBUG4 ) << "debug level 4";
+ sink->setReportingLevel( logINFO );
+ LogLevel level = Logger::fromString( "bla" );
+ LOG( logINFO ) << "the level is " << Logger::toString( level );
+
return 0;
}