1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | * $Id: SynchronizedStringPool.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | #if !defined(SYNCHRONIZEDSTRINGPOOL_HPP) |
---|
23 | #define SYNCHRONIZEDSTRINGPOOL_HPP |
---|
24 | |
---|
25 | #include <xercesc/framework/MemoryManager.hpp> |
---|
26 | #include <xercesc/util/StringPool.hpp> |
---|
27 | #include <xercesc/util/Mutexes.hpp> |
---|
28 | |
---|
29 | XERCES_CPP_NAMESPACE_BEGIN |
---|
30 | |
---|
31 | // |
---|
32 | // This class provides a synchronized string pool implementation. |
---|
33 | // This will necessarily be slower than the regular StringPool, so it |
---|
34 | // should only be used when updates need to be made in a thread-safe |
---|
35 | // way. Updates will be made on datastructures local to this object; |
---|
36 | // all queries that don't involve mutation will first be directed at |
---|
37 | // the StringPool implementation with which this object is |
---|
38 | // constructed. |
---|
39 | class XMLUTIL_EXPORT XMLSynchronizedStringPool : public XMLStringPool |
---|
40 | { |
---|
41 | public : |
---|
42 | // ----------------------------------------------------------------------- |
---|
43 | // Constructors and Destructor |
---|
44 | // ----------------------------------------------------------------------- |
---|
45 | XMLSynchronizedStringPool |
---|
46 | ( |
---|
47 | const XMLStringPool * constPool |
---|
48 | , const unsigned int modulus = 109 |
---|
49 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
50 | ); |
---|
51 | virtual ~XMLSynchronizedStringPool(); |
---|
52 | |
---|
53 | |
---|
54 | // ----------------------------------------------------------------------- |
---|
55 | // Pool management methods |
---|
56 | // ----------------------------------------------------------------------- |
---|
57 | virtual unsigned int addOrFind(const XMLCh* const newString); |
---|
58 | virtual bool exists(const XMLCh* const newString) const; |
---|
59 | virtual bool exists(const unsigned int id) const; |
---|
60 | virtual void flushAll(); |
---|
61 | virtual unsigned int getId(const XMLCh* const toFind) const; |
---|
62 | virtual const XMLCh* getValueForId(const unsigned int id) const; |
---|
63 | virtual unsigned int getStringCount() const; |
---|
64 | |
---|
65 | |
---|
66 | private : |
---|
67 | // ----------------------------------------------------------------------- |
---|
68 | // Unimplemented constructors and operators |
---|
69 | // ----------------------------------------------------------------------- |
---|
70 | XMLSynchronizedStringPool(const XMLSynchronizedStringPool&); |
---|
71 | XMLSynchronizedStringPool& operator=(const XMLSynchronizedStringPool&); |
---|
72 | |
---|
73 | |
---|
74 | // ----------------------------------------------------------------------- |
---|
75 | // private data members |
---|
76 | // fConstPool |
---|
77 | // the pool whose immutability we're protecting |
---|
78 | // fMutex |
---|
79 | // mutex to permit synchronous updates of our StringPool |
---|
80 | const XMLStringPool* fConstPool; |
---|
81 | XMLMutex fMutex; |
---|
82 | }; |
---|
83 | |
---|
84 | XERCES_CPP_NAMESPACE_END |
---|
85 | |
---|
86 | #endif |
---|