Author: tschoening
Date: Sun Feb 16 19:18:20 2014
New Revision: 1568810

URL: http://svn.apache.org/r1568810
Log:
LOGCXX-394: With removing static in Level::get* some of the tests failed 
because they relied on the fact that LevelPtr overrides operator== by comparing 
pointers and because of the static levels those pointers where always the same 
for every level. I changed this by LevelPtr overriding operator== on it's own 
and comparing the level values instead of it's pointers. The seems to make more 
sense for Levels anyways, especially because Level::equals already behaved that 
way and ignored the pointer of LevelPtr, but compared it's level value instead.

I'll focus on == and != for now and not override each method of ObjectPtr 
because those 2 are only used in Level.

We don't have many options anyways, either we revert to using sttaic levels and 
introduce the bug again or we need to adopt already written code to compare 
using a cast or such.

Modified:
    incubator/log4cxx/trunk/src/main/include/log4cxx/level.h

Modified: incubator/log4cxx/trunk/src/main/include/log4cxx/level.h
URL: 
http://svn.apache.org/viewvc/incubator/log4cxx/trunk/src/main/include/log4cxx/level.h?rev=1568810&r1=1568809&r2=1568810&view=diff
==============================================================================
--- incubator/log4cxx/trunk/src/main/include/log4cxx/level.h (original)
+++ incubator/log4cxx/trunk/src/main/include/log4cxx/level.h Sun Feb 16 
19:18:20 2014
@@ -27,9 +27,16 @@
 
 namespace log4cxx
 {
-    class Level;
-    /** smart pointer to a Level instance */
-    LOG4CXX_PTR_DEF(Level);
+       /**
+        * LOG4CXX_PTR_DEF can't be used to get a smart pointer for Level 
because we need to override
+        * the comparison operator and this doesn't work if the template has 
alread been initialized,
+        * which is what the macro does on some platforms. The overriding takes 
place underneath the
+        * definition of Level because we need one of it's methods.
+        *
+        * https://issues.apache.org/jira/browse/LOGCXX-394
+        */
+       class Level;
+       typedef log4cxx::helpers::ObjectPtrT<Level> LevelPtr;
 
         /**
         Defines the minimum set of levels recognized by the system, that is
@@ -82,7 +89,7 @@ namespace log4cxx
                 <code>defaultLevel</code>.
                 * @param sArg level name.
                 * @param defaultLevel level to return if no match.
-                * @return 
+                * @return
                 */
                 static LevelPtr toLevel(const std::string& sArg,
                         const LevelPtr& defaultLevel);
@@ -105,7 +112,7 @@ namespace log4cxx
                 <code>defaultLevel</code>.
                 * @param sArg level name.
                 * @param defaultLevel level to return if no match.
-                * @return 
+                * @return
                 */
                 static LevelPtr toLevel(const std::wstring& sArg,
                         const LevelPtr& defaultLevel);
@@ -128,7 +135,7 @@ namespace log4cxx
                 <code>defaultLevel</code>.
                 * @param sArg level name.
                 * @param defaultLevel level to return if no match.
-                * @return 
+                * @return
                 */
                 static LevelPtr toLevel(const std::basic_string<UniChar>& sArg,
                         const LevelPtr& defaultLevel);
@@ -151,7 +158,7 @@ namespace log4cxx
                 <code>defaultLevel</code>.
                 * @param sArg level name.
                 * @param defaultLevel level to return if no match.
-                * @return 
+                * @return
                 */
                 static LevelPtr toLevel(const CFStringRef& sArg,
                         const LevelPtr& defaultLevel);
@@ -173,7 +180,7 @@ namespace log4cxx
                 <code>defaultLevel</code>.
                 * @param sArg level name.
                 * @param defaultLevel level to return if no match.
-                * @return 
+                * @return
                 */
                 static LevelPtr toLevelLS(const LogString& sArg,
                         const LevelPtr& defaultLevel);
@@ -262,6 +269,25 @@ namespace log4cxx
                 Level(const Level&);
                 Level& operator=(const Level&);
         };
+
+       /**
+        * We need to double some logic from LOG4CXX_PTR_DEF or else we are 
unable to override the
+        * comparison operator, which we need to properly fix LOGCXX-394.
+        *
+        * https://issues.apache.org/jira/browse/LOGCXX-394
+        */
+       inline bool LevelPtr::operator==(const LevelPtr& rhs) const
+       { return (*this)->equals(rhs); }
+       inline bool LevelPtr::operator!=(const LevelPtr& rhs) const
+       { return !(*this == rhs); }
+       #if defined(_MSC_VER) && !defined(LOG4CXX_STATIC) && defined(LOG4CXX)
+               template class LOG4CXX_EXPORT 
log4cxx::helpers::ObjectPtrT<Level>;
+       #elif defined(_MSC_VER) && !defined(LOG4CXX_STATIC)
+               #pragma warning(push)
+               #pragma warning(disable: 4231)
+               extern template class LOG4CXX_EXPORT 
log4cxx::helpers::ObjectPtrT<Level>;
+               #pragma warning(pop)
+       #endif
 }
 
 #define DECLARE_LOG4CXX_LEVEL(level)\


Reply via email to