source: icXML/icXML-devel/src/xercesc/validators/schema/identity/ValueStoreCache.cpp

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

Updates for build

File size: 5.4 KB
RevLine 
[2722]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: ValueStoreCache.cpp 708224 2008-10-27 16:02:26Z amassari $
20 */
21
22// ---------------------------------------------------------------------------
23//  Includes
24// ---------------------------------------------------------------------------
25#include <xercesc/validators/schema/identity/ValueStoreCache.hpp>
26#include <xercesc/validators/schema/identity/ValueStore.hpp>
[3153]27#include <icxercesc/validators/schema/SchemaElementDecl.hpp>
[2722]28#include <xercesc/util/OutOfMemoryException.hpp>
29
30XERCES_CPP_NAMESPACE_BEGIN
31
32typedef JanitorMemFunCall<ValueStoreCache>    CleanupType;
33
34// ---------------------------------------------------------------------------
35//  ValueStoreCache: Constructors and Destructor
36// ---------------------------------------------------------------------------
37ValueStoreCache::ValueStoreCache(MemoryManager* const manager)
38    : fValueStores(0)
39    , fGlobalICMap(0)
40    , fIC2ValueStoreMap(0)
41    , fGlobalMapStack(0)
42    , fScanner(0)
43    , fMemoryManager(manager)
44{
45    CleanupType cleanup(this, &ValueStoreCache::cleanUp);
46
47    try {
48        init();
49    }
50    catch(const OutOfMemoryException&)
51    {
52        cleanup.release();
53
54        throw;
55    }
56
57    cleanup.release();
58}
59
60
61ValueStoreCache::~ValueStoreCache()
62{
63    cleanUp();
64}
65
66// ---------------------------------------------------------------------------
67//  ValueStoreCache: Document handling methods
68// ---------------------------------------------------------------------------
69void ValueStoreCache::startDocument() {
70
71    fIC2ValueStoreMap->removeAll();
72    fGlobalICMap->removeAll();
73    fValueStores->removeAllElements();
74    fGlobalMapStack->removeAllElements();
75}
76
77void ValueStoreCache::startElement() {
78
79    fGlobalMapStack->push(fGlobalICMap);
80    fGlobalICMap = new (fMemoryManager) RefHashTableOf<ValueStore, PtrHasher>
81    (
82        13
83        , false
84        , fMemoryManager
85    );
86}
87
88void ValueStoreCache::endElement() {
89
90    if (fGlobalMapStack->empty()) {
91        return; // must be an invalid doc!
92    }
93
94    RefHashTableOf<ValueStore, PtrHasher>* oldMap = fGlobalMapStack->pop();
95    RefHashTableOfEnumerator<ValueStore, PtrHasher> mapEnum(oldMap, false, fMemoryManager);
96//    Janitor<RefHashTableOf<ValueStore> > janMap(oldMap);
97
98    while (mapEnum.hasMoreElements()) {
99
100        ValueStore& oldVal = mapEnum.nextElement();
101        IdentityConstraint* ic = oldVal.getIdentityConstraint();
102        ValueStore* currVal = fGlobalICMap->get(ic);
103
104        if (!currVal) {
105            fGlobalICMap->put(ic, &oldVal);
106        }
107        else {
108            currVal->append(&oldVal);
109        }
110    }
111    delete oldMap;
112}
113
114// ---------------------------------------------------------------------------
115//  ValueStoreCache: Helper methods
116// ---------------------------------------------------------------------------
117void ValueStoreCache::cleanUp() {
118
119    delete fIC2ValueStoreMap;
120    delete fGlobalICMap;
121    delete fGlobalMapStack;
122    delete fValueStores;
123}
124
125void ValueStoreCache::init() {
126
127    fValueStores = new (fMemoryManager) RefVectorOf<ValueStore>(8, false, fMemoryManager);
128    fGlobalICMap = new (fMemoryManager) RefHashTableOf<ValueStore, PtrHasher>
129    (
130        13
131        , false
132        , fMemoryManager
133    );
134    fIC2ValueStoreMap = new (fMemoryManager) RefHash2KeysTableOf<ValueStore, PtrHasher>
135    (
136        13
137        , true
138        , fMemoryManager
139    );
140    fGlobalMapStack = new (fMemoryManager) RefStackOf<RefHashTableOf<ValueStore, PtrHasher> >(8, true, fMemoryManager);
141}
142
143void ValueStoreCache::initValueStoresFor(SchemaElementDecl* const elemDecl,
144                                         const int initialDepth) {
145
146    // initialize value stores for unique fields
147    XMLSize_t icCount = elemDecl->getIdentityConstraintCount();
148
149    for (XMLSize_t i=0; i<icCount; i++) {
150
151        IdentityConstraint* ic = elemDecl->getIdentityConstraintAt(i);
152        ValueStore* valueStore=fIC2ValueStoreMap->get(ic, initialDepth);
153        if(valueStore==0)
154        {
155            valueStore = new (fMemoryManager) ValueStore(ic, fScanner, fMemoryManager);
156            fIC2ValueStoreMap->put(ic, initialDepth, valueStore);
157        }
158        else
159            valueStore->clear();
160        fValueStores->addElement(valueStore);
161    }
162}
163
164void ValueStoreCache::transplant(IdentityConstraint* const ic, const int initialDepth) {
165
166    if (ic->getType() == IdentityConstraint::ICType_KEYREF) {
167        return;
168    }
169
170    ValueStore* newVals = fIC2ValueStoreMap->get(ic, initialDepth);
171    ValueStore* currVals = fGlobalICMap->get(ic);
172
173    if (currVals) {
174        currVals->append(newVals);
175    } else {
176        fGlobalICMap->put(ic, newVals);
177    }
178}
179
180XERCES_CPP_NAMESPACE_END
181
182/**
183  * End of file ValueStoreCache.cpp
184  */
Note: See TracBrowser for help on using the repository browser.