source: icXML/icXML-devel/src/xercesc/util/SynchronizedStringPool.cpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 4.1 KB
Line 
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.cpp 903137 2010-01-26 09:26:28Z borisk $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#include <xercesc/util/SynchronizedStringPool.hpp>
27
28
29XERCES_CPP_NAMESPACE_BEGIN
30
31// ---------------------------------------------------------------------------
32//  XMLSynchronizedStringPool: Constructors and Destructor
33// ---------------------------------------------------------------------------
34XMLSynchronizedStringPool::XMLSynchronizedStringPool(const XMLStringPool *constPool
35                , const  unsigned int  modulus
36                , MemoryManager* const manager) :
37
38    XMLStringPool(modulus, manager)
39    , fConstPool(constPool)
40    , fMutex(manager)
41{
42}
43
44XMLSynchronizedStringPool::~XMLSynchronizedStringPool()
45{
46}
47
48
49// ---------------------------------------------------------------------------
50//  XMLSynchronizedStringPool: Pool management methods
51// ---------------------------------------------------------------------------
52unsigned int XMLSynchronizedStringPool::addOrFind(const XMLCh* const newString)
53{
54    unsigned int id = fConstPool->getId(newString);
55    if(id)
56        return id;
57    // might have to add it to our own table.
58    // synchronize this bit
59    unsigned int constCount = fConstPool->getStringCount();
60    XMLMutexLock lockInit(&fMutex);
61    id = XMLStringPool::addOrFind(newString);
62    return id+constCount;
63}
64
65bool XMLSynchronizedStringPool::exists(const XMLCh* const newString) const
66{
67    if(fConstPool->exists(newString))
68        return true;
69
70    XMLMutexLock lockInit(&const_cast<XMLSynchronizedStringPool*>(this)->fMutex);
71    return XMLStringPool::exists(newString);
72}
73
74bool XMLSynchronizedStringPool::exists(const unsigned int id) const
75{
76    if (!id)
77        return false;
78
79    // First see if this id belongs to the const pool.
80    //
81    unsigned int constCount = fConstPool->getStringCount();
82
83    if (id <= constCount)
84      return true;
85
86    // The rest needs to be synchronized.
87    //
88    XMLMutexLock lockInit(&const_cast<XMLSynchronizedStringPool*>(this)->fMutex);
89    return id < fCurId + constCount;
90}
91
92void XMLSynchronizedStringPool::flushAll()
93{
94    // don't touch const pool!
95    XMLStringPool::flushAll();
96}
97
98
99unsigned int XMLSynchronizedStringPool::getId(const XMLCh* const toFind) const
100{
101    unsigned int retVal = fConstPool->getId(toFind);
102    if(retVal)
103        return retVal;
104
105    // make sure we return a truly unique id
106    unsigned int constCount = fConstPool->getStringCount();
107    XMLMutexLock lockInit(&const_cast<XMLSynchronizedStringPool*>(this)->fMutex);
108    return XMLStringPool::getId(toFind)+constCount;
109}
110
111
112const XMLCh* XMLSynchronizedStringPool::getValueForId(const unsigned int id) const
113{
114    if (id <= fConstPool->getStringCount())
115        return fConstPool->getValueForId(id);
116
117    unsigned int constCount = fConstPool->getStringCount();
118    XMLMutexLock lockInit(&const_cast<XMLSynchronizedStringPool*>(this)->fMutex);
119    return XMLStringPool::getValueForId(id-constCount);
120}
121
122unsigned int XMLSynchronizedStringPool::getStringCount() const
123{
124    unsigned int constCount = fConstPool->getStringCount();
125    XMLMutexLock lockInit(&const_cast<XMLSynchronizedStringPool*>(this)->fMutex);
126    return fCurId+constCount-1;
127}
128
129XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.