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