logging-log4cxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carn...@apache.org
Subject cvs commit: logging-log4cxx/src class.cpp
Date Fri, 07 Jan 2005 22:17:54 GMT
carnold     2005/01/07 14:17:54

  Modified:    include/log4cxx level.h
               include/log4cxx/helpers class.h object.h
               src      class.cpp
  Log:
  LOGCXX-4: Eliminated non-local static Class objects
  
  Revision  Changes    Path
  1.20      +7 -5      logging-log4cxx/include/log4cxx/level.h
  
  Index: level.h
  ===================================================================
  RCS file: /home/cvs/logging-log4cxx/include/log4cxx/level.h,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- level.h	2 Jan 2005 05:40:04 -0000	1.19
  +++ level.h	7 Jan 2005 22:17:53 -0000	1.20
  @@ -58,11 +58,12 @@
           public:
                   class LOG4CXX_EXPORT LevelClass : public helpers::Class
                   {
  -                protected:
  -                        LevelClass(const LogString& className) : helpers::Class(className)
{}
  -
                   public:
  -                        LevelClass() : helpers::Class(LOG4CXX_STR("Level")) {}
  +                        LevelClass() : helpers::Class() {}
  +
  +                        virtual const log4cxx::logchar* getName() const {
  +                            return LOG4CXX_STR("Level");
  +                        }
   
                           virtual const LevelPtr& toLevel(const LogString& sArg)
const
                           { return Level::toLevel(sArg); }
  @@ -229,7 +230,8 @@
           class Class##level : public Level::LevelClass\
   {\
   public:\
  -        Class##level() : Level::LevelClass(LOG4CXX_STR(#level)) {}\
  +        Class##level() : Level::LevelClass() {}\
  +        virtual const log4cxx::logchar* getName() const { return LOG4CXX_STR(#level); }
\
           virtual const LevelPtr& toLevel(const LogString& sArg) const\
           { return level::toLevel(sArg); }\
           virtual const LevelPtr& toLevel(int val) const\
  
  
  
  1.17      +53 -52    logging-log4cxx/include/log4cxx/helpers/class.h
  
  Index: class.h
  ===================================================================
  RCS file: /home/cvs/logging-log4cxx/include/log4cxx/helpers/class.h,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- class.h	18 Dec 2004 07:53:04 -0000	1.16
  +++ class.h	7 Jan 2005 22:17:53 -0000	1.17
  @@ -1,53 +1,54 @@
  -/*
  - * Copyright 2003,2004 The Apache Software Foundation.
  - *
  - * Licensed under the Apache License, Version 2.0 (the "License");
  - * you may not use this file except in compliance with the License.
  - * You may obtain a copy of the License at
  - *
  - *      http://www.apache.org/licenses/LICENSE-2.0
  - *
  - * Unless required by applicable law or agreed to in writing, software
  - * distributed under the License is distributed on an "AS IS" BASIS,
  - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  - * See the License for the specific language governing permissions and
  - * limitations under the License.
  - */
  -
  -#ifndef _LOG4CXX_HELPERS_CLASS_H
  -#define _LOG4CXX_HELPERS_CLASS_H
  -
  -#include <log4cxx/logstring.h>
  -#include <log4cxx/helpers/objectptr.h>
  +/*
  + * Copyright 2003,2005 The Apache Software Foundation.
  + *
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *      http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  + * See the License for the specific language governing permissions and
  + * limitations under the License.
  + */
  +
  +#ifndef _LOG4CXX_HELPERS_CLASS_H
  +#define _LOG4CXX_HELPERS_CLASS_H
  +
  +#include <log4cxx/logstring.h>
  +#include <log4cxx/helpers/objectptr.h>
   #include <map>
  -
  -namespace log4cxx
  -{
  -        namespace helpers
  -        {
  -                class Object;
  -                typedef ObjectPtrT<Object> ObjectPtr;
  -
  -
  -                class LOG4CXX_EXPORT Class
  -                {
  -                public:
  -                        Class(const LogString& name);
  -                        virtual ~Class();
  -                        virtual ObjectPtr newInstance() const;
  -                        const LogString& toString() const;
  -                        const LogString& getName() const;
  -                        static const Class& forName(const LogString& className);
  -
  -                protected:
  -                        static void registerClass(const Class * newClass);
  -                        LogString name;
  -
  -                private:
  -                        typedef std::map<LogString, const Class *> ClassMap;
  -                        static ClassMap& getRegistry();
  -                };
  -        }  // namespace log4cxx
  -} // namespace helper
  -
  -#endif //_LOG4CXX_HELPERS_CLASS_H
  +
  +namespace log4cxx
  +{
  +        namespace helpers
  +        {
  +                class Object;
  +                typedef ObjectPtrT<Object> ObjectPtr;
  +
  +
  +                class LOG4CXX_EXPORT Class
  +                {
  +                public:
  +                        virtual ~Class();
  +                        virtual ObjectPtr newInstance() const;
  +                        const LogString toString() const;
  +                        virtual const logchar* getName() const = 0;
  +                        static const Class& forName(const LogString& className);
  +                        static bool registerClass(const Class& newClass);
  +
  +                protected:
  +                        Class();
  +
  +                private:
  +                        Class(const Class&);
  +                        Class& operator=(const Class&);
  +                        typedef std::map<LogString, const Class *> ClassMap;
  +                        static ClassMap& getRegistry();
  +                };
  +        }  // namespace log4cxx
  +} // namespace helper
  +
  +#endif //_LOG4CXX_HELPERS_CLASS_H
  
  
  
  1.19      +19 -14    logging-log4cxx/include/log4cxx/helpers/object.h
  
  Index: object.h
  ===================================================================
  RCS file: /home/cvs/logging-log4cxx/include/log4cxx/helpers/object.h,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- object.h	26 Dec 2004 07:31:52 -0000	1.18
  +++ object.h	7 Jan 2005 22:17:53 -0000	1.19
  @@ -28,42 +28,47 @@
   class Class##object : public helpers::Class\
   {\
   public:\
  -        Class##object() : helpers::Class(LOG4CXX_STR(#object)) {}\
  +        Class##object() : helpers::Class() {}\
  +        virtual const log4cxx::logchar* getName() const { return LOG4CXX_STR(#object);
} \
   };\
   virtual const helpers::Class& getClass() const;\
  -static const helpers::Class& getStaticClass();\
  -static Class##object theClass##object;
  +static const helpers::Class& getStaticClass();
   
   #define DECLARE_LOG4CXX_OBJECT(object)\
   public:\
   class Class##object : public helpers::Class\
   {\
   public:\
  -        Class##object() : helpers::Class(LOG4CXX_STR(#object)) {}\
  +        Class##object() : helpers::Class() {}\
  +        virtual const log4cxx::logchar* getName() const { return LOG4CXX_STR(#object);
} \
           virtual helpers::ObjectPtr newInstance() const\
           {\
                   return new object();\
           }\
   };\
   virtual const helpers::Class& getClass() const;\
  -static const helpers::Class& getStaticClass();\
  -static Class##object theClass##object;
  +static const helpers::Class& getStaticClass();
   
   #define DECLARE_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(object, class)\
   public:\
   virtual const helpers::Class& getClass() const;\
  -static const helpers::Class& getStaticClass();\
  -static class theClass##object;
  +static const helpers::Class& getStaticClass();
   
   #define IMPLEMENT_LOG4CXX_OBJECT(object)\
  -object::Class##object object::theClass##object;\
  -const log4cxx::helpers::Class& object::getClass() const { return theClass##object;
}\
  -const log4cxx::helpers::Class& object::getStaticClass() { return theClass##object;
}
  +const log4cxx::helpers::Class& object::getClass() const { return getStaticClass();
}\
  +const log4cxx::helpers::Class& object::getStaticClass() { \
  +   static Class##object theClass;                         \
  +   return theClass;                                       \
  +}                                                         \
  +namespace log4cxx { namespace classes { bool object##IsRegistered = log4cxx::helpers::Class::registerClass(object::getStaticClass());
} }
   
   #define IMPLEMENT_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(object, class)\
  -object::class object::theClass##object;\
  -const log4cxx::helpers::Class& object::getClass() const { return theClass##object;
}\
  -const log4cxx::helpers::Class& object::getStaticClass() { return theClass##object;
}
  +const log4cxx::helpers::Class& object::getClass() const { return getStaticClass();
}\
  +const log4cxx::helpers::Class& object::getStaticClass() { \
  +   static class theClass;                                 \
  +   return theClass;                                       \
  +}                                                         \
  +namespace log4cxx { namespace classes { bool object##IsRegistered = log4cxx::helpers::Class::registerClass(object::getStaticClass());
} }
   
   
   namespace log4cxx
  
  
  
  1.17      +6 -16     logging-log4cxx/src/class.cpp
  
  Index: class.cpp
  ===================================================================
  RCS file: /home/cvs/logging-log4cxx/src/class.cpp,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- class.cpp	2 Jan 2005 05:40:04 -0000	1.16
  +++ class.cpp	7 Jan 2005 22:17:54 -0000	1.17
  @@ -25,23 +25,16 @@
   
   
   
  -Class::Class(const LogString& name) : name(name)
  -{
  -        registerClass(this);
  +Class::Class() {
   }
   
   Class::~Class()
   {
   }
   
  -const LogString& Class::toString() const
  -{
  -        return name;
  -}
  -
  -const LogString& Class::getName() const
  +const LogString Class::toString() const
   {
  -        return name;
  +        return getName();
   }
   
   ObjectPtr Class::newInstance() const
  @@ -79,11 +72,8 @@
           return *clazz;
   }
   
  -void Class::registerClass(const Class * newClass)
  +bool Class::registerClass(const Class& newClass)
   {
  -        if (newClass == 0)
  -        {
  -                return;
  -        }
  -        getRegistry()[StringHelper::toLowerCase(newClass->toString())] = newClass;
  +        getRegistry()[StringHelper::toLowerCase(newClass.getName())] = &newClass;
  +        return true;
   }
  
  
  

Mime
View raw message