ValueVectorOf.hpp
上传用户:huihehuasu
上传日期:2007-01-10
资源大小:6948k
文件大小:7k
源码类别:

xml/soap/webservice

开发平台:

C/C++

  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.  * $Log: ValueVectorOf.hpp,v $
  58.  * Revision 1.5  2001/08/09 15:24:37  knoaman
  59.  * add support for <anyAttribute> declaration.
  60.  *
  61.  * Revision 1.4  2000/03/02 19:54:47  roddey
  62.  * This checkin includes many changes done while waiting for the
  63.  * 1.1.0 code to be finished. I can't list them all here, but a list is
  64.  * available elsewhere.
  65.  *
  66.  * Revision 1.3  2000/02/24 20:05:26  abagchi
  67.  * Swat for removing Log from API docs
  68.  *
  69.  * Revision 1.2  2000/02/06 07:48:05  rahulj
  70.  * Year 2K copyright swat.
  71.  *
  72.  * Revision 1.1.1.1  1999/11/09 01:05:33  twl
  73.  * Initial checkin
  74.  *
  75.  * Revision 1.2  1999/11/08 20:45:19  rahul
  76.  * Swat for adding in Product name and CVS comment log variable.
  77.  *
  78.  */
  79. #if !defined(VALUEVECTOROF_HPP)
  80. #define VALUEVECTOROF_HPP
  81. #include <util/XercesDefs.hpp>
  82. #include <util/ArrayIndexOutOfBoundsException.hpp>
  83. #include <util/XMLEnumerator.hpp>
  84. template <class TElem> class ValueVectorOf
  85. {
  86. public :
  87.     // -----------------------------------------------------------------------
  88.     //  Constructors and Destructor
  89.     // -----------------------------------------------------------------------
  90.     ValueVectorOf(const unsigned int maxElems);
  91.     ValueVectorOf(const ValueVectorOf<TElem>& toCopy);
  92.     ~ValueVectorOf();
  93.     // -----------------------------------------------------------------------
  94.     //  Operators
  95.     // -----------------------------------------------------------------------
  96.     ValueVectorOf<TElem>& operator=(const ValueVectorOf<TElem>& toAssign);
  97.     
  98.     // -----------------------------------------------------------------------
  99.     //  Element management
  100.     // -----------------------------------------------------------------------
  101.     void addElement(const TElem& toAdd);
  102.     void setElementAt(const TElem& toSet, const unsigned int setAt);
  103.     void insertElementAt(const TElem& toInsert, const unsigned int insertAt);
  104.     void removeElementAt(const unsigned int removeAt);
  105.     void removeAllElements();
  106.     bool containsElement(const TElem& toCheck);
  107.     // -----------------------------------------------------------------------
  108.     //  Getter methods
  109.     // -----------------------------------------------------------------------
  110.     const TElem& elementAt(const unsigned int getAt) const;
  111.     TElem& elementAt(const unsigned int getAt);
  112.     unsigned int curCapacity() const;
  113.     unsigned int size() const;
  114.     // -----------------------------------------------------------------------
  115.     //  Miscellaneous
  116.     // -----------------------------------------------------------------------
  117.     void ensureExtraCapacity(const unsigned int length);
  118.     const TElem* rawData() const;
  119. private:
  120.     // -----------------------------------------------------------------------
  121.     //  Data members
  122.     //
  123.     //  fCurCount
  124.     //      The count of values current added to the vector, which may be
  125.     //      less than the internal capacity.
  126.     //
  127.     //  fMaxCount
  128.     //      The current capacity of the vector.
  129.     //
  130.     //  fElemList
  131.     //      The list of elements, which is dynamically allocated to the needed
  132.     //      size.
  133.     // -----------------------------------------------------------------------
  134.     unsigned int    fCurCount;
  135.     unsigned int    fMaxCount;
  136.     TElem*          fElemList;
  137. };
  138. //
  139. //  An enumerator for a value vector. It derives from the basic enumerator
  140. //  class, so that value vectors can be generically enumerated.
  141. //
  142. template <class TElem> class ValueVectorEnumerator : public XMLEnumerator<TElem>
  143. {
  144. public :
  145.     // -----------------------------------------------------------------------
  146.     //  Constructors and Destructor
  147.     // -----------------------------------------------------------------------
  148.     ValueVectorEnumerator
  149.     (
  150.                 ValueVectorOf<TElem>* const toEnum
  151.         , const bool                        adopt = false
  152.     );
  153.     ~ValueVectorEnumerator();
  154.     // -----------------------------------------------------------------------
  155.     //  Enum interface
  156.     // -----------------------------------------------------------------------
  157.     bool hasMoreElements() const;
  158.     TElem& nextElement();
  159.     void Reset();
  160. private :    
  161.     // -----------------------------------------------------------------------
  162.     //  Data Members
  163.     //
  164.     //  fAdopted
  165.     //      Indicates whether we have adopted the passed vector. If so then
  166.     //      we delete the vector when we are destroyed.
  167.     //
  168.     //  fCurIndex
  169.     //      This is the current index into the vector.
  170.     //
  171.     //  fToEnum
  172.     //      The value vector being enumerated.
  173.     // -----------------------------------------------------------------------
  174.     bool                    fAdopted;
  175.     unsigned int            fCurIndex;
  176.     ValueVectorOf<TElem>*   fToEnum;
  177. };
  178. #if !defined(XERCES_TMPLSINC)
  179. #include <util/ValueVectorOf.c>
  180. #endif
  181. #endif