|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 /* |
|
18 * Licensed to the Apache Software Foundation (ASF) under one or more |
|
19 * contributor license agreements. See the NOTICE file distributed with |
|
20 * this work for additional information regarding copyright ownership. |
|
21 * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
22 * (the "License"); you may not use this file except in compliance with |
|
23 * the License. You may obtain a copy of the License at |
|
24 * |
|
25 * http://www.apache.org/licenses/LICENSE-2.0 |
|
26 * |
|
27 * Unless required by applicable law or agreed to in writing, software |
|
28 * distributed under the License is distributed on an "AS IS" BASIS, |
|
29 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
30 * See the License for the specific language governing permissions and |
|
31 * limitations under the License. |
|
32 */ |
|
33 |
|
34 /* |
|
35 * $Id: FieldValueMap.hpp 568078 2007-08-21 11:43:25Z amassari $ |
|
36 */ |
|
37 |
|
38 #if !defined(FIELDVALUEMAP_HPP) |
|
39 #define FIELDVALUEMAP_HPP |
|
40 |
|
41 /** |
|
42 * This class maps values associated with fields of an identity constraint |
|
43 * that have successfully matched some string in an instance document. |
|
44 */ |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // Includes |
|
48 // --------------------------------------------------------------------------- |
|
49 #include <xercesc/util/XMLString.hpp> |
|
50 #include <xercesc/util/ValueVectorOf.hpp> |
|
51 #include <xercesc/util/RefArrayVectorOf.hpp> |
|
52 |
|
53 XERCES_CPP_NAMESPACE_BEGIN |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // Forward Declaration |
|
57 // --------------------------------------------------------------------------- |
|
58 class IC_Field; |
|
59 class DatatypeValidator; |
|
60 |
|
61 |
|
62 class VALIDATORS_EXPORT FieldValueMap : public XMemory |
|
63 { |
|
64 public: |
|
65 // ----------------------------------------------------------------------- |
|
66 // Constructors/Destructor |
|
67 // ----------------------------------------------------------------------- |
|
68 FieldValueMap(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
|
69 FieldValueMap(const FieldValueMap& other); |
|
70 ~FieldValueMap(); |
|
71 |
|
72 // ----------------------------------------------------------------------- |
|
73 // Getter methods |
|
74 // ----------------------------------------------------------------------- |
|
75 DatatypeValidator* getDatatypeValidatorAt(const unsigned int index) const; |
|
76 DatatypeValidator* getDatatypeValidatorFor(const IC_Field* const key) const; |
|
77 XMLCh* getValueAt(const unsigned int index) const; |
|
78 XMLCh* getValueFor(const IC_Field* const key) const; |
|
79 IC_Field* keyAt(const unsigned int index) const; |
|
80 |
|
81 // ----------------------------------------------------------------------- |
|
82 // Setter methods |
|
83 // ----------------------------------------------------------------------- |
|
84 void put(IC_Field* const key, DatatypeValidator* const dv, |
|
85 const XMLCh* const value); |
|
86 |
|
87 // ----------------------------------------------------------------------- |
|
88 // Helper methods |
|
89 // ----------------------------------------------------------------------- |
|
90 unsigned int size() const; |
|
91 int indexOf(const IC_Field* const key) const; |
|
92 |
|
93 private: |
|
94 // ----------------------------------------------------------------------- |
|
95 // Private helper methods |
|
96 // ----------------------------------------------------------------------- |
|
97 void cleanUp(); |
|
98 |
|
99 // ----------------------------------------------------------------------- |
|
100 // Unimplemented operators |
|
101 // ----------------------------------------------------------------------- |
|
102 FieldValueMap& operator= (const FieldValueMap& other); |
|
103 |
|
104 // ----------------------------------------------------------------------- |
|
105 // Data |
|
106 // ----------------------------------------------------------------------- |
|
107 ValueVectorOf<IC_Field*>* fFields; |
|
108 ValueVectorOf<DatatypeValidator*>* fValidators; |
|
109 RefArrayVectorOf<XMLCh>* fValues; |
|
110 MemoryManager* fMemoryManager; |
|
111 }; |
|
112 |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // FieldValueMap: Getter methods |
|
116 // --------------------------------------------------------------------------- |
|
117 inline DatatypeValidator* |
|
118 FieldValueMap::getDatatypeValidatorAt(const unsigned int index) const { |
|
119 |
|
120 if (fValidators) { |
|
121 return fValidators->elementAt(index); |
|
122 } |
|
123 |
|
124 return 0; |
|
125 } |
|
126 |
|
127 inline DatatypeValidator* |
|
128 FieldValueMap::getDatatypeValidatorFor(const IC_Field* const key) const { |
|
129 |
|
130 if (fValidators) { |
|
131 return fValidators->elementAt(indexOf(key)); |
|
132 } |
|
133 |
|
134 return 0; |
|
135 } |
|
136 |
|
137 inline XMLCh* FieldValueMap::getValueAt(const unsigned int index) const { |
|
138 |
|
139 if (fValues) { |
|
140 return fValues->elementAt(index); |
|
141 } |
|
142 |
|
143 return 0; |
|
144 } |
|
145 |
|
146 inline XMLCh* FieldValueMap::getValueFor(const IC_Field* const key) const { |
|
147 |
|
148 if (fValues) { |
|
149 return fValues->elementAt(indexOf(key)); |
|
150 } |
|
151 |
|
152 return 0; |
|
153 } |
|
154 |
|
155 inline IC_Field* FieldValueMap::keyAt(const unsigned int index) const { |
|
156 |
|
157 if (fFields) { |
|
158 return fFields->elementAt(index); |
|
159 } |
|
160 |
|
161 return 0; |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // FieldValueMap: Helper methods |
|
166 // --------------------------------------------------------------------------- |
|
167 inline unsigned int FieldValueMap::size() const { |
|
168 |
|
169 if (fFields) { |
|
170 return fFields->size(); |
|
171 } |
|
172 |
|
173 return 0; |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // FieldValueMap: Setter methods |
|
178 // --------------------------------------------------------------------------- |
|
179 inline void FieldValueMap::put(IC_Field* const key, |
|
180 DatatypeValidator* const dv, |
|
181 const XMLCh* const value) { |
|
182 |
|
183 if (!fFields) { |
|
184 fFields = new (fMemoryManager) ValueVectorOf<IC_Field*>(4, fMemoryManager); |
|
185 fValidators = new (fMemoryManager) ValueVectorOf<DatatypeValidator*>(4, fMemoryManager); |
|
186 fValues = new (fMemoryManager) RefArrayVectorOf<XMLCh>(4, true, fMemoryManager); |
|
187 } |
|
188 |
|
189 int keyIndex = indexOf(key); |
|
190 |
|
191 if (keyIndex == -1) { |
|
192 |
|
193 fFields->addElement(key); |
|
194 fValidators->addElement(dv); |
|
195 fValues->addElement(XMLString::replicate(value, fMemoryManager)); |
|
196 } |
|
197 else { |
|
198 fValidators->setElementAt(dv, keyIndex); |
|
199 fValues->setElementAt(XMLString::replicate(value, fMemoryManager), keyIndex); |
|
200 } |
|
201 } |
|
202 |
|
203 XERCES_CPP_NAMESPACE_END |
|
204 |
|
205 #endif |
|
206 |
|
207 /** |
|
208 * End of file FieldValueMap.hpp |
|
209 */ |
|
210 |