GME  13
FieldValueMap.cpp
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  * 
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  * 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: FieldValueMap.cpp 708224 2008-10-27 16:02:26Z amassari $
00020  */
00021 
00022 // ---------------------------------------------------------------------------
00023 //  Includes
00024 // ---------------------------------------------------------------------------
00025 #include <xercesc/validators/schema/identity/FieldValueMap.hpp>
00026 #include <xercesc/util/Janitor.hpp>
00027 #include <xercesc/util/OutOfMemoryException.hpp>
00028 
00029 XERCES_CPP_NAMESPACE_BEGIN
00030 
00031 typedef JanitorMemFunCall<FieldValueMap>    CleanupType;
00032 
00033 // ---------------------------------------------------------------------------
00034 //  FieldValueMap: Constructors and Destructor
00035 // ---------------------------------------------------------------------------
00036 FieldValueMap::FieldValueMap(MemoryManager* const manager)
00037     : fFields(0)
00038     , fValidators(0)
00039     , fValues(0)
00040     , fMemoryManager(manager)
00041 {
00042 }
00043 
00044 FieldValueMap::FieldValueMap(const FieldValueMap& other)
00045     : XMemory(other)
00046     , fFields(0)
00047     , fValidators(0)
00048     , fValues(0)
00049     , fMemoryManager(other.fMemoryManager)
00050 {
00051     if (other.fFields) {
00052         CleanupType cleanup(this, &FieldValueMap::cleanUp);
00053 
00054         try {
00055 
00056                 XMLSize_t valuesSize = other.fValues->size();
00057 
00058                 fFields = new (fMemoryManager) ValueVectorOf<IC_Field*>(*(other.fFields));
00059                 fValidators = new (fMemoryManager) ValueVectorOf<DatatypeValidator*>(*(other.fValidators));
00060                 fValues = new (fMemoryManager) RefArrayVectorOf<XMLCh>(other.fFields->curCapacity(), true, fMemoryManager);
00061 
00062                 for (XMLSize_t i=0; i<valuesSize; i++) {
00063                     fValues->addElement(XMLString::replicate(other.fValues->elementAt(i), fMemoryManager));
00064                 }
00065         }
00066         catch(const OutOfMemoryException&)
00067         {
00068             cleanup.release();
00069 
00070             throw;
00071         }
00072 
00073         cleanup.release();
00074     }
00075 }
00076 
00077 FieldValueMap::~FieldValueMap()
00078 {
00079     cleanUp();
00080 }
00081 
00082 // ---------------------------------------------------------------------------
00083 //  FieldValueMap: Private helper methods.
00084 // ---------------------------------------------------------------------------
00085 void FieldValueMap::cleanUp()
00086 {
00087     delete fFields;
00088     delete fValidators;
00089     delete fValues;
00090 }
00091 
00092 // ---------------------------------------------------------------------------
00093 //  FieldValueMap: Helper methods
00094 // ---------------------------------------------------------------------------
00095 bool FieldValueMap::indexOf(const IC_Field* const key, XMLSize_t& location) const {
00096 
00097     if (fFields) {
00098 
00099         XMLSize_t fieldSize = fFields->size();
00100 
00101         for (XMLSize_t i=0; i < fieldSize; i++) {
00102             if (fFields->elementAt(i) == key) {
00103                 location=i;
00104                 return true;
00105             }
00106         }
00107     }
00108 
00109     return false;
00110 }
00111 
00112 void FieldValueMap::clear()
00113 {
00114     if(fFields)
00115         fFields->removeAllElements();
00116     if(fValidators)
00117         fValidators->removeAllElements();
00118     if(fValues)
00119         fValues->removeAllElements();
00120 }
00121 
00122 XERCES_CPP_NAMESPACE_END
00123