[188] | 1 | /*
|
---|
| 2 | * The Apache Software License, Version 1.1
|
---|
| 3 | *
|
---|
| 4 | * Copyright (c) 1999-2000 The Apache Software Foundation. All rights
|
---|
| 5 | * reserved.
|
---|
| 6 | *
|
---|
| 7 | * Redistribution and use in source and binary forms, with or without
|
---|
| 8 | * modification, are permitted provided that the following conditions
|
---|
| 9 | * are met:
|
---|
| 10 | *
|
---|
| 11 | * 1. Redistributions of source code must retain the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer.
|
---|
| 13 | *
|
---|
| 14 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 15 | * notice, this list of conditions and the following disclaimer in
|
---|
| 16 | * the documentation and/or other materials provided with the
|
---|
| 17 | * distribution.
|
---|
| 18 | *
|
---|
| 19 | * 3. The end-user documentation included with the redistribution,
|
---|
| 20 | * if any, must include the following acknowledgment:
|
---|
| 21 | * "This product includes software developed by the
|
---|
| 22 | * Apache Software Foundation (http://www.apache.org/)."
|
---|
| 23 | * Alternately, this acknowledgment may appear in the software itself,
|
---|
| 24 | * if and wherever such third-party acknowledgments normally appear.
|
---|
| 25 | *
|
---|
| 26 | * 4. The names "Xerces" and "Apache Software Foundation" must
|
---|
| 27 | * not be used to endorse or promote products derived from this
|
---|
| 28 | * software without prior written permission. For written
|
---|
| 29 | * permission, please contact apache\@apache.org.
|
---|
| 30 | *
|
---|
| 31 | * 5. Products derived from this software may not be called "Apache",
|
---|
| 32 | * nor may "Apache" appear in their name, without prior written
|
---|
| 33 | * permission of the Apache Software Foundation.
|
---|
| 34 | *
|
---|
| 35 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
---|
| 36 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 37 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
| 38 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
---|
| 39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
| 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
| 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
---|
| 42 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
| 43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
| 44 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
---|
| 45 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
| 46 | * SUCH DAMAGE.
|
---|
| 47 | * ====================================================================
|
---|
| 48 | *
|
---|
| 49 | * This software consists of voluntary contributions made by many
|
---|
| 50 | * individuals on behalf of the Apache Software Foundation, and was
|
---|
| 51 | * originally based on software copyright (c) 1999, International
|
---|
| 52 | * Business Machines, Inc., http://www.ibm.com . For more information
|
---|
| 53 | * on the Apache Software Foundation, please see
|
---|
| 54 | * <http://www.apache.org/>.
|
---|
| 55 | */
|
---|
| 56 |
|
---|
| 57 | /*
|
---|
| 58 | * $Log: ValueVectorOf.hpp,v $
|
---|
| 59 | * Revision 1.8 2004/01/29 11:48:46 cargilld
|
---|
| 60 | * Code cleanup changes to get rid of various compiler diagnostic messages.
|
---|
| 61 | *
|
---|
| 62 | * Revision 1.7 2003/05/29 13:26:44 knoaman
|
---|
| 63 | * Fix memory leak when using deprecated dom.
|
---|
| 64 | *
|
---|
| 65 | * Revision 1.6 2003/05/16 21:37:00 knoaman
|
---|
| 66 | * Memory manager implementation: Modify constructors to pass in the memory manager.
|
---|
| 67 | *
|
---|
| 68 | * Revision 1.5 2003/05/16 06:01:52 knoaman
|
---|
| 69 | * Partial implementation of the configurable memory manager.
|
---|
| 70 | *
|
---|
| 71 | * Revision 1.4 2003/05/15 19:07:46 knoaman
|
---|
| 72 | * Partial implementation of the configurable memory manager.
|
---|
| 73 | *
|
---|
| 74 | * Revision 1.3 2002/11/04 15:22:05 tng
|
---|
| 75 | * C++ Namespace Support.
|
---|
| 76 | *
|
---|
| 77 | * Revision 1.2 2002/08/21 17:45:00 tng
|
---|
| 78 | * [Bug 7087] compiler warnings when using gcc.
|
---|
| 79 | *
|
---|
| 80 | * Revision 1.1.1.1 2002/02/01 22:22:13 peiyongz
|
---|
| 81 | * sane_include
|
---|
| 82 | *
|
---|
| 83 | * Revision 1.6 2002/01/10 17:44:49 knoaman
|
---|
| 84 | * Fix for bug 5786.
|
---|
| 85 | *
|
---|
| 86 | * Revision 1.5 2001/08/09 15:24:37 knoaman
|
---|
| 87 | * add support for <anyAttribute> declaration.
|
---|
| 88 | *
|
---|
| 89 | * Revision 1.4 2000/03/02 19:54:47 roddey
|
---|
| 90 | * This checkin includes many changes done while waiting for the
|
---|
| 91 | * 1.1.0 code to be finished. I can't list them all here, but a list is
|
---|
| 92 | * available elsewhere.
|
---|
| 93 | *
|
---|
| 94 | * Revision 1.3 2000/02/24 20:05:26 abagchi
|
---|
| 95 | * Swat for removing Log from API docs
|
---|
| 96 | *
|
---|
| 97 | * Revision 1.2 2000/02/06 07:48:05 rahulj
|
---|
| 98 | * Year 2K copyright swat.
|
---|
| 99 | *
|
---|
| 100 | * Revision 1.1.1.1 1999/11/09 01:05:33 twl
|
---|
| 101 | * Initial checkin
|
---|
| 102 | *
|
---|
| 103 | * Revision 1.2 1999/11/08 20:45:19 rahul
|
---|
| 104 | * Swat for adding in Product name and CVS comment log variable.
|
---|
| 105 | *
|
---|
| 106 | */
|
---|
| 107 |
|
---|
| 108 |
|
---|
| 109 | #if !defined(VALUEVECTOROF_HPP)
|
---|
| 110 | #define VALUEVECTOROF_HPP
|
---|
| 111 |
|
---|
| 112 | #include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
|
---|
| 113 | #include <xercesc/util/XMLEnumerator.hpp>
|
---|
| 114 | #include <xercesc/util/PlatformUtils.hpp>
|
---|
| 115 | #include <xercesc/framework/MemoryManager.hpp>
|
---|
| 116 |
|
---|
| 117 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
| 118 |
|
---|
| 119 | template <class TElem> class ValueVectorOf : public XMemory
|
---|
| 120 | {
|
---|
| 121 | public :
|
---|
| 122 | // -----------------------------------------------------------------------
|
---|
| 123 | // Constructors and Destructor
|
---|
| 124 | // -----------------------------------------------------------------------
|
---|
| 125 | ValueVectorOf
|
---|
| 126 | (
|
---|
| 127 | const unsigned int maxElems
|
---|
| 128 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
| 129 | , const bool toCallDestructor = false
|
---|
| 130 | );
|
---|
| 131 | ValueVectorOf(const ValueVectorOf<TElem>& toCopy);
|
---|
| 132 | ~ValueVectorOf();
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | // -----------------------------------------------------------------------
|
---|
| 136 | // Operators
|
---|
| 137 | // -----------------------------------------------------------------------
|
---|
| 138 | ValueVectorOf<TElem>& operator=(const ValueVectorOf<TElem>& toAssign);
|
---|
| 139 |
|
---|
| 140 |
|
---|
| 141 | // -----------------------------------------------------------------------
|
---|
| 142 | // Element management
|
---|
| 143 | // -----------------------------------------------------------------------
|
---|
| 144 | void addElement(const TElem& toAdd);
|
---|
| 145 | void setElementAt(const TElem& toSet, const unsigned int setAt);
|
---|
| 146 | void insertElementAt(const TElem& toInsert, const unsigned int insertAt);
|
---|
| 147 | void removeElementAt(const unsigned int removeAt);
|
---|
| 148 | void removeAllElements();
|
---|
| 149 | bool containsElement(const TElem& toCheck, const unsigned int startIndex = 0);
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | // -----------------------------------------------------------------------
|
---|
| 153 | // Getter methods
|
---|
| 154 | // -----------------------------------------------------------------------
|
---|
| 155 | const TElem& elementAt(const unsigned int getAt) const;
|
---|
| 156 | TElem& elementAt(const unsigned int getAt);
|
---|
| 157 | unsigned int curCapacity() const;
|
---|
| 158 | unsigned int size() const;
|
---|
| 159 | MemoryManager* getMemoryManager() const;
|
---|
| 160 |
|
---|
| 161 |
|
---|
| 162 | // -----------------------------------------------------------------------
|
---|
| 163 | // Miscellaneous
|
---|
| 164 | // -----------------------------------------------------------------------
|
---|
| 165 | void ensureExtraCapacity(const unsigned int length);
|
---|
| 166 | const TElem* rawData() const;
|
---|
| 167 |
|
---|
| 168 |
|
---|
| 169 | private:
|
---|
| 170 | // -----------------------------------------------------------------------
|
---|
| 171 | // Data members
|
---|
| 172 | //
|
---|
| 173 | // fCurCount
|
---|
| 174 | // The count of values current added to the vector, which may be
|
---|
| 175 | // less than the internal capacity.
|
---|
| 176 | //
|
---|
| 177 | // fMaxCount
|
---|
| 178 | // The current capacity of the vector.
|
---|
| 179 | //
|
---|
| 180 | // fElemList
|
---|
| 181 | // The list of elements, which is dynamically allocated to the needed
|
---|
| 182 | // size.
|
---|
| 183 | // -----------------------------------------------------------------------
|
---|
| 184 | bool fCallDestructor;
|
---|
| 185 | unsigned int fCurCount;
|
---|
| 186 | unsigned int fMaxCount;
|
---|
| 187 | TElem* fElemList;
|
---|
| 188 | MemoryManager* fMemoryManager;
|
---|
| 189 | };
|
---|
| 190 |
|
---|
| 191 |
|
---|
| 192 | //
|
---|
| 193 | // An enumerator for a value vector. It derives from the basic enumerator
|
---|
| 194 | // class, so that value vectors can be generically enumerated.
|
---|
| 195 | //
|
---|
| 196 | template <class TElem> class ValueVectorEnumerator : public XMLEnumerator<TElem>, public XMemory
|
---|
| 197 | {
|
---|
| 198 | public :
|
---|
| 199 | // -----------------------------------------------------------------------
|
---|
| 200 | // Constructors and Destructor
|
---|
| 201 | // -----------------------------------------------------------------------
|
---|
| 202 | ValueVectorEnumerator
|
---|
| 203 | (
|
---|
| 204 | ValueVectorOf<TElem>* const toEnum
|
---|
| 205 | , const bool adopt = false
|
---|
| 206 | );
|
---|
| 207 | virtual ~ValueVectorEnumerator();
|
---|
| 208 |
|
---|
| 209 |
|
---|
| 210 | // -----------------------------------------------------------------------
|
---|
| 211 | // Enum interface
|
---|
| 212 | // -----------------------------------------------------------------------
|
---|
| 213 | bool hasMoreElements() const;
|
---|
| 214 | TElem& nextElement();
|
---|
| 215 | void Reset();
|
---|
| 216 |
|
---|
| 217 |
|
---|
| 218 | private :
|
---|
| 219 | // -----------------------------------------------------------------------
|
---|
| 220 | // Unimplemented constructors and operators
|
---|
| 221 | // -----------------------------------------------------------------------
|
---|
| 222 | ValueVectorEnumerator(const ValueVectorEnumerator<TElem>&);
|
---|
| 223 | ValueVectorEnumerator<TElem>& operator=(const ValueVectorEnumerator<TElem>&);
|
---|
| 224 |
|
---|
| 225 | // -----------------------------------------------------------------------
|
---|
| 226 | // Data Members
|
---|
| 227 | //
|
---|
| 228 | // fAdopted
|
---|
| 229 | // Indicates whether we have adopted the passed vector. If so then
|
---|
| 230 | // we delete the vector when we are destroyed.
|
---|
| 231 | //
|
---|
| 232 | // fCurIndex
|
---|
| 233 | // This is the current index into the vector.
|
---|
| 234 | //
|
---|
| 235 | // fToEnum
|
---|
| 236 | // The value vector being enumerated.
|
---|
| 237 | // -----------------------------------------------------------------------
|
---|
| 238 | bool fAdopted;
|
---|
| 239 | unsigned int fCurIndex;
|
---|
| 240 | ValueVectorOf<TElem>* fToEnum;
|
---|
| 241 | };
|
---|
| 242 |
|
---|
| 243 | XERCES_CPP_NAMESPACE_END
|
---|
| 244 |
|
---|
| 245 | #if !defined(XERCES_TMPLSINC)
|
---|
| 246 | #include <xercesc/util/ValueVectorOf.c>
|
---|
| 247 | #endif
|
---|
| 248 |
|
---|
| 249 | #endif
|
---|