source: NonGTP/Xerces/xerces/include/xercesc/validators/schema/identity/ValueStoreCache.hpp @ 358

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

xerces added

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