source: icXML/icXML-devel/src/xercesc/validators/schema/identity/ValueStoreCache.hpp @ 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: 7.0 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: ValueStoreCache.hpp 932887 2010-04-11 13:04:59Z borisk $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_VALUESTORECACHE_HPP)
23#define XERCESC_INCLUDE_GUARD_VALUESTORECACHE_HPP
24
25/**
26  * This class is used to store the values for identity constraints.
27  *
28  * Sketch of algorithm:
29  *  - When a constraint is first encountered, its values are stored in the
30  *    (local) fIC2ValueStoreMap;
31  *  - Once it is validated (i.e., when it goes out of scope), its values are
32  *    merged into the fGlobalICMap;
33  *  - As we encounter keyref's, we look at the global table to validate them.
34  *  - Validation always occurs against the fGlobalIDConstraintMap (which
35  *    comprises all the "eligible" id constraints). When an endelement is
36  *    found, this Hashtable is merged with the one below in the stack. When a
37  *    start tag is encountered, we create a new fGlobalICMap.
38  *    i.e., the top of the fGlobalIDMapStack always contains the preceding
39  *    siblings' eligible id constraints; the fGlobalICMap contains
40  *    descendants+self. Keyrefs can only match descendants+self.
41  */
42
43// ---------------------------------------------------------------------------
44//  Includes
45// ---------------------------------------------------------------------------
46#include <xercesc/util/RefVectorOf.hpp>
47#include <icxercesc/util/RefHashTableOf.hpp>
48#include <xercesc/util/RefHash2KeysTableOf.hpp>
49#include <xercesc/util/RefStackOf.hpp>
50#include <xercesc/validators/schema/identity/IdentityConstraint.hpp>
51#include <xercesc/validators/schema/identity/IC_Field.hpp>
52
53XERCES_CPP_NAMESPACE_BEGIN
54
55// ---------------------------------------------------------------------------
56//  Forward Declaration
57// ---------------------------------------------------------------------------
58class ValueStore;
59class SchemaElementDecl;
60class XMLScanner;
61
62
63class VALIDATORS_EXPORT ValueStoreCache : public XMemory
64{
65public:
66    // -----------------------------------------------------------------------
67    //  Constructors/Destructor
68    // -----------------------------------------------------------------------
69    ValueStoreCache(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
70        ~ValueStoreCache();
71
72        // -----------------------------------------------------------------------
73    //  Setter Methods
74    // -----------------------------------------------------------------------
75    void setScanner(XMLScanner* const scanner);
76
77        // -----------------------------------------------------------------------
78    //  Document Handling methods
79    // -----------------------------------------------------------------------
80    void startDocument();
81    void startElement();
82    void endElement();
83    void endDocument();
84
85        // -----------------------------------------------------------------------
86    //  Initialization methods
87    // -----------------------------------------------------------------------
88    void initValueStoresFor(SchemaElementDecl* const elemDecl, const int initialDepth);
89
90
91        // -----------------------------------------------------------------------
92    //  Access methods
93    // -----------------------------------------------------------------------
94    ValueStore* getValueStoreFor(const IC_Field* const field, const int initialDepth);
95    ValueStore* getValueStoreFor(const IdentityConstraint* const ic, const int initialDepth);
96    ValueStore* getGlobalValueStoreFor(const IdentityConstraint* const ic);
97
98        // -----------------------------------------------------------------------
99    //  Helper methods
100    // -----------------------------------------------------------------------
101    /** This method takes the contents of the (local) ValueStore associated
102      * with ic and moves them into the global hashtable, if ic is a <unique>
103      * or a <key>. If it's a <keyRef>, then we leave it for later.
104      */
105    void transplant(IdentityConstraint* const ic, const int initialDepth);
106
107private:
108    // -----------------------------------------------------------------------
109    //  Unimplemented constructors and operators
110    // -----------------------------------------------------------------------
111    ValueStoreCache(const ValueStoreCache& other);
112    ValueStoreCache& operator= (const ValueStoreCache& other);
113
114    // -----------------------------------------------------------------------
115    //  Helper methods
116    // -----------------------------------------------------------------------
117    void init();
118    void cleanUp();
119
120    // -----------------------------------------------------------------------
121    //  Data
122    // -----------------------------------------------------------------------
123    RefVectorOf<ValueStore>*                 fValueStores;
124    RefHashTableOf<ValueStore, PtrHasher>*   fGlobalICMap;
125    RefHash2KeysTableOf<ValueStore, PtrHasher>* fIC2ValueStoreMap;
126    RefStackOf<RefHashTableOf<ValueStore, PtrHasher> >* fGlobalMapStack;
127    XMLScanner*                              fScanner;
128    MemoryManager*                           fMemoryManager;
129};
130
131// ---------------------------------------------------------------------------
132//  ValueStoreCache: Access methods
133// ---------------------------------------------------------------------------
134inline void ValueStoreCache::setScanner(XMLScanner* const scanner) {
135
136    fScanner = scanner;
137}
138
139// ---------------------------------------------------------------------------
140//  ValueStoreCache: Access methods
141// ---------------------------------------------------------------------------
142inline ValueStore*
143ValueStoreCache::getValueStoreFor(const IC_Field* const field, const int initialDepth) {
144
145    return fIC2ValueStoreMap->get(field->getIdentityConstraint(), initialDepth);
146}
147
148inline ValueStore*
149ValueStoreCache::getValueStoreFor(const IdentityConstraint* const ic, const int initialDepth) {
150
151    return fIC2ValueStoreMap->get(ic, initialDepth);
152}
153
154inline ValueStore*
155ValueStoreCache::getGlobalValueStoreFor(const IdentityConstraint* const ic) {
156
157    return fGlobalICMap->get(ic);
158}
159
160// ---------------------------------------------------------------------------
161//  ValueStoreCache: Document handling methods
162// ---------------------------------------------------------------------------
163inline void ValueStoreCache::endDocument() {
164}
165
166XERCES_CPP_NAMESPACE_END
167
168#endif
169
170/**
171  * End of file ValueStoreCache.hpp
172  */
Note: See TracBrowser for help on using the repository browser.