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

Revision 358, 6.1 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: FieldValueMap.hpp,v 1.8 2004/09/08 13:56:59 peiyongz Exp $
19 */
20
21#if !defined(FIELDVALUEMAP_HPP)
22#define FIELDVALUEMAP_HPP
23
24/**
25  * This class maps values associated with fields of an identity constraint
26  * that have successfully matched some string in an instance document.
27  */
28
29// ---------------------------------------------------------------------------
30//  Includes
31// ---------------------------------------------------------------------------
32#include <xercesc/util/XMLString.hpp>
33#include <xercesc/util/ValueVectorOf.hpp>
34#include <xercesc/util/RefArrayVectorOf.hpp>
35
36XERCES_CPP_NAMESPACE_BEGIN
37
38// ---------------------------------------------------------------------------
39//  Forward Declaration
40// ---------------------------------------------------------------------------
41class IC_Field;
42class DatatypeValidator;
43
44
45class VALIDATORS_EXPORT FieldValueMap : public XMemory
46{
47public:
48    // -----------------------------------------------------------------------
49    //  Constructors/Destructor
50    // -----------------------------------------------------------------------
51    FieldValueMap(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
52    FieldValueMap(const FieldValueMap& other);
53        ~FieldValueMap();
54
55        // -----------------------------------------------------------------------
56    //  Getter methods
57    // -----------------------------------------------------------------------
58    DatatypeValidator* getDatatypeValidatorAt(const unsigned int index) const;
59    DatatypeValidator* getDatatypeValidatorFor(const IC_Field* const key) const;
60    XMLCh* getValueAt(const unsigned int index) const;
61    XMLCh* getValueFor(const IC_Field* const key) const;
62    IC_Field* keyAt(const unsigned int index) const;
63
64        // -----------------------------------------------------------------------
65    //  Setter methods
66    // -----------------------------------------------------------------------
67    void put(IC_Field* const key, DatatypeValidator* const dv,
68             const XMLCh* const value);
69
70        // -----------------------------------------------------------------------
71    //  Helper methods
72    // -----------------------------------------------------------------------
73    unsigned int size() const;
74    int indexOf(const IC_Field* const key) const;
75
76private:
77    // -----------------------------------------------------------------------
78    //  Unimplemented operators
79    // -----------------------------------------------------------------------
80    FieldValueMap& operator= (const FieldValueMap& other);
81
82    // -----------------------------------------------------------------------
83    //  Data
84    // -----------------------------------------------------------------------
85    ValueVectorOf<IC_Field*>*          fFields;
86    ValueVectorOf<DatatypeValidator*>* fValidators;
87    RefArrayVectorOf<XMLCh>*           fValues;
88    MemoryManager*                     fMemoryManager;
89};
90
91
92// ---------------------------------------------------------------------------
93//  FieldValueMap: Getter methods
94// ---------------------------------------------------------------------------
95inline DatatypeValidator*
96FieldValueMap::getDatatypeValidatorAt(const unsigned int index) const {
97
98    if (fValidators) {
99        return fValidators->elementAt(index);
100    }
101
102    return 0;
103}
104
105inline DatatypeValidator*
106FieldValueMap::getDatatypeValidatorFor(const IC_Field* const key) const {
107
108    if (fValidators) {
109        return fValidators->elementAt(indexOf(key));
110    }
111
112    return 0;
113}
114
115inline XMLCh* FieldValueMap::getValueAt(const unsigned int index) const {
116
117    if (fValues) {
118        return fValues->elementAt(index);
119    }
120
121    return 0;
122}
123
124inline XMLCh* FieldValueMap::getValueFor(const IC_Field* const key) const {
125
126    if (fValues) {
127        return fValues->elementAt(indexOf(key));
128    }
129
130    return 0;
131}
132
133inline IC_Field* FieldValueMap::keyAt(const unsigned int index) const {
134
135    if (fFields) {
136        return fFields->elementAt(index);
137    }
138
139    return 0;
140}
141
142// ---------------------------------------------------------------------------
143//  FieldValueMap: Helper methods
144// ---------------------------------------------------------------------------
145inline unsigned int FieldValueMap::size() const {
146
147    if (fFields) {
148        return fFields->size();
149    }
150
151    return 0;
152}
153
154// ---------------------------------------------------------------------------
155//  FieldValueMap: Setter methods
156// ---------------------------------------------------------------------------
157inline void FieldValueMap::put(IC_Field* const key,
158                               DatatypeValidator* const dv,
159                               const XMLCh* const value) {
160
161    if (!fFields) {
162        fFields = new (fMemoryManager) ValueVectorOf<IC_Field*>(4, fMemoryManager);
163        fValidators = new (fMemoryManager) ValueVectorOf<DatatypeValidator*>(4, fMemoryManager);
164        fValues = new (fMemoryManager) RefArrayVectorOf<XMLCh>(4, true, fMemoryManager);
165    }
166
167    int keyIndex = indexOf(key);
168
169    if (keyIndex == -1) {
170
171        fFields->addElement(key);
172        fValidators->addElement(dv);
173        fValues->addElement(XMLString::replicate(value, fMemoryManager));
174    }
175    else {
176        fValidators->setElementAt(dv, keyIndex);
177        fValues->setElementAt(XMLString::replicate(value, fMemoryManager), keyIndex);
178    }
179}
180
181XERCES_CPP_NAMESPACE_END
182
183#endif
184
185/**
186  * End of file FieldValueMap.hpp
187  */
188
Note: See TracBrowser for help on using the repository browser.