summaryrefslogtreecommitdiff
path: root/inc/TCollection_Array1.gxx
blob: 8efa2aa2fdf63abbb22ca55f3c08b89b6b6db1d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <Standard_DimensionMismatch.hxx>
#include <Standard_RangeError.hxx>
#include <Standard_OutOfMemory.hxx>
#include <Standard.hxx>

// ###### REFERENCER LE STORAGE MANAGER DES COLLECTIONS ######

//=======================================================================
//function : TCollection_Array1
//purpose  : 
//=======================================================================

TCollection_Array1::TCollection_Array1 (const Standard_Integer Low,
					const Standard_Integer Up) :
       myLowerBound(Low),
       myUpperBound(Up),
       isAllocated(Standard_True)
{
  Standard_RangeError_Raise_if(Up < Low,"TCollection_Array1::Create");

  Array1Item* p = 0;
#ifdef __OPTIM_ARRAY
  //  p = new char [(Up-Low+1)*sizeof (Array1Item)];
  p =  (Array1Item *)Standard::Allocate((Up-Low+1)*sizeof (Array1Item));
#else
  p = new Array1Item[Up-Low+1];
#endif

  if (!p) Standard_OutOfMemory::Raise("Array1 : Allocation failed");
  myStart = (void*)(p - myLowerBound);
}



//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

void TCollection_Array1::Init (const Array1Item& V) {
  Array1Item* p = &ChangeValue(myLowerBound);
  Standard_Integer i;
  for(i = myLowerBound; i <= myUpperBound; i++) {
    *p++ = V;
  }
}

//=======================================================================
//function : TCollection_Array1
//purpose  : C Array constructor
//=======================================================================

TCollection_Array1::TCollection_Array1(const Array1Item& AnItem,
				       const Standard_Integer Low,
				       const Standard_Integer Up) :
       myLowerBound(Low),
       myUpperBound(Up),
       isAllocated(Standard_False)
{

  Standard_RangeError_Raise_if(Up < Low,"Array1::CArray");
  myStart = (void*)( &AnItem - Low ); 
}

//=======================================================================
//function : Destroy
//purpose  : 
//=======================================================================

void TCollection_Array1::Destroy() 
{
  if (isAllocated) {
#ifdef __OPTIM_ARRAY
    Standard_Address it = (Standard_Address)&((Array1Item *)myStart)[myLowerBound];
    Standard::Free(it);
#else
    delete [] &ChangeValue(myLowerBound);
#endif
  }
}

//=======================================================================
//function : Assign
//purpose  : 
//=======================================================================

const TCollection_Array1& TCollection_Array1::Assign 
  (const TCollection_Array1& Right)
{
  if (&Right != this) {
    Standard_Integer max = Length() ;
    Standard_DimensionMismatch_Raise_if(max != Right.Length(),
					"DimensionMismatch in Array1::Operator=");
    
    Array1Item* p       = &ChangeValue(myLowerBound);
    const Array1Item* q = &Right.Value(Right.Lower());
    for (Standard_Integer i=0; i<max; i++){
      *p++ = *q++;
    }
  }
  return *this;
}