source: trunk/VUT/GtpVisibilityPreprocessor/support/xercesc/validators/schema/identity/FieldValueMap.hpp @ 188

Revision 188, 8.2 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
1/*
2 * The Apache Software License, Version 1.1
3 *
4 * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
5 * reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in
16 *    the documentation and/or other materials provided with the
17 *    distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 *    if any, must include the following acknowledgment:
21 *       "This product includes software developed by the
22 *        Apache Software Foundation (http://www.apache.org/)."
23 *    Alternately, this acknowledgment may appear in the software itself,
24 *    if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Xerces" and "Apache Software Foundation" must
27 *    not be used to endorse or promote products derived from this
28 *    software without prior written permission. For written
29 *    permission, please contact apache\@apache.org.
30 *
31 * 5. Products derived from this software may not be called "Apache",
32 *    nor may "Apache" appear in their name, without prior written
33 *    permission of the Apache Software Foundation.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation, and was
51 * originally based on software copyright (c) 2001, International
52 * Business Machines, Inc., http://www.ibm.com .  For more information
53 * on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57/*
58 * $Id: FieldValueMap.hpp,v 1.7 2003/05/26 22:05:01 knoaman Exp $
59 */
60
61#if !defined(FIELDVALUEMAP_HPP)
62#define FIELDVALUEMAP_HPP
63
64/**
65  * This class maps values associated with fields of an identity constraint
66  * that have successfully matched some string in an instance document.
67  */
68
69// ---------------------------------------------------------------------------
70//  Includes
71// ---------------------------------------------------------------------------
72#include <xercesc/util/XMLString.hpp>
73#include <xercesc/util/ValueVectorOf.hpp>
74#include <xercesc/util/RefArrayVectorOf.hpp>
75
76XERCES_CPP_NAMESPACE_BEGIN
77
78// ---------------------------------------------------------------------------
79//  Forward Declaration
80// ---------------------------------------------------------------------------
81class IC_Field;
82class DatatypeValidator;
83
84
85class VALIDATORS_EXPORT FieldValueMap : public XMemory
86{
87public:
88    // -----------------------------------------------------------------------
89    //  Constructors/Destructor
90    // -----------------------------------------------------------------------
91    FieldValueMap(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
92    FieldValueMap(const FieldValueMap& other);
93        ~FieldValueMap();
94
95        // -----------------------------------------------------------------------
96    //  Getter methods
97    // -----------------------------------------------------------------------
98    DatatypeValidator* getDatatypeValidatorAt(const unsigned int index) const;
99    DatatypeValidator* getDatatypeValidatorFor(const IC_Field* const key) const;
100    XMLCh* getValueAt(const unsigned int index) const;
101    XMLCh* getValueFor(const IC_Field* const key) const;
102    IC_Field* keyAt(const unsigned int index) const;
103
104        // -----------------------------------------------------------------------
105    //  Setter methods
106    // -----------------------------------------------------------------------
107    void put(IC_Field* const key, DatatypeValidator* const dv,
108             const XMLCh* const value);
109
110        // -----------------------------------------------------------------------
111    //  Helper methods
112    // -----------------------------------------------------------------------
113    unsigned int size() const;
114    int indexOf(const IC_Field* const key) const;
115
116private:
117    // -----------------------------------------------------------------------
118    //  Unimplemented operators
119    // -----------------------------------------------------------------------
120    FieldValueMap& operator= (const FieldValueMap& other);
121
122    // -----------------------------------------------------------------------
123    //  Data
124    // -----------------------------------------------------------------------
125    ValueVectorOf<IC_Field*>*          fFields;
126    ValueVectorOf<DatatypeValidator*>* fValidators;
127    RefArrayVectorOf<XMLCh>*           fValues;
128    MemoryManager*                     fMemoryManager;
129};
130
131
132// ---------------------------------------------------------------------------
133//  FieldValueMap: Getter methods
134// ---------------------------------------------------------------------------
135inline DatatypeValidator*
136FieldValueMap::getDatatypeValidatorAt(const unsigned int index) const {
137
138    if (fValidators) {
139        return fValidators->elementAt(index);
140    }
141
142    return 0;
143}
144
145inline DatatypeValidator*
146FieldValueMap::getDatatypeValidatorFor(const IC_Field* const key) const {
147
148    if (fValidators) {
149        return fValidators->elementAt(indexOf(key));
150    }
151
152    return 0;
153}
154
155inline XMLCh* FieldValueMap::getValueAt(const unsigned int index) const {
156
157    if (fValues) {
158        return fValues->elementAt(index);
159    }
160
161    return 0;
162}
163
164inline XMLCh* FieldValueMap::getValueFor(const IC_Field* const key) const {
165
166    if (fValues) {
167        return fValues->elementAt(indexOf(key));
168    }
169
170    return 0;
171}
172
173inline IC_Field* FieldValueMap::keyAt(const unsigned int index) const {
174
175    if (fFields) {
176        return fFields->elementAt(index);
177    }
178
179    return 0;
180}
181
182// ---------------------------------------------------------------------------
183//  FieldValueMap: Helper methods
184// ---------------------------------------------------------------------------
185inline unsigned int FieldValueMap::size() const {
186
187    if (fFields) {
188        return fFields->size();
189    }
190
191    return 0;
192}
193
194// ---------------------------------------------------------------------------
195//  FieldValueMap: Setter methods
196// ---------------------------------------------------------------------------
197inline void FieldValueMap::put(IC_Field* const key,
198                               DatatypeValidator* const dv,
199                               const XMLCh* const value) {
200
201    if (!fFields) {
202        fFields = new (fMemoryManager) ValueVectorOf<IC_Field*>(4, fMemoryManager);
203        fValidators = new (fMemoryManager) ValueVectorOf<DatatypeValidator*>(4, fMemoryManager);
204        fValues = new (fMemoryManager) RefArrayVectorOf<XMLCh>(4, true, fMemoryManager);
205    }
206
207    int keyIndex = indexOf(key);
208
209    if (keyIndex == -1) {
210
211        fFields->addElement(key);
212        fValidators->addElement(dv);
213        fValues->addElement(XMLString::replicate(value, fMemoryManager));
214    }
215    else {
216        fValidators->setElementAt(dv, keyIndex);
217        fValues->setElementAt(XMLString::replicate(value, fMemoryManager), keyIndex);
218    }
219}
220
221XERCES_CPP_NAMESPACE_END
222
223#endif
224
225/**
226  * End of file FieldValueMap.hpp
227  */
228
Note: See TracBrowser for help on using the repository browser.