Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-27 09:18:12

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_DynamicArray.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_DynamicArray 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>
0059 class IntPolyh_Array
0060 {
0061 public:
0062   typedef NCollection_DynamicArray<Type> IntPolyh_VectorOfType;
0063 
0064   /**
0065    * Constructor.
0066    * @param aIncrement
0067    *   size of memory (in terms of Items) to expand the array
0068    */
0069   IntPolyh_Array(const int aIncrement = 256)
0070   {
0071     myNbAllocated = 0;
0072     myNbItems     = 0;
0073     myIncrement   = aIncrement;
0074   }
0075 
0076   /**
0077    * Constructor.
0078    * @param aN
0079    *   size of memory (in terms of Items) to allocate
0080    * @param aIncrement
0081    *   size of memory (in terms of Items) to expand the array
0082    */
0083   IntPolyh_Array(const int aN, const int aIncrement = 256)
0084   {
0085     myNbItems   = 0;
0086     myIncrement = aIncrement;
0087     Init(aN);
0088   }
0089 
0090   /**
0091    * Assignment operator
0092    * @param
0093    *   aOther - the array to copy from
0094    * @return
0095    *   the array
0096    */
0097   IntPolyh_Array& operator=(const IntPolyh_Array& aOther) { return Copy(aOther); }
0098 
0099   /**
0100    * Copy
0101    * @param
0102    *   aOther - the array to copy from
0103    * @return
0104    *   the array
0105    */
0106   IntPolyh_Array& Copy(const IntPolyh_Array& aOther)
0107   {
0108     myVectorOfType.Clear();
0109     Init(aOther.myNbAllocated);
0110     myVectorOfType = aOther.myVectorOfType;
0111     myNbItems      = aOther.myNbItems;
0112     //
0113     return *this;
0114   }
0115 
0116   /**
0117    * Init - allocate memory for <aN> items
0118    * @param
0119    *   aN - the number of items to allocate the memory
0120    */
0121   void Init(const int aN)
0122   {
0123     Type aSL;
0124     //
0125     myVectorOfType.SetValue(aN, aSL);
0126     myNbAllocated = aN;
0127   }
0128 
0129   /**
0130    * IncrementNbItems - increment the number of stored items
0131    */
0132   void IncrementNbItems()
0133   {
0134     myNbItems++;
0135     if (myNbItems >= myNbAllocated)
0136     {
0137       int aN;
0138       //
0139       aN = myNbAllocated + myIncrement;
0140       Init(aN);
0141     }
0142   }
0143 
0144   /**
0145    * GetN - returns the number of 'allocated' items
0146    * @return
0147    *   the number of 'allocated' items
0148    */
0149   int GetN() const { return myNbAllocated; }
0150 
0151   /**
0152    * NbItems - returns the number of stored items
0153    * @return
0154    *   the number of stored items
0155    */
0156   int NbItems() const { return myNbItems; }
0157 
0158   /**
0159    * set the number of stored items
0160    * @param aNb
0161    *   the number of stored items
0162    */
0163   void SetNbItems(const int aNb) { myNbItems = aNb; }
0164 
0165   /**
0166    * query the const value
0167    * @param aIndex
0168    *   index
0169    * @return
0170    *   the const item
0171    */
0172   const Type& Value(const int aIndex) const { return myVectorOfType.Value(aIndex); }
0173 
0174   /**
0175    * query the const value
0176    * @param aIndex
0177    *   index
0178    * @return
0179    *   the const item
0180    */
0181   const Type& operator[](const int aIndex) const { return Value(aIndex); }
0182 
0183   /**
0184    * query the value
0185    * @param aIndex
0186    *   index
0187    * @return
0188    *   the item
0189    */
0190   Type& ChangeValue(const int aIndex) { return myVectorOfType.ChangeValue(aIndex); }
0191 
0192   /**
0193    * query the value
0194    * @param aIndex
0195    *   index
0196    * @return
0197    *   the item
0198    */
0199   Type& operator[](const int aIndex) { return ChangeValue(aIndex); }
0200 
0201   /**
0202    * dump the contents
0203    */
0204   void Dump() const
0205   {
0206     printf("\n ArrayOfSectionLines 0-> %d", myNbItems - 1);
0207     for (int i = 0; i < myNbItems; i++)
0208     {
0209       (*this)[i].Dump();
0210     }
0211     printf("\n");
0212   }
0213 
0214 protected:
0215   int                   myNbAllocated;
0216   int                   myNbItems;
0217   int                   myIncrement;
0218   IntPolyh_VectorOfType myVectorOfType;
0219 };
0220 
0221 #endif