Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:14

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  * 
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  * 
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_VALUEVECTOROF_HPP)
0023 #define XERCESC_INCLUDE_GUARD_VALUEVECTOROF_HPP
0024 
0025 #include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
0026 #include <xercesc/util/XMLEnumerator.hpp>
0027 #include <xercesc/util/PlatformUtils.hpp>
0028 #include <xercesc/framework/MemoryManager.hpp>
0029 
0030 XERCES_CPP_NAMESPACE_BEGIN
0031 
0032 template <class TElem> class ValueVectorOf : public XMemory
0033 {
0034 public :
0035     // -----------------------------------------------------------------------
0036     //  Constructors and Destructor
0037     // -----------------------------------------------------------------------
0038     ValueVectorOf
0039     (
0040         const XMLSize_t maxElems
0041         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
0042         , const bool toCallDestructor = false
0043     );
0044     ValueVectorOf(const ValueVectorOf<TElem>& toCopy);
0045     ~ValueVectorOf();
0046 
0047 
0048     // -----------------------------------------------------------------------
0049     //  Operators
0050     // -----------------------------------------------------------------------
0051     ValueVectorOf<TElem>& operator=(const ValueVectorOf<TElem>& toAssign);
0052 
0053 
0054     // -----------------------------------------------------------------------
0055     //  Element management
0056     // -----------------------------------------------------------------------
0057     void addElement(const TElem& toAdd);
0058     void setElementAt(const TElem& toSet, const XMLSize_t setAt);
0059     void insertElementAt(const TElem& toInsert, const XMLSize_t insertAt);
0060     void removeElementAt(const XMLSize_t removeAt);
0061     void removeAllElements();
0062     bool containsElement(const TElem& toCheck, const XMLSize_t startIndex = 0);
0063 
0064 
0065     // -----------------------------------------------------------------------
0066     //  Getter methods
0067     // -----------------------------------------------------------------------
0068     const TElem& elementAt(const XMLSize_t getAt) const;
0069     TElem& elementAt(const XMLSize_t getAt);
0070     XMLSize_t curCapacity() const;
0071     XMLSize_t size() const;
0072     MemoryManager* getMemoryManager() const;
0073 
0074 
0075     // -----------------------------------------------------------------------
0076     //  Miscellaneous
0077     // -----------------------------------------------------------------------
0078     void ensureExtraCapacity(const XMLSize_t length);
0079     const TElem* rawData() const;
0080 
0081 
0082 private:
0083     // -----------------------------------------------------------------------
0084     //  Data members
0085     //
0086     //  fCurCount
0087     //      The count of values current added to the vector, which may be
0088     //      less than the internal capacity.
0089     //
0090     //  fMaxCount
0091     //      The current capacity of the vector.
0092     //
0093     //  fElemList
0094     //      The list of elements, which is dynamically allocated to the needed
0095     //      size.
0096     // -----------------------------------------------------------------------
0097     bool            fCallDestructor;
0098     XMLSize_t       fCurCount;
0099     XMLSize_t       fMaxCount;
0100     TElem*          fElemList;
0101     MemoryManager*  fMemoryManager;
0102 };
0103 
0104 
0105 //
0106 //  An enumerator for a value vector. It derives from the basic enumerator
0107 //  class, so that value vectors can be generically enumerated.
0108 //
0109 template <class TElem> class ValueVectorEnumerator : public XMLEnumerator<TElem>, public XMemory
0110 {
0111 public :
0112     // -----------------------------------------------------------------------
0113     //  Constructors and Destructor
0114     // -----------------------------------------------------------------------
0115     ValueVectorEnumerator
0116     (
0117                 ValueVectorOf<TElem>* const toEnum
0118         , const bool                        adopt = false
0119     );
0120     virtual ~ValueVectorEnumerator();
0121 
0122 
0123     // -----------------------------------------------------------------------
0124     //  Enum interface
0125     // -----------------------------------------------------------------------
0126     bool hasMoreElements() const;
0127     TElem& nextElement();
0128     void Reset();
0129 
0130 
0131 private :
0132     // -----------------------------------------------------------------------
0133     //  Unimplemented constructors and operators
0134     // -----------------------------------------------------------------------    
0135     ValueVectorEnumerator(const ValueVectorEnumerator<TElem>&);
0136     ValueVectorEnumerator<TElem>& operator=(const ValueVectorEnumerator<TElem>&);
0137 
0138     // -----------------------------------------------------------------------
0139     //  Data Members
0140     //
0141     //  fAdopted
0142     //      Indicates whether we have adopted the passed vector. If so then
0143     //      we delete the vector when we are destroyed.
0144     //
0145     //  fCurIndex
0146     //      This is the current index into the vector.
0147     //
0148     //  fToEnum
0149     //      The value vector being enumerated.
0150     // -----------------------------------------------------------------------
0151     bool                    fAdopted;
0152     XMLSize_t               fCurIndex;
0153     ValueVectorOf<TElem>*   fToEnum;
0154 };
0155 
0156 XERCES_CPP_NAMESPACE_END
0157 
0158 #if !defined(XERCES_TMPLSINC)
0159 #include <xercesc/util/ValueVectorOf.c>
0160 #endif
0161 
0162 #endif