source: icXML/icXML-devel/src/xercesc/validators/schema/identity/FieldValueMap.cpp @ 3157

Last change on this file since 3157 was 3157, checked in by cameron, 6 years ago

Fixes for icXML 0.9

File size: 4.7 KB
Line 
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.cpp 708224 2008-10-27 16:02:26Z amassari $
20 */
21
22// ---------------------------------------------------------------------------
23//  Includes
24// ---------------------------------------------------------------------------
25#include <xercesc/validators/schema/identity/FieldValueMap.hpp>
26#include <xercesc/util/Janitor.hpp>
27#include <xercesc/util/OutOfMemoryException.hpp>
28
29XERCES_CPP_NAMESPACE_BEGIN
30
31typedef JanitorMemFunCall<FieldValueMap>    CleanupType;
32
33// ---------------------------------------------------------------------------
34//  FieldValueMap: Constructors and Destructor
35// ---------------------------------------------------------------------------
36FieldValueMap::FieldValueMap(MemoryManager* const manager)
37    : fFields(0)
38    , fValidators(0)
39    , fValues(0)
40    , fMemoryManager(manager)
41{
42}
43
44FieldValueMap::FieldValueMap(const FieldValueMap& other)
45    : XMemory(other)
46    , fFields(0)
47    , fValidators(0)
48    , fValues(0)
49    , fMemoryManager(other.fMemoryManager)
50{
51    if (other.fFields) {
52        CleanupType cleanup(this, &FieldValueMap::cleanUp);
53
54        try {
55
56                XMLSize_t valuesSize = other.fValues->size();
57
58                fFields = new (fMemoryManager) ValueVectorOf<IC_Field*>(*(other.fFields));
59                fValidators = new (fMemoryManager) ValueVectorOf<DatatypeValidator*>(*(other.fValidators));
60                fValues = new (fMemoryManager) RefArrayVectorOf<XMLCh>(other.fFields->curCapacity(), true, fMemoryManager);
61
62                for (XMLSize_t i=0; i<valuesSize; i++) {
63                    fValues->addElement(XMLString::replicate(other.fValues->elementAt(i), fMemoryManager));
64                }
65        }
66        catch(const OutOfMemoryException&)
67        {
68            cleanup.release();
69
70            throw;
71        }
72
73        cleanup.release();
74    }
75}
76
77FieldValueMap::~FieldValueMap()
78{
79    cleanUp();
80}
81
82// ---------------------------------------------------------------------------
83//  FieldValueMap: Private helper methods.
84// ---------------------------------------------------------------------------
85void FieldValueMap::cleanUp()
86{
87    delete fFields;
88    delete fValidators;
89    delete fValues;
90}
91
92// ---------------------------------------------------------------------------
93//  FieldValueMap: Helper methods
94// ---------------------------------------------------------------------------
95bool FieldValueMap::indexOf(const IC_Field* const key, XMLSize_t& location) const {
96
97    if (fFields) {
98
99        XMLSize_t fieldSize = fFields->size();
100
101        for (XMLSize_t i=0; i < fieldSize; i++) {
102            if (fFields->elementAt(i) == key) {
103                location=i;
104                return true;
105            }
106        }
107    }
108
109    return false;
110}
111
112void FieldValueMap::clear()
113{
114    if(fFields)
115        fFields->removeAllElements();
116    if(fValidators)
117        fValidators->removeAllElements();
118    if(fValues)
119        fValues->removeAllElements();
120}
121
122// ---------------------------------------------------------------------------
123//  FieldValueMap: Setter methods
124// ---------------------------------------------------------------------------
125void FieldValueMap::put(IC_Field* const key, DatatypeValidator* const dv, const XMLCh* const value)
126{
127    if (!fFields) {
128        fFields = new (fMemoryManager) ValueVectorOf<IC_Field*>(4, fMemoryManager);
129        fValidators = new (fMemoryManager) ValueVectorOf<DatatypeValidator*>(4, fMemoryManager);
130        fValues = new (fMemoryManager) RefArrayVectorOf<XMLCh>(4, true, fMemoryManager);
131    }
132
133    XMLSize_t keyIndex;
134    if (!indexOf(key, keyIndex))
135    {
136        fFields->addElement(key);
137        fValidators->addElement(dv);
138        fValues->addElement(XMLString::replicate(value, fMemoryManager));
139    }
140    else
141    {
142        fValidators->setElementAt(dv, keyIndex);
143        fValues->setElementAt(XMLString::replicate(value, fMemoryManager), keyIndex);
144    }
145}
146
147XERCES_CPP_NAMESPACE_END
148
149/**
150  * End of file FieldValueMap.cpp
151  */
152
Note: See TracBrowser for help on using the repository browser.