[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: ValueArrayOf.hpp,v $
|
---|
| 59 | * Revision 1.6 2004/01/29 11:48:46 cargilld
|
---|
| 60 | * Code cleanup changes to get rid of various compiler diagnostic messages.
|
---|
| 61 | *
|
---|
| 62 | * Revision 1.5 2003/05/16 06:01:52 knoaman
|
---|
| 63 | * Partial implementation of the configurable memory manager.
|
---|
| 64 | *
|
---|
| 65 | * Revision 1.4 2003/05/15 19:07:46 knoaman
|
---|
| 66 | * Partial implementation of the configurable memory manager.
|
---|
| 67 | *
|
---|
| 68 | * Revision 1.3 2002/11/04 15:22:05 tng
|
---|
| 69 | * C++ Namespace Support.
|
---|
| 70 | *
|
---|
| 71 | * Revision 1.2 2002/08/21 17:45:00 tng
|
---|
| 72 | * [Bug 7087] compiler warnings when using gcc.
|
---|
| 73 | *
|
---|
| 74 | * Revision 1.1.1.1 2002/02/01 22:22:13 peiyongz
|
---|
| 75 | * sane_include
|
---|
| 76 | *
|
---|
| 77 | * Revision 1.4 2000/03/02 19:54:47 roddey
|
---|
| 78 | * This checkin includes many changes done while waiting for the
|
---|
| 79 | * 1.1.0 code to be finished. I can't list them all here, but a list is
|
---|
| 80 | * available elsewhere.
|
---|
| 81 | *
|
---|
| 82 | * Revision 1.3 2000/02/24 20:05:26 abagchi
|
---|
| 83 | * Swat for removing Log from API docs
|
---|
| 84 | *
|
---|
| 85 | * Revision 1.2 2000/02/06 07:48:05 rahulj
|
---|
| 86 | * Year 2K copyright swat.
|
---|
| 87 | *
|
---|
| 88 | * Revision 1.1.1.1 1999/11/09 01:05:27 twl
|
---|
| 89 | * Initial checkin
|
---|
| 90 | *
|
---|
| 91 | * Revision 1.2 1999/11/08 20:45:18 rahul
|
---|
| 92 | * Swat for adding in Product name and CVS comment log variable.
|
---|
| 93 | *
|
---|
| 94 | */
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | #if !defined(VALUEARRAY_HPP)
|
---|
| 98 | #define VALUEARRAY_HPP
|
---|
| 99 |
|
---|
| 100 | #include <xercesc/util/XMLEnumerator.hpp>
|
---|
| 101 | #include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
|
---|
| 102 | #include <xercesc/util/IllegalArgumentException.hpp>
|
---|
| 103 | #include <xercesc/util/PlatformUtils.hpp>
|
---|
| 104 | #include <xercesc/framework/MemoryManager.hpp>
|
---|
| 105 |
|
---|
| 106 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
| 107 |
|
---|
| 108 | template <class TElem> class ValueArrayOf : public XMemory
|
---|
| 109 | {
|
---|
| 110 | public :
|
---|
| 111 | // -----------------------------------------------------------------------
|
---|
| 112 | // Contructors and Destructor
|
---|
| 113 | // -----------------------------------------------------------------------
|
---|
| 114 | ValueArrayOf
|
---|
| 115 | (
|
---|
| 116 | const unsigned int size
|
---|
| 117 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
| 118 | );
|
---|
| 119 | ValueArrayOf
|
---|
| 120 | (
|
---|
| 121 | const TElem* values
|
---|
| 122 | , const unsigned int size
|
---|
| 123 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
| 124 | );
|
---|
| 125 | ValueArrayOf(const ValueArrayOf<TElem>& source);
|
---|
| 126 | ~ValueArrayOf();
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 | // -----------------------------------------------------------------------
|
---|
| 130 | // Public operators
|
---|
| 131 | // -----------------------------------------------------------------------
|
---|
| 132 | TElem& operator[](const unsigned int index);
|
---|
| 133 | const TElem& operator[](const unsigned int index) const;
|
---|
| 134 | ValueArrayOf<TElem>& operator=(const ValueArrayOf<TElem>& toAssign);
|
---|
| 135 | bool operator==(const ValueArrayOf<TElem>& toCompare) const;
|
---|
| 136 | bool operator!=(const ValueArrayOf<TElem>& toCompare) const;
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 | // -----------------------------------------------------------------------
|
---|
| 140 | // Copy operations
|
---|
| 141 | // -----------------------------------------------------------------------
|
---|
| 142 | unsigned int copyFrom(const ValueArrayOf<TElem>& srcArray);
|
---|
| 143 |
|
---|
| 144 |
|
---|
| 145 | // -----------------------------------------------------------------------
|
---|
| 146 | // Getter methods
|
---|
| 147 | // -----------------------------------------------------------------------
|
---|
| 148 | unsigned int length() const;
|
---|
| 149 | TElem* rawData() const;
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | // -----------------------------------------------------------------------
|
---|
| 153 | // Miscellaneous methods
|
---|
| 154 | // -----------------------------------------------------------------------
|
---|
| 155 | void resize(const unsigned int newSize);
|
---|
| 156 |
|
---|
| 157 |
|
---|
| 158 | private :
|
---|
| 159 | // -----------------------------------------------------------------------
|
---|
| 160 | // Data members
|
---|
| 161 | // -----------------------------------------------------------------------
|
---|
| 162 | unsigned int fSize;
|
---|
| 163 | TElem* fArray;
|
---|
| 164 | MemoryManager* fMemoryManager;
|
---|
| 165 | };
|
---|
| 166 |
|
---|
| 167 |
|
---|
| 168 | //
|
---|
| 169 | // An enumerator for a value array. It derives from the basic enumerator
|
---|
| 170 | // class, so that value vectors can be generically enumerated.
|
---|
| 171 | //
|
---|
| 172 | template <class TElem> class ValueArrayEnumerator : public XMLEnumerator<TElem>, public XMemory
|
---|
| 173 | {
|
---|
| 174 | public :
|
---|
| 175 | // -----------------------------------------------------------------------
|
---|
| 176 | // Constructors and Destructor
|
---|
| 177 | // -----------------------------------------------------------------------
|
---|
| 178 | ValueArrayEnumerator
|
---|
| 179 | (
|
---|
| 180 | ValueArrayOf<TElem>* const toEnum
|
---|
| 181 | , const bool adopt = false
|
---|
| 182 | );
|
---|
| 183 | virtual ~ValueArrayEnumerator();
|
---|
| 184 |
|
---|
| 185 |
|
---|
| 186 | // -----------------------------------------------------------------------
|
---|
| 187 | // Enum interface
|
---|
| 188 | // -----------------------------------------------------------------------
|
---|
| 189 | bool hasMoreElements() const;
|
---|
| 190 | TElem& nextElement();
|
---|
| 191 | void Reset();
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | private :
|
---|
| 195 | // -----------------------------------------------------------------------
|
---|
| 196 | // Unimplemented constructors and operators
|
---|
| 197 | // -----------------------------------------------------------------------
|
---|
| 198 | ValueArrayEnumerator(const ValueArrayEnumerator<TElem>&);
|
---|
| 199 | ValueArrayEnumerator<TElem>& operator=(const ValueArrayEnumerator<TElem>&);
|
---|
| 200 |
|
---|
| 201 | // -----------------------------------------------------------------------
|
---|
| 202 | // Data Members
|
---|
| 203 | //
|
---|
| 204 | // fAdopted
|
---|
| 205 | // Indicates whether we have adopted the passed vector. If so then
|
---|
| 206 | // we delete the vector when we are destroyed.
|
---|
| 207 | //
|
---|
| 208 | // fCurIndex
|
---|
| 209 | // This is the current index into the vector.
|
---|
| 210 | //
|
---|
| 211 | // fToEnum
|
---|
| 212 | // The value array being enumerated.
|
---|
| 213 | // -----------------------------------------------------------------------
|
---|
| 214 | bool fAdopted;
|
---|
| 215 | unsigned int fCurIndex;
|
---|
| 216 | ValueArrayOf<TElem>* fToEnum;
|
---|
| 217 | };
|
---|
| 218 |
|
---|
| 219 | XERCES_CPP_NAMESPACE_END
|
---|
| 220 |
|
---|
| 221 | #if !defined(XERCES_TMPLSINC)
|
---|
| 222 | #include <xercesc/util/ValueArrayOf.c>
|
---|
| 223 | #endif
|
---|
| 224 |
|
---|
| 225 | #endif
|
---|