source: NonGTP/Xerces/xerces/include/xercesc/util/SynchronizedStringPool.hpp @ 358

Revision 358, 3.5 KB checked in by bittner, 19 years ago (diff)

xerces added

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