1 // Module:  Log4CPLUS
 2 // File:    objectregistry.h
 3 // Created: 3/2003
 4 // Author:  Tad E. Smith
 5 //
 6 //
 7 // Copyright (C) Tad E. Smith  All rights reserved.
 8 //
 9 // This software is published under the terms of the Apache Software
10 // License version 1.1, a copy of which has been included with this
11 // distribution in the LICENSE.APL file.
12 //
13 
14 /** @file */
15 
16 #ifndef LOG4CPLUS_SPI_OBJECT_REGISTRY_HEADER_
17 #define LOG4CPLUS_SPI_OBJECT_REGISTRY_HEADER_
18 
19 #include <log4cplus/config.h>
20 #include <log4cplus/tstring.h>
21 #include <log4cplus/helpers/threads.h>
22 #include <map>
23 #include <memory>
24 #include <vector>
25 
26 
27 namespace log4cplus {
28     namespace spi {
29 
30         /**
31          * This is the base class used to implement the functionality required
32          * by the ObjectRegistry template class.
33          */
34         class LOG4CPLUS_EXPORT ObjectRegistryBase {
35         public:
36           // public methods
37             /**
38              * Tests to see whether or not an object is bound in the
39              * registry as <code>name</code>.
40              */
41             bool exists(const log4cplus::tstring& name) const;
42 
43             /**
44              * Returns the names of all registered objects.
45              */
46             std::vector<log4cplus::tstring> getAllNames() const;
47 
48         protected:
49           // Ctor and Dtor
50             ObjectRegistryBase();
51             virtual ~ObjectRegistryBase();
52 
53           // protected methods
54             /**
55              * Used to enter an object into the registry.  (The registry now
56              * owns <code>object</code>.)
57              */
58             bool putVal(const log4cplus::tstring& name, void* object);
59 
60             /**
61              * Used to retrieve an object from the registry.  (The registry
62              * owns the returned pointer.)
63              */
64             void* getVal(const log4cplus::tstring& name) const;
65 
66             /**
67              * Deletes <code>object</code>.
68              */
69             virtual void deleteObject(void *object) const = 0;
70 
71             /**
72              * Deletes all objects from this registry.
73              */
74             virtual void clear();
75 
76           // Types
77             typedef std::map<log4cplus::tstring, void*> ObjectMap;
78 
79           // Data
80             LOG4CPLUS_MUTEX_PTR_DECLARE mutex;
81             ObjectMap data;
82         };
83 
84     }
85 }
86 
87 
88 #endif // LOG4CPLUS_SPI_OBJECT_REGISTRY_HEADER_


syntax highlighted by Code2HTML, v. 0.9.1