source: icXML/icXML-devel/src/icxercesc/util/BaseRefVectorOf.hpp

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

Changes to icxercesc files

File size: 6.5 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: BaseRefVectorOf.hpp 676911 2008-07-15 13:27:32Z amassari $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_ABSTRACTVECTOROF_HPP)
23#define XERCESC_INCLUDE_GUARD_ABSTRACTVECTOROF_HPP
24
25#include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
26#include <xercesc/util/XMLEnumerator.hpp>
27#include <icxercesc/util/PlatformUtils.hpp>
28#include <xercesc/framework/MemoryManager.hpp>
29
30XERCES_CPP_NAMESPACE_BEGIN
31
32/**
33 * Abstract base class for the xerces internal representation of Vector.
34 *
35 * The destructor is abstract, forcing each of RefVectorOf and
36 * RefArrayVectorOf to implement their own appropriate one.
37 *
38 */
39template <class TElem>
40class BaseRefVectorOf : public XMemory
41{
42    template <class DocHandlerType, bool doPSVI> friend class XMLDocumentDisseminatorImpl;
43
44public :
45    // -----------------------------------------------------------------------
46    //  Constructors and Destructor
47    // -----------------------------------------------------------------------
48    BaseRefVectorOf
49    (
50          const XMLSize_t maxElems
51        , const bool adoptElems = true
52        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
53    );
54    virtual ~BaseRefVectorOf();
55
56
57    // -----------------------------------------------------------------------
58    //  Element management
59    // -----------------------------------------------------------------------
60    void addElement(TElem* const toAdd);
61    virtual void setElementAt(TElem* const toSet, const XMLSize_t setAt);
62    void insertElementAt(TElem* const toInsert, const XMLSize_t insertAt);
63    TElem* orphanElementAt(const XMLSize_t orphanAt);
64    virtual void removeAllElements();
65    virtual void removeElementAt(const XMLSize_t removeAt);
66    virtual void removeLastElement();
67    bool containsElement(const TElem* const toCheck);
68    virtual void cleanup();
69    void reinitialize();
70
71
72    // -----------------------------------------------------------------------
73    //  Getter methods
74    // -----------------------------------------------------------------------
75    XMLSize_t curCapacity() const;
76    const TElem* elementAt(const XMLSize_t getAt) const;
77    TElem* elementAt(const XMLSize_t getAt);
78    XMLSize_t size() const;
79    MemoryManager* getMemoryManager() const;
80    TElem *& operator[](const XMLSize_t index);
81
82    // -----------------------------------------------------------------------
83    //  Miscellaneous
84    // -----------------------------------------------------------------------
85    void ensureExtraCapacity(const XMLSize_t length);
86    void ensureCapacity(const XMLSize_t capacity);
87    void setCount(const XMLSize_t count);
88
89private:
90    // -----------------------------------------------------------------------
91    //  Unimplemented constructors and operators
92    // -----------------------------------------------------------------------
93    BaseRefVectorOf(const BaseRefVectorOf<TElem>& copy);
94    BaseRefVectorOf& operator=(const BaseRefVectorOf<TElem>& copy);       
95
96protected:
97    // -----------------------------------------------------------------------
98    //  Data members
99    // -----------------------------------------------------------------------
100    bool            fAdoptedElems;
101    XMLSize_t       fCurCount;
102    XMLSize_t       fMaxCount;
103    TElem**         fElemList;
104    MemoryManager*  fMemoryManager;
105};
106
107template <class TElem>
108inline void BaseRefVectorOf<TElem>::setCount(const XMLSize_t count)
109{
110    fCurCount = count;
111}
112
113template <class TElem>
114inline TElem *& BaseRefVectorOf<TElem>::operator[](const XMLSize_t index)
115{
116    return fElemList[index];
117}
118
119template <class TElem>
120inline void BaseRefVectorOf<TElem>::ensureCapacity(const XMLSize_t capacity)
121{
122    if (capacity > fMaxCount)
123    {
124        fMemoryManager->deallocate(fElemList);//delete [] fElemList;
125        fElemList = (TElem**) fMemoryManager->allocate(capacity * sizeof(TElem*));
126        fMaxCount = capacity;
127    }
128}
129
130
131//
132//  An enumerator for a vector. It derives from the basic enumerator
133//  class, so that value vectors can be generically enumerated.
134//
135template <class TElem> class BaseRefVectorEnumerator : public XMLEnumerator<TElem>, public XMemory
136{
137public :
138    // -----------------------------------------------------------------------
139    //  Constructors and Destructor
140    // -----------------------------------------------------------------------
141    BaseRefVectorEnumerator
142    (
143        BaseRefVectorOf<TElem>* const   toEnum
144        , const bool adopt = false
145    );
146    virtual ~BaseRefVectorEnumerator();
147
148    BaseRefVectorEnumerator(const BaseRefVectorEnumerator<TElem>& copy);
149    // -----------------------------------------------------------------------
150    //  Enum interface
151    // -----------------------------------------------------------------------
152    bool hasMoreElements() const;
153    TElem& nextElement();
154    void Reset();
155
156
157private :
158    // -----------------------------------------------------------------------
159    //  Unimplemented constructors and operators
160    // -----------------------------------------------------------------------       
161    BaseRefVectorEnumerator& operator=(const BaseRefVectorEnumerator<TElem>& copy);   
162    // -----------------------------------------------------------------------
163    //  Data Members
164    //
165    //  fAdopted
166    //      Indicates whether we have adopted the passed vector. If so then
167    //      we delete the vector when we are destroyed.
168    //
169    //  fCurIndex
170    //      This is the current index into the vector.
171    //
172    //  fToEnum
173    //      The reference vector being enumerated.
174    // -----------------------------------------------------------------------
175    bool                fAdopted;
176    XMLSize_t           fCurIndex;
177    BaseRefVectorOf<TElem>*    fToEnum;
178};
179
180XERCES_CPP_NAMESPACE_END
181
182#if !defined(XERCES_TMPLSINC)
183#include <icxercesc/util/BaseRefVectorOf.c>
184#endif
185
186#endif
Note: See TracBrowser for help on using the repository browser.