From f5c586f7231f7e033c5528bcefea357e4e64441c Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 6 Sep 2012 10:25:57 +0200 Subject: first properly working logger on Windows (singleton dll issue) --- include/logger/ConsoleLogSink.hpp | 2 +- include/logger/FileLogSink.hpp | 2 +- include/logger/LogSink.hpp | 2 +- include/logger/Logger.hpp | 28 ++++++++++++++-------------- include/logger/SyslogLogSink.hpp | 2 +- include/logger/WinDbgLogSink.hpp | 2 +- include/util/Exportable.hpp | 23 ++++++++++++----------- include/util/NonCopyable.hpp | 2 +- include/util/ScopedPtr.hpp | 2 +- include/util/Singleton.hpp | 14 ++++++++++---- 10 files changed, 43 insertions(+), 36 deletions(-) (limited to 'include') diff --git a/include/logger/ConsoleLogSink.hpp b/include/logger/ConsoleLogSink.hpp index 0605fb8..4380df8 100755 --- a/include/logger/ConsoleLogSink.hpp +++ b/include/logger/ConsoleLogSink.hpp @@ -8,7 +8,7 @@ class ConsoleLogSink : public LogSink public: ConsoleLogSink( const LogLevel level ) : LogSink( level ) { } - DLL_EXPORT virtual void log( const LogLevel level, const std::string &msg ); + DLL_VISIBLE virtual void log( const LogLevel level, const std::string &msg ); }; #endif diff --git a/include/logger/FileLogSink.hpp b/include/logger/FileLogSink.hpp index d8b1381..0acb6b9 100755 --- a/include/logger/FileLogSink.hpp +++ b/include/logger/FileLogSink.hpp @@ -13,7 +13,7 @@ class FileLogSink : public LogSink ~FileLogSink( ); - DLL_EXPORT virtual void log( const LogLevel level, const std::string &msg ); + DLL_VISIBLE virtual void log( const LogLevel level, const std::string &msg ); private: std::string m_filename; diff --git a/include/logger/LogSink.hpp b/include/logger/LogSink.hpp index 0cde9d4..4d07df0 100755 --- a/include/logger/LogSink.hpp +++ b/include/logger/LogSink.hpp @@ -11,7 +11,7 @@ class LogSink virtual ~LogSink( ) { } - DLL_EXPORT virtual void log( const LogLevel level, const std::string &msg ) = 0; + DLL_VISIBLE virtual void log( const LogLevel level, const std::string &msg ) = 0; void setReportingLevel( const LogLevel level ) { m_level = level; } diff --git a/include/logger/Logger.hpp b/include/logger/Logger.hpp index 9a84f55..f0c0012 100755 --- a/include/logger/Logger.hpp +++ b/include/logger/Logger.hpp @@ -30,21 +30,21 @@ class Logger : public Singleton< Logger > public: DECLARE_SINGLETON( Logger ) - DLL_EXPORT void addSink( LogSink *sink ); - DLL_EXPORT void removeSink( LogSink *sink ); - DLL_EXPORT void log( const LogLevel level, const std::string &msg ); + DLL_VISIBLE void addSink( LogSink *sink ); + DLL_VISIBLE void removeSink( LogSink *sink ); + DLL_VISIBLE void log( const LogLevel level, const std::string &msg ); - DLL_EXPORT static std::string toString( const LogLevel level ); - DLL_EXPORT static LogLevel fromString( const std::string &s ); + DLL_VISIBLE static std::string toString( const LogLevel level ); + DLL_VISIBLE static LogLevel fromString( const std::string &s ); - DLL_EXPORT void openConsoleLog( const LogLevel level ); - DLL_EXPORT void openFileLog( const LogLevel level, const std::string &filename ); - DLL_EXPORT void openSyslog( const LogLevel level, const std::string &ident, const std::string &facility ); - DLL_EXPORT void openWinDbgLog( const LogLevel level ); + DLL_VISIBLE void openConsoleLog( const LogLevel level ); + DLL_VISIBLE void openFileLog( const LogLevel level, const std::string &filename ); + DLL_VISIBLE void openSyslog( const LogLevel level, const std::string &ident, const std::string &facility ); + DLL_VISIBLE void openWinDbgLog( const LogLevel level ); protected: - DLL_EXPORT Logger( ); - DLL_EXPORT virtual ~Logger( ); + DLL_VISIBLE Logger( ); + DLL_VISIBLE virtual ~Logger( ); private: scopedPtr< LoggerImpl > m_impl; @@ -55,9 +55,9 @@ DEFINE_SINGLETON( Logger ) class LogStream : private noncopyable, public std::ostringstream { public: - DLL_EXPORT LogStream( Logger &logger, const LogLevel level ); - DLL_EXPORT ~LogStream( ); - DLL_EXPORT std::ostream &get( ); + DLL_VISIBLE LogStream( Logger &logger, const LogLevel level ); + DLL_VISIBLE ~LogStream( ); + DLL_VISIBLE std::ostream &get( ); private: LogStream( ); diff --git a/include/logger/SyslogLogSink.hpp b/include/logger/SyslogLogSink.hpp index af0e7ee..f5824a6 100755 --- a/include/logger/SyslogLogSink.hpp +++ b/include/logger/SyslogLogSink.hpp @@ -12,7 +12,7 @@ class SyslogLogSink : public LogSink ~SyslogLogSink( ); - DLL_EXPORT virtual void log( const LogLevel level, const std::string &msg ); + DLL_VISIBLE virtual void log( const LogLevel level, const std::string &msg ); static int levelToSyslogLevel( const LogLevel level ); static int facilityFromString( const std::string &facility ); diff --git a/include/logger/WinDbgLogSink.hpp b/include/logger/WinDbgLogSink.hpp index 67e13e7..d073cdc 100755 --- a/include/logger/WinDbgLogSink.hpp +++ b/include/logger/WinDbgLogSink.hpp @@ -8,7 +8,7 @@ class WinDbgLogSink : public LogSink public: WinDbgLogSink( const LogLevel level ) : LogSink( level ) { } - DLL_EXPORT virtual void log( const LogLevel level, const std::string &msg ); + DLL_VISIBLE virtual void log( const LogLevel level, const std::string &msg ); }; #endif diff --git a/include/util/Exportable.hpp b/include/util/Exportable.hpp index a676ae3..fc8269f 100755 --- a/include/util/Exportable.hpp +++ b/include/util/Exportable.hpp @@ -3,21 +3,22 @@ #ifndef _WIN32 -#define SINGLETON_EXPORT -#define SINGLETON_EXTERN - -#define DLL_EXPORT +#define DLL_VISIBLE +#define DLL_EXTERN #else -#define DLL_EXPORT __declspec(dllexport) - -#ifndef SHARED -#define SINGLETON_EXPORT __declspec(dllexport) -#define SINGLETON_EXTERN +#ifdef NODLL +#define DLL_VISIBLE +#define DLL_EXTERN #else -#define SINGLETON_EXPORT __declspec(dllimport) -#define SINGLETON_EXTERN extern +#ifdef SHARED +#define DLL_VISIBLE __declspec(dllexport) +#define DLL_EXTERN +#else +#define DLL_VISIBLE __declspec(dllimport) +#define DLL_EXTERN +#endif #endif #endif // _WIN32 diff --git a/include/util/NonCopyable.hpp b/include/util/NonCopyable.hpp index 44d1a93..99804d2 100755 --- a/include/util/NonCopyable.hpp +++ b/include/util/NonCopyable.hpp @@ -6,7 +6,7 @@ namespace __dont_touch { -class SINGLETON_EXPORT noncopyable +class DLL_VISIBLE noncopyable { protected: noncopyable( ) { } diff --git a/include/util/ScopedPtr.hpp b/include/util/ScopedPtr.hpp index 19a41d2..991409d 100755 --- a/include/util/ScopedPtr.hpp +++ b/include/util/ScopedPtr.hpp @@ -4,7 +4,7 @@ #include "NonCopyable.hpp" template< typename T > -class scopedPtr : private noncopyable +class DLL_VISIBLE scopedPtr : private noncopyable { public: explicit scopedPtr( T *p = 0 ) : m_p( p ) { } diff --git a/include/util/Singleton.hpp b/include/util/Singleton.hpp index 1bfb460..f291435 100755 --- a/include/util/Singleton.hpp +++ b/include/util/Singleton.hpp @@ -10,17 +10,23 @@ #include #define DECLARE_SINGLETON( T ) \ - friend class scopedPtr< T >; \ - friend class Singleton< T >; + friend class Singleton< T >; \ + friend class scopedPtr< T >; + +#define DEFINE_SINGLETON( T ) + +#if 0 +#define DECLARE_SINGLETON( T ) \ #define DEFINE_SINGLETON( T ) \ - SINGLETON_EXTERN template class SINGLETON_EXPORT Singleton< T >; + DLL_EXTERN template class DLL_VISIBLE Singleton< T >; +#endif template< class T > class Singleton : private noncopyable { public: - static T& instance( ) + DLL_VISIBLE static T& instance( ) { if( destroyed ) { onDeadReference( ); -- cgit v1.2.3-54-g00ecf