1 | /*
|
---|
2 | * Copyright 1999-2002,2004 The Apache Software Foundation.
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | */
|
---|
16 | #if !defined(ABSTRACTVECTOROF_HPP)
|
---|
17 | #define ABSTRACTVECTOROF_HPP
|
---|
18 |
|
---|
19 | #include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
|
---|
20 | #include <xercesc/util/XMLEnumerator.hpp>
|
---|
21 | #include <xercesc/util/PlatformUtils.hpp>
|
---|
22 | #include <xercesc/framework/MemoryManager.hpp>
|
---|
23 |
|
---|
24 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Abstract base class for the xerces internal representation of Vector.
|
---|
28 | *
|
---|
29 | * The destructor is abstract, forcing each of RefVectorOf and
|
---|
30 | * RefArrayVectorOf to implement their own appropriate one.
|
---|
31 | *
|
---|
32 | */
|
---|
33 | template <class TElem> class BaseRefVectorOf : public XMemory
|
---|
34 | {
|
---|
35 | public :
|
---|
36 | // -----------------------------------------------------------------------
|
---|
37 | // Constructors and Destructor
|
---|
38 | // -----------------------------------------------------------------------
|
---|
39 | BaseRefVectorOf
|
---|
40 | (
|
---|
41 | const unsigned int maxElems
|
---|
42 | , const bool adoptElems = true
|
---|
43 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
44 | );
|
---|
45 | virtual ~BaseRefVectorOf() = 0;
|
---|
46 |
|
---|
47 |
|
---|
48 | // -----------------------------------------------------------------------
|
---|
49 | // Element management
|
---|
50 | // -----------------------------------------------------------------------
|
---|
51 | void addElement(TElem* const toAdd);
|
---|
52 | virtual void setElementAt(TElem* const toSet, const unsigned int setAt);
|
---|
53 | void insertElementAt(TElem* const toInsert, const unsigned int insertAt);
|
---|
54 | TElem* orphanElementAt(const unsigned int orphanAt);
|
---|
55 | virtual void removeAllElements();
|
---|
56 | virtual void removeElementAt(const unsigned int removeAt);
|
---|
57 | virtual void removeLastElement();
|
---|
58 | bool containsElement(const TElem* const toCheck);
|
---|
59 | virtual void cleanup();
|
---|
60 | void reinitialize();
|
---|
61 |
|
---|
62 |
|
---|
63 | // -----------------------------------------------------------------------
|
---|
64 | // Getter methods
|
---|
65 | // -----------------------------------------------------------------------
|
---|
66 | unsigned int curCapacity() const;
|
---|
67 | const TElem* elementAt(const unsigned int getAt) const;
|
---|
68 | TElem* elementAt(const unsigned int getAt);
|
---|
69 | unsigned int size() const;
|
---|
70 | MemoryManager* getMemoryManager() const;
|
---|
71 |
|
---|
72 |
|
---|
73 | // -----------------------------------------------------------------------
|
---|
74 | // Miscellaneous
|
---|
75 | // -----------------------------------------------------------------------
|
---|
76 | void ensureExtraCapacity(const unsigned int length);
|
---|
77 |
|
---|
78 | private:
|
---|
79 | // -----------------------------------------------------------------------
|
---|
80 | // Unimplemented constructors and operators
|
---|
81 | // -----------------------------------------------------------------------
|
---|
82 | BaseRefVectorOf(const BaseRefVectorOf<TElem>& copy);
|
---|
83 | BaseRefVectorOf& operator=(const BaseRefVectorOf<TElem>& copy);
|
---|
84 |
|
---|
85 | protected:
|
---|
86 | // -----------------------------------------------------------------------
|
---|
87 | // Data members
|
---|
88 | // -----------------------------------------------------------------------
|
---|
89 | bool fAdoptedElems;
|
---|
90 | unsigned int fCurCount;
|
---|
91 | unsigned int fMaxCount;
|
---|
92 | TElem** fElemList;
|
---|
93 | MemoryManager* fMemoryManager;
|
---|
94 | };
|
---|
95 |
|
---|
96 |
|
---|
97 | //
|
---|
98 | // An enumerator for a vector. It derives from the basic enumerator
|
---|
99 | // class, so that value vectors can be generically enumerated.
|
---|
100 | //
|
---|
101 | template <class TElem> class BaseRefVectorEnumerator : public XMLEnumerator<TElem>, public XMemory
|
---|
102 | {
|
---|
103 | public :
|
---|
104 | // -----------------------------------------------------------------------
|
---|
105 | // Constructors and Destructor
|
---|
106 | // -----------------------------------------------------------------------
|
---|
107 | BaseRefVectorEnumerator
|
---|
108 | (
|
---|
109 | BaseRefVectorOf<TElem>* const toEnum
|
---|
110 | , const bool adopt = false
|
---|
111 | );
|
---|
112 | virtual ~BaseRefVectorEnumerator();
|
---|
113 |
|
---|
114 | BaseRefVectorEnumerator(const BaseRefVectorEnumerator<TElem>& copy);
|
---|
115 | // -----------------------------------------------------------------------
|
---|
116 | // Enum interface
|
---|
117 | // -----------------------------------------------------------------------
|
---|
118 | bool hasMoreElements() const;
|
---|
119 | TElem& nextElement();
|
---|
120 | void Reset();
|
---|
121 |
|
---|
122 |
|
---|
123 | private :
|
---|
124 | // -----------------------------------------------------------------------
|
---|
125 | // Unimplemented constructors and operators
|
---|
126 | // -----------------------------------------------------------------------
|
---|
127 | BaseRefVectorEnumerator& operator=(const BaseRefVectorEnumerator<TElem>& copy);
|
---|
128 | // -----------------------------------------------------------------------
|
---|
129 | // Data Members
|
---|
130 | //
|
---|
131 | // fAdopted
|
---|
132 | // Indicates whether we have adopted the passed vector. If so then
|
---|
133 | // we delete the vector when we are destroyed.
|
---|
134 | //
|
---|
135 | // fCurIndex
|
---|
136 | // This is the current index into the vector.
|
---|
137 | //
|
---|
138 | // fToEnum
|
---|
139 | // The reference vector being enumerated.
|
---|
140 | // -----------------------------------------------------------------------
|
---|
141 | bool fAdopted;
|
---|
142 | unsigned int fCurIndex;
|
---|
143 | BaseRefVectorOf<TElem>* fToEnum;
|
---|
144 | };
|
---|
145 |
|
---|
146 | XERCES_CPP_NAMESPACE_END
|
---|
147 |
|
---|
148 | #if !defined(XERCES_TMPLSINC)
|
---|
149 | #include <xercesc/util/BaseRefVectorOf.c>
|
---|
150 | #endif
|
---|
151 |
|
---|
152 | #endif
|
---|