Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2008-01-19 10:48:51


Author: jtorjo
Date: 2008-01-19 10:48:51 EST (Sat, 19 Jan 2008)
New Revision: 42867
URL: http://svn.boost.org/trac/boost/changeset/42867

Log:
[logging]
v0.20.8, 19 jan 2008
- refactored logger_holder - that is, we need to return logger_holder,
  but keep logger_holder_by_value, for after_destroyed to work
Text files modified:
   sandbox/logging/boost/logging/detail/log_keeper.hpp | 89 +++++++++++++++++++++++++++++++++------
   sandbox/logging/boost/logging/detail/macros.hpp | 18 ++++----
   sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp | 4 +
   3 files changed, 86 insertions(+), 25 deletions(-)

Modified: sandbox/logging/boost/logging/detail/log_keeper.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/log_keeper.hpp (original)
+++ sandbox/logging/boost/logging/detail/log_keeper.hpp 2008-01-19 10:48:51 EST (Sat, 19 Jan 2008)
@@ -38,37 +38,96 @@
     @brief Allows using a log without knowing its full type yet. Even if the log is not fully @b defined, you can still use it.
 
     This will allow you to log messages even if you don't know the full type of the log (which can aid compilation time).
+
+ This is a base class. Use logger_holder_by_value or logger_holder_by_ptr instead
 */
-template<class type, class gather_msg = default_, class dummy = override> struct log_holder {
+template<class type, class gather_msg = default_, class dummy = override> struct logger_holder {
     typedef typename use_default<gather_msg, typename ::boost::logging::detail::fast_compile_with_default_gather<dummy>::gather_msg > ::type gather_type;
     typedef logger<gather_type> logger_base_type;
 
- BOOST_LOGGING_FORWARD_CONSTRUCTOR_INIT(log_holder, m_log, init)
-
- const type* operator->() const { return &m_log; }
- type* operator->() { return &m_log; }
+ const type* operator->() const { return m_log; }
+ type* operator->() { return m_log; }
 
     /**
         in case you want to get the real log object
     */
- const type* get() const { return &m_log; }
- type* get() { return &m_log; }
+ const type* get() const { return m_log; }
+ type* get() { return m_log; }
 
 
     const logger_base_type * base() const { return m_base; }
     logger_base_type * base() { return m_base; }
 
-private:
- void init() {
- m_base = 0;
+protected:
+ logger_holder() : m_log(0), m_base(0) {}
+ virtual ~logger_holder() {}
+
+ void init(type * log) {
+ m_log = log;
         typedef typename type::write_type write_type;
- m_base = m_log.common_base();
+ m_base = m_log->common_base();
     }
 private:
- type m_log;
+ // note: I have a pointer to the log, as opposed to having it by value, because the whole purpose of this class
+ // is to be able to use a log without knowing its full type
+ type *m_log;
     logger_base_type * m_base;
 };
 
+
+
+/**
+ @brief Allows using a log without knowing its full type yet. Even if the log is not fully @b defined, you can still use it.
+
+ This will allow you to log messages even if you don't know the full type of the log (which can aid compilation time).
+
+ This keeps the logger by value, so that the after_being_destroyed stuff works.
+ More specifically, in case the logger is used after it's been destroyed, the logger_holder instances CAN ONLY BE GLOBAL.
+*/
+template<class type, class gather_msg = default_> struct logger_holder_by_value : logger_holder<type, gather_msg> {
+ typedef logger_holder<type, gather_msg> base_type;
+
+ BOOST_LOGGING_FORWARD_CONSTRUCTOR_INIT(logger_holder_by_value, m_log, init)
+private:
+ void init() {
+ base_type::init( &m_log_value);
+ }
+private:
+ // VERY IMPORTANT: we keep this BY VALUE, because, at destruction, we don't want the memory to be freed
+ // (in order for the after_being_destroyed to work, for global instances of this type)
+ type m_log_value;
+};
+
+
+/**
+ @brief Allows using a log without knowing its full type yet. Even if the log is not fully @b defined, you can still use it.
+
+ This will allow you to log messages even if you don't know the full type of the log (which can aid compilation time).
+
+ This keeps the logger by value, so that the after_being_destroyed stuff works.
+ More specifically, in case the logger is used after it's been destroyed, the logger_holder instances CAN ONLY BE GLOBAL.
+*/
+template<class type, class gather_msg = default_> struct logger_holder_by_ptr : logger_holder<type, gather_msg> {
+ typedef logger_holder<type, gather_msg> base_type;
+
+ BOOST_LOGGING_FORWARD_CONSTRUCTOR_WITH_NEW_AND_INIT(logger_holder_by_ptr, m_log_ptr, type, init)
+ ~logger_holder_by_ptr() {
+ delete m_log_ptr;
+ }
+private:
+ void init() {
+ base_type::init( m_log_ptr);
+ }
+private:
+ type *m_log_ptr;
+};
+
+
+
+
+
+
+
 /**
     @brief Ensures the log is created before main(), even if not used before main
 
@@ -104,17 +163,17 @@
 typedef ensure_early_log_creation ensure_early_filter_creation;
 
 /**
- Useful for log_holder - to get the logger' base (so that we can use it even without knowing the full log's definition).
+ Useful for logger_holder - to get the logger' base (so that we can use it even without knowing the full log's definition).
 
     If used on a logger, it just returns it .
 */
 template<class logger> inline logger* get_logger_base(logger * l) { return l; }
 template<class logger> inline const logger* get_logger_base(const logger * l) { return l; }
 
-template<class type, class gather_msg> inline typename log_holder<type,gather_msg>::logger_base_type* get_logger_base(log_holder<type,gather_msg> & l) {
+template<class type, class gather_msg> inline typename logger_holder<type,gather_msg>::logger_base_type* get_logger_base(logger_holder<type,gather_msg> & l) {
     return l.base();
 }
-template<class type, class gather_msg> inline const typename log_holder<type,gather_msg>::logger_base_type* get_logger_base(const log_holder<type,gather_msg> & l) {
+template<class type, class gather_msg> inline const typename logger_holder<type,gather_msg>::logger_base_type* get_logger_base(const logger_holder<type,gather_msg> & l) {
     return l.base();
 }
 

Modified: sandbox/logging/boost/logging/detail/macros.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/macros.hpp (original)
+++ sandbox/logging/boost/logging/detail/macros.hpp 2008-01-19 10:48:51 EST (Sat, 19 Jan 2008)
@@ -530,27 +530,27 @@
 
 #ifdef BOOST_LOG_COMPILE_FAST
 // ****** Fast compile ******
-#define BOOST_DECLARE_LOG(name,type) ::boost::logging::log_holder< type > & name ();
+#define BOOST_DECLARE_LOG(name,type) ::boost::logging::logger_holder< type > & name ();
 
 #ifdef BOOST_LOG_AFTER_BEING_DESTROYED_LEAK_LOGGER
     // leak the loggers
- #define BOOST_DEFINE_LOG(name,type) ::boost::logging::log_holder< type > & name () \
- { static ::boost::logging::log_holder< type > *l = new ::boost::logging::log_holder< type > ; return *l; } \
+ #define BOOST_DEFINE_LOG(name,type) ::boost::logging::logger_holder< type > & name () \
+ { static ::boost::logging::logger_holder_by_value< type > *l = new ::boost::logging::logger_holder< type > ; return *l; } \
         namespace { boost::logging::ensure_early_log_creation ensure_log_is_created_before_main ## name ( name () ); }
 
- #define BOOST_DEFINE_LOG_WITH_ARGS(name,type, args) ::boost::logging::log_holder< type > & name () \
- { static ::boost::logging::log_holder< type > *l = new ::boost::logging::log_holder< type > ( args ); return *l; } \
+ #define BOOST_DEFINE_LOG_WITH_ARGS(name,type, args) ::boost::logging::logger_holder< type > & name () \
+ { static ::boost::logging::logger_holder_by_value< type > *l = new ::boost::logging::logger_holder< type > ( args ); return *l; } \
         namespace { boost::logging::ensure_early_log_creation ensure_log_is_created_before_main ## name ( name () ); }
 
 #else
 
     // don't leak
- #define BOOST_DEFINE_LOG(name,type) ::boost::logging::log_holder< type > & name () \
- { static ::boost::logging::log_holder< type > l; return l; } \
+ #define BOOST_DEFINE_LOG(name,type) ::boost::logging::logger_holder< type > & name () \
+ { static ::boost::logging::logger_holder_by_value< type > l; return l; } \
         namespace { boost::logging::ensure_early_log_creation ensure_log_is_created_before_main ## name ( name () ); }
 
- #define BOOST_DEFINE_LOG_WITH_ARGS(name,type, args) ::boost::logging::log_holder< type > & name () \
- { static ::boost::logging::log_holder< type > l ( args ); return l; } \
+ #define BOOST_DEFINE_LOG_WITH_ARGS(name,type, args) ::boost::logging::logger_holder< type > & name () \
+ { static ::boost::logging::logger_holder_by_value< type > l ( args ); return l; } \
         namespace { boost::logging::ensure_early_log_creation ensure_log_is_created_before_main ## name ( name () ); }
 #endif
 

Modified: sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp 2008-01-19 10:48:51 EST (Sat, 19 Jan 2008)
@@ -1,7 +1,9 @@
 /**
 @page page_changelog Changelog
 
-_at_section changelog_cur_ver Current Version: v0.20.7, 18 jan 2008
+@section changelog_cur_ver Current Version: v0.20.8, 19 jan 2008
+- refactored logger_holder - that is, we need to return logger_holder,
+ but keep logger_holder_by_value, for after_destroyed to work
 - added test for using logger after it's been destroyed
 - handle using logger after it's been destroyed
 - simpler version of logger (derive from logger_base)


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk