Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:10

0001 // Created on: 2012-11-13
0002 // Created by: Peter KURNEV
0003 // Copyright (c) 2012-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef IntPolyh_Array_HeaderFile
0017 #define IntPolyh_Array_HeaderFile
0018 
0019 #include <NCollection_Vector.hxx>
0020 #include <stdio.h>
0021 
0022 /**
0023 * Class IntPolyh_Array (dynamic array of objects)
0024 *
0025 *   1. The Array is dynamic array of objects.
0026 *
0027 *   2. The Array uses NCollection_Vector to store objects
0028 *
0029 *   3. The Array can be created:
0030 *      3.1.  with initial length Nb=0. 
0031 *            In this case Array should be initiated by invoke 
0032 *            the method Init(Nb).
0033 *      3.2.  with initial length Nb>0.
0034 *            In this case Array is initiated automatically.
0035 * 
0036 *      The memory is allocated to store myNbAllocated oblects.
0037 *
0038 *   4. The number of items that are stored in the Array (myNbItems)
0039 *      can be increased by calling the method:  IncrementNbItems().
0040 *      The objects are stored in already allocated memory if it is 
0041 *      possible.
0042 *      Otherwise the new chunk of memory is allocated to store the 
0043 *      objects.
0044 *      The size of chunk <aIncrement> can be defined during the creation
0045 *      of the Array.
0046 *      
0047 *   5. The start index of the Array is 0, The end index of the Array 
0048 *      can be obtained by the method  NbItems();
0049 
0050 *   6. The contents of the element with index "i" can be queried or 
0051 *      modified by the methods:  Value(i), ChangeValue(i), operator[](i)
0052 */
0053 
0054 //=======================================================================
0055 // class : IntPolyh_Array
0056 //
0057 //=======================================================================
0058 template <class Type> class IntPolyh_Array {
0059  public:
0060   typedef NCollection_Vector <Type> IntPolyh_VectorOfType;
0061   
0062   /**
0063    * Constructor.
0064    * @param aIncrement
0065    *   size of memory (in terms of Items) to expand the array
0066    */
0067   IntPolyh_Array(const Standard_Integer aIncrement=256) {
0068     myNbAllocated=0;
0069     myNbItems=0;
0070     myIncrement=aIncrement;
0071   }
0072   
0073   /**
0074    * Constructor.
0075    * @param aN
0076    *   size of memory (in terms of Items) to allocate
0077    * @param aIncrement
0078    *   size of memory (in terms of Items) to expand the array
0079    */
0080   IntPolyh_Array(const Standard_Integer aN,
0081          const Standard_Integer aIncrement=256) {
0082     myNbItems=0;
0083     myIncrement=aIncrement;
0084     Init(aN);
0085   }
0086   
0087   /**
0088    * Assignment operator
0089    * @param
0090    *   aOther - the array to copy from 
0091    * @return
0092    *   the array
0093    */
0094   IntPolyh_Array& operator =(const IntPolyh_Array& aOther) {
0095     return Copy(aOther);
0096   }
0097 
0098   /**
0099    * Copy 
0100    * @param
0101    *   aOther - the array to copy from
0102    * @return
0103    *   the array 
0104    */
0105   IntPolyh_Array& Copy(const IntPolyh_Array& aOther) {
0106     myVectorOfType.Clear();
0107     Init(aOther.myNbAllocated);
0108     myVectorOfType=aOther.myVectorOfType;
0109     myNbItems=aOther.myNbItems; 
0110     //
0111     return *this;
0112   }
0113 
0114   /**
0115    * Init - allocate memory for <aN> items  
0116    * @param
0117    *   aN - the number of items to allocate the memory
0118    */
0119   void Init(const Standard_Integer aN) {
0120     Type aSL;
0121     //
0122     myVectorOfType.SetValue(aN, aSL);
0123     myNbAllocated=aN;
0124   }
0125 
0126   /**
0127    * IncrementNbItems - increment the number of stored items 
0128    */
0129   void IncrementNbItems() {
0130     myNbItems++; 
0131     if (myNbItems>=myNbAllocated) {
0132       Standard_Integer aN;
0133       //
0134       aN=myNbAllocated+myIncrement;
0135       Init(aN);
0136     }
0137   } 
0138 
0139   /**
0140    * GetN - returns the number of 'allocated' items  
0141    * @return
0142    *   the number of 'allocated' items 
0143    */
0144   Standard_Integer GetN() const { 
0145     return myNbAllocated; 
0146   }
0147 
0148   /**
0149    * NbItems - returns the number of stored items  
0150    * @return
0151    *   the number of stored items 
0152    */
0153   Standard_Integer NbItems() const { 
0154     return myNbItems; 
0155   }
0156   
0157 
0158   /**
0159    * set the number of stored items  
0160    * @param aNb
0161    *   the number of stored items 
0162    */
0163   void SetNbItems(const Standard_Integer aNb){ 
0164     myNbItems=aNb; 
0165   } 
0166 
0167   /**
0168    * query the const value
0169    * @param aIndex
0170    *   index 
0171    * @return
0172    *   the const item
0173    */
0174   const Type& Value(const Standard_Integer aIndex) const {
0175     return myVectorOfType.Value(aIndex);
0176   }
0177 
0178   /**
0179    * query the const value
0180    * @param aIndex
0181    *   index 
0182    * @return
0183    *   the const item
0184    */
0185   const Type& operator [](const Standard_Integer aIndex) const {
0186     return Value(aIndex);
0187   }
0188 
0189    /**
0190    * query the value
0191    * @param aIndex
0192    *   index 
0193    * @return
0194    *   the item
0195    */
0196   Type& ChangeValue(const Standard_Integer aIndex)  {
0197     return myVectorOfType.ChangeValue(aIndex);
0198   }
0199   
0200   /**
0201    * query the value
0202    * @param aIndex
0203    *   index 
0204    * @return
0205    *   the item
0206    */
0207   Type& operator [](const Standard_Integer aIndex)  {
0208     return ChangeValue(aIndex);
0209   }
0210 
0211   /**
0212    * dump the contents
0213    */
0214   void Dump() const   { 
0215     printf("\n ArrayOfSectionLines 0-> %d",myNbItems-1);
0216     for(Standard_Integer i=0;i<myNbItems;i++) { 
0217       (*this)[i].Dump();
0218     }
0219     printf("\n");
0220   }
0221 
0222  protected:
0223   Standard_Integer myNbAllocated;
0224   Standard_Integer myNbItems;
0225   Standard_Integer myIncrement;
0226   IntPolyh_VectorOfType myVectorOfType;
0227 };
0228 
0229 #endif