Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:18

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  * 
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  * 
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_FIELDVALUEMAP_HPP)
0023 #define XERCESC_INCLUDE_GUARD_FIELDVALUEMAP_HPP
0024 
0025 /**
0026   * This class maps values associated with fields of an identity constraint
0027   * that have successfully matched some string in an instance document.
0028   */
0029 
0030 // ---------------------------------------------------------------------------
0031 //  Includes
0032 // ---------------------------------------------------------------------------
0033 #include <xercesc/util/XMLString.hpp>
0034 #include <xercesc/util/ValueVectorOf.hpp>
0035 #include <xercesc/util/RefArrayVectorOf.hpp>
0036 
0037 XERCES_CPP_NAMESPACE_BEGIN
0038 
0039 // ---------------------------------------------------------------------------
0040 //  Forward Declaration
0041 // ---------------------------------------------------------------------------
0042 class IC_Field;
0043 class DatatypeValidator;
0044 
0045 
0046 class VALIDATORS_EXPORT FieldValueMap : public XMemory
0047 {
0048 public:
0049     // -----------------------------------------------------------------------
0050     //  Constructors/Destructor
0051     // -----------------------------------------------------------------------
0052     FieldValueMap(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0053     FieldValueMap(const FieldValueMap& other);
0054     ~FieldValueMap();
0055 
0056     // -----------------------------------------------------------------------
0057     //  Getter methods
0058     // -----------------------------------------------------------------------
0059     DatatypeValidator* getDatatypeValidatorAt(const XMLSize_t index) const;
0060     DatatypeValidator* getDatatypeValidatorFor(const IC_Field* const key) const;
0061     XMLCh* getValueAt(const XMLSize_t index) const;
0062     XMLCh* getValueFor(const IC_Field* const key) const;
0063     IC_Field* keyAt(const XMLSize_t index) const;
0064 
0065     // -----------------------------------------------------------------------
0066     //  Setter methods
0067     // -----------------------------------------------------------------------
0068     void put(IC_Field* const key, DatatypeValidator* const dv,
0069              const XMLCh* const value);
0070 
0071     // -----------------------------------------------------------------------
0072     //  Helper methods
0073     // -----------------------------------------------------------------------
0074     XMLSize_t size() const;
0075     bool indexOf(const IC_Field* const key, XMLSize_t& location) const;
0076     void clear();
0077 
0078 private:
0079     // -----------------------------------------------------------------------
0080     //  Private helper methods
0081     // -----------------------------------------------------------------------
0082     void cleanUp();
0083 
0084     // -----------------------------------------------------------------------
0085     //  Unimplemented operators
0086     // -----------------------------------------------------------------------
0087     FieldValueMap& operator= (const FieldValueMap& other);
0088 
0089     // -----------------------------------------------------------------------
0090     //  Data
0091     // -----------------------------------------------------------------------
0092     ValueVectorOf<IC_Field*>*          fFields;
0093     ValueVectorOf<DatatypeValidator*>* fValidators;
0094     RefArrayVectorOf<XMLCh>*           fValues;
0095     MemoryManager*                     fMemoryManager;
0096 };
0097 
0098 
0099 // ---------------------------------------------------------------------------
0100 //  FieldValueMap: Getter methods
0101 // ---------------------------------------------------------------------------
0102 inline DatatypeValidator*
0103 FieldValueMap::getDatatypeValidatorAt(const XMLSize_t index) const {
0104 
0105     if (fValidators) {
0106         return fValidators->elementAt(index);
0107     }
0108 
0109     return 0;
0110 }
0111 
0112 inline DatatypeValidator*
0113 FieldValueMap::getDatatypeValidatorFor(const IC_Field* const key) const {
0114 
0115     XMLSize_t location;
0116     if (fValidators && indexOf(key, location)) {
0117         return fValidators->elementAt(location);
0118     }
0119 
0120     return 0;
0121 }
0122 
0123 inline XMLCh* FieldValueMap::getValueAt(const XMLSize_t index) const {
0124 
0125     if (fValues) {
0126         return fValues->elementAt(index);
0127     }
0128 
0129     return 0;
0130 }
0131 
0132 inline XMLCh* FieldValueMap::getValueFor(const IC_Field* const key) const {
0133 
0134     XMLSize_t location;
0135     if (fValues && indexOf(key, location)) {
0136         return fValues->elementAt(location);
0137     }
0138 
0139     return 0;
0140 }
0141 
0142 inline IC_Field* FieldValueMap::keyAt(const XMLSize_t index) const {
0143 
0144     if (fFields) {
0145         return fFields->elementAt(index);
0146     }
0147 
0148     return 0;
0149 }
0150 
0151 // ---------------------------------------------------------------------------
0152 //  FieldValueMap: Helper methods
0153 // ---------------------------------------------------------------------------
0154 inline XMLSize_t FieldValueMap::size() const {
0155 
0156     if (fFields) {
0157         return fFields->size();
0158     }
0159 
0160     return 0;
0161 }
0162 
0163 // ---------------------------------------------------------------------------
0164 //  FieldValueMap: Setter methods
0165 // ---------------------------------------------------------------------------
0166 inline void FieldValueMap::put(IC_Field* const key,
0167                                DatatypeValidator* const dv,
0168                                const XMLCh* const value) {
0169 
0170     if (!fFields) {
0171         fFields = new (fMemoryManager) ValueVectorOf<IC_Field*>(4, fMemoryManager);
0172         fValidators = new (fMemoryManager) ValueVectorOf<DatatypeValidator*>(4, fMemoryManager);
0173         fValues = new (fMemoryManager) RefArrayVectorOf<XMLCh>(4, true, fMemoryManager);
0174     }
0175 
0176     XMLSize_t keyIndex;
0177     bool bFound=indexOf(key, keyIndex);
0178 
0179     if (!bFound) {
0180 
0181         fFields->addElement(key);
0182         fValidators->addElement(dv);
0183         fValues->addElement(XMLString::replicate(value, fMemoryManager));
0184     }
0185     else {
0186         fValidators->setElementAt(dv, keyIndex);
0187         fValues->setElementAt(XMLString::replicate(value, fMemoryManager), keyIndex);
0188     }
0189 }
0190 
0191 XERCES_CPP_NAMESPACE_END
0192 
0193 #endif
0194 
0195 /**
0196   * End of file FieldValueMap.hpp
0197   */
0198