1 // Created on: 2012-11-13
2 // Created by: Peter KURNEV
3 // Copyright (c) 2012-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef IntPolyh_Array_HeaderFile
17 #define IntPolyh_Array_HeaderFile
19 #include <NCollection_Vector.hxx>
23 * Class IntPolyh_Array (dynamic array of objects)
25 * 1. The Array is dynamic array of objects.
27 * 2. The Array uses NCollection_Vector to store objects
29 * 3. The Array can be created:
30 * 3.1. with initial length Nb=0.
31 * In this case Array should be initiated by invoke
32 * the method Init(Nb).
33 * 3.2. with initial length Nb>0.
34 * In this case Array is initiated automatically.
36 * The memory is allocated to store myNbAllocated oblects.
38 * 4. The number of items that are stored in the Array (myNbItems)
39 * can be increased by calling the method: IncrementNbItems().
40 * The objects are stored in already allocated memory if it is
42 * Otherwise the new chunk of memory is allocated to store the
44 * The size of chunk <aIncrement> can be defined during the creation
47 * 5. The start index of the Array is 0, The end index of the Array
48 * can be obtained by the method NbItems();
50 * 6. The contents of the element with index "i" can be queried or
51 * modified by the methods: Value(i), ChangeValue(i), operator[](i)
54 //=======================================================================
55 // class : IntPolyh_Array
57 //=======================================================================
58 template <class Type> class IntPolyh_Array {
60 typedef NCollection_Vector <Type> IntPolyh_VectorOfType;
65 * size of memory (in terms of Items) to expand the array
67 IntPolyh_Array(const Standard_Integer aIncrement=256) {
70 myIncrement=aIncrement;
76 * size of memory (in terms of Items) to allocate
78 * size of memory (in terms of Items) to expand the array
80 IntPolyh_Array(const Standard_Integer aN,
81 const Standard_Integer aIncrement=256) {
83 myIncrement=aIncrement;
90 * aOther - the array to copy from
94 IntPolyh_Array& operator =(const IntPolyh_Array& aOther) {
101 * aOther - the array to copy from
105 IntPolyh_Array& Copy(const IntPolyh_Array& aOther) {
106 myVectorOfType.Clear();
107 Init(aOther.myNbAllocated);
108 myVectorOfType=aOther.myVectorOfType;
109 myNbItems=aOther.myNbItems;
115 * Init - allocate memory for <aN> items
117 * aN - the number of items to allocate the memory
119 void Init(const Standard_Integer aN) {
122 myVectorOfType.SetValue(aN, aSL);
127 * IncrementNbItems - increment the number of stored items
129 void IncrementNbItems() {
131 if (myNbItems>=myNbAllocated) {
134 aN=myNbAllocated+myIncrement;
140 * GetN - returns the number of 'allocated' items
142 * the number of 'allocated' items
144 Standard_Integer GetN() const {
145 return myNbAllocated;
149 * NbItems - returns the number of stored items
151 * the number of stored items
153 Standard_Integer NbItems() const {
159 * set the number of stored items
161 * the number of stored items
163 void SetNbItems(const Standard_Integer aNb){
168 * query the const value
174 const Type& Value(const Standard_Integer aIndex) const {
175 return myVectorOfType.Value(aIndex);
179 * query the const value
185 const Type& operator [](const Standard_Integer aIndex) const {
186 return Value(aIndex);
196 Type& ChangeValue(const Standard_Integer aIndex) {
197 return myVectorOfType.ChangeValue(aIndex);
207 Type& operator [](const Standard_Integer aIndex) {
208 return ChangeValue(aIndex);
215 printf("\n ArrayOfSectionLines 0-> %d",myNbItems-1);
216 for(Standard_Integer i=0;i<myNbItems;i++) {
223 Standard_Integer myNbAllocated;
224 Standard_Integer myNbItems;
225 Standard_Integer myIncrement;
226 IntPolyh_VectorOfType myVectorOfType;