log4cplus
2.0.0
|
00001 // -*- C++ -*- 00002 // Module: Log4CPLUS 00003 // File: objectregistry.h 00004 // Created: 3/2003 00005 // Author: Tad E. Smith 00006 // 00007 // 00008 // Copyright 2003-2015 Tad E. Smith 00009 // 00010 // Licensed under the Apache License, Version 2.0 (the "License"); 00011 // you may not use this file except in compliance with the License. 00012 // You may obtain a copy of the License at 00013 // 00014 // http://www.apache.org/licenses/LICENSE-2.0 00015 // 00016 // Unless required by applicable law or agreed to in writing, software 00017 // distributed under the License is distributed on an "AS IS" BASIS, 00018 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 // See the License for the specific language governing permissions and 00020 // limitations under the License. 00021 00024 #ifndef LOG4CPLUS_SPI_OBJECT_REGISTRY_HEADER_ 00025 #define LOG4CPLUS_SPI_OBJECT_REGISTRY_HEADER_ 00026 00027 #include <log4cplus/config.hxx> 00028 00029 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 00030 #pragma once 00031 #endif 00032 00033 #include <log4cplus/tstring.h> 00034 #include <log4cplus/thread/syncprims.h> 00035 #include <map> 00036 #include <memory> 00037 #include <vector> 00038 00039 00040 namespace log4cplus { 00041 namespace spi { 00042 00047 class LOG4CPLUS_EXPORT ObjectRegistryBase { 00048 public: 00049 // public methods 00054 bool exists(const log4cplus::tstring& name) const; 00055 00059 std::vector<log4cplus::tstring> getAllNames() const; 00060 00064 void _enableLocking (bool); 00065 00066 protected: 00067 // Ctor and Dtor 00068 ObjectRegistryBase(); 00069 virtual ~ObjectRegistryBase(); 00070 00071 // protected methods 00076 bool putVal(const log4cplus::tstring& name, void* object); 00077 00082 void* getVal(const log4cplus::tstring& name) const; 00083 00087 virtual void deleteObject(void *object) const = 0; 00088 00092 virtual void clear(); 00093 00094 // Types 00095 typedef std::map<log4cplus::tstring, void*> ObjectMap; 00096 00097 // Data 00098 thread::Mutex mutex; 00099 ObjectMap data; 00100 00101 private: 00102 ObjectRegistryBase (ObjectRegistryBase const &); 00103 ObjectRegistryBase & operator = (ObjectRegistryBase const &); 00104 00105 bool volatile locking; 00106 }; 00107 00108 } 00109 } 00110 00111 00112 #endif // LOG4CPLUS_SPI_OBJECT_REGISTRY_HEADER_ 00113