/src/dcmtk/oflog/libsrc/objreg.cc
Line | Count | Source |
1 | | // Module: Log4CPLUS |
2 | | // File: objectregistry.cxx |
3 | | // Created: 3/2003 |
4 | | // Author: Tad E. Smith |
5 | | // |
6 | | // |
7 | | // Copyright 2003-2010 Tad E. Smith |
8 | | // |
9 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
10 | | // you may not use this file except in compliance with the License. |
11 | | // You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software |
16 | | // distributed under the License is distributed on an "AS IS" BASIS, |
17 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
18 | | // See the License for the specific language governing permissions and |
19 | | // limitations under the License. |
20 | | |
21 | | #include "dcmtk/oflog/spi/objreg.h" |
22 | | #include "dcmtk/oflog/thread/syncpub.h" |
23 | | #include "dcmtk/oflog/thread/threads.h" |
24 | | |
25 | | |
26 | | namespace dcmtk { |
27 | | namespace log4cplus { namespace spi { |
28 | | |
29 | | |
30 | | /////////////////////////////////////////////////////////////////////////////// |
31 | | // ObjectRegistryBase ctor and dtor |
32 | | /////////////////////////////////////////////////////////////////////////////// |
33 | | |
34 | | ObjectRegistryBase::ObjectRegistryBase() |
35 | 24 | : mutex() |
36 | 24 | , data() |
37 | 24 | { } |
38 | | |
39 | | |
40 | | ObjectRegistryBase::~ObjectRegistryBase() |
41 | 0 | { } |
42 | | |
43 | | |
44 | | |
45 | | /////////////////////////////////////////////////////////////////////////////// |
46 | | // ObjectRegistryBase public methods |
47 | | /////////////////////////////////////////////////////////////////////////////// |
48 | | |
49 | | bool |
50 | | ObjectRegistryBase::exists(const tstring& name) const |
51 | 0 | { |
52 | 0 | thread::MutexGuard guard (mutex); |
53 | |
|
54 | 0 | return data.find(name) != data.end(); |
55 | 0 | } |
56 | | |
57 | | |
58 | | OFVector<tstring> |
59 | | ObjectRegistryBase::getAllNames() const |
60 | 0 | { |
61 | 0 | OFVector<tstring> tmp; |
62 | |
|
63 | 0 | { |
64 | 0 | thread::MutexGuard guard (mutex); |
65 | 0 | for(ObjectMap::const_iterator it=data.begin(); it!=data.end(); ++it) |
66 | 0 | tmp.push_back( (*it).first ); |
67 | 0 | } |
68 | |
|
69 | 0 | return tmp; |
70 | 0 | } |
71 | | |
72 | | |
73 | | |
74 | | /////////////////////////////////////////////////////////////////////////////// |
75 | | // ObjectRegistryBase protected methods |
76 | | /////////////////////////////////////////////////////////////////////////////// |
77 | | |
78 | | bool |
79 | | ObjectRegistryBase::putVal(const tstring& name, void* object) |
80 | 120 | { |
81 | 120 | ObjectMap::value_type value(name, object); |
82 | 120 | OFPair<ObjectMap::iterator, bool> ret; |
83 | | |
84 | 120 | { |
85 | 120 | thread::MutexGuard guard (mutex); |
86 | 120 | ret = data.insert(value); |
87 | 120 | } |
88 | | |
89 | 120 | if (! ret.second) |
90 | 0 | deleteObject( value.second ); |
91 | 120 | return ret.second; |
92 | 120 | } |
93 | | |
94 | | |
95 | | void* |
96 | | ObjectRegistryBase::getVal(const tstring& name) const |
97 | 0 | { |
98 | 0 | thread::MutexGuard guard (mutex); |
99 | |
|
100 | 0 | ObjectMap::const_iterator it (data.find (name)); |
101 | 0 | if (it != data.end ()) |
102 | 0 | return it->second; |
103 | 0 | else |
104 | 0 | return 0; |
105 | 0 | } |
106 | | |
107 | | |
108 | | |
109 | | |
110 | | void |
111 | | ObjectRegistryBase::clear() |
112 | 0 | { |
113 | 0 | thread::MutexGuard guard (mutex); |
114 | |
|
115 | 0 | for(ObjectMap::iterator it=data.begin(); it!=data.end(); ++it) |
116 | 0 | deleteObject( it->second ); |
117 | 0 | } |
118 | | |
119 | | |
120 | | } } // namespace log4cplus { namespace spi { |
121 | | } // end namespace dcmtk |