Salome HOME
update from the MedMemory V1.0.1
[modules/med.git] / src / MEDMEM / MEDMEM_SkyLineArray.hxx
1 # ifndef __MEDSKYLINEARRAY_H__
2 # define __MEDSKYLINEARRAY_H__
3
4 #include "MEDMEM_Exception.hxx"
5
6 #include "MEDMEM_PointerOf.hxx"
7 #include "MEDMEM_define.hxx"
8
9 using  MED_EN::med_int ;
10
11 class MEDSKYLINEARRAY
12 {
13 private :
14   med_int   _count ;
15   med_int   _length ;
16   PointerOf <med_int> _index ; // array of size _count+1 : _index[0]=1 and
17                                // _index[_count]=length+1
18   PointerOf <med_int> _value ; // array of size _length
19
20 public :
21   MEDSKYLINEARRAY();
22   ~MEDSKYLINEARRAY();
23   MEDSKYLINEARRAY( const MEDSKYLINEARRAY &myArray );
24   MEDSKYLINEARRAY( const med_int count, const med_int length );
25   MEDSKYLINEARRAY( const med_int count, const med_int length,
26                    const med_int* index, const med_int* value );
27
28   //void setMEDSKYLINEARRAY( const med_int count, const med_int length, med_int* index , med_int* value ) ;
29
30   inline med_int  getNumberOf()       const;
31   inline med_int  getLength()         const;
32   inline const med_int*  getIndex()   const;
33   inline const med_int*  getValue()   const;
34   inline med_int  getNumberOfI(int i) const throw (MEDEXCEPTION) ;
35   inline const med_int*  getI(int i)  const throw (MEDEXCEPTION) ;
36   inline med_int  getIJ(int i, int j) const throw (MEDEXCEPTION) ;
37   inline med_int  getIndexValue(int i) const throw (MEDEXCEPTION) ;
38
39   inline void setIndex(const med_int* index) ;
40   inline void setI(const med_int i, const med_int* values) throw (MEDEXCEPTION) ;
41   inline void setIJ(med_int i, med_int j, med_int value) throw (MEDEXCEPTION) ;
42   inline void setIndexValue(med_int i, med_int value) throw (MEDEXCEPTION) ;
43
44 } ;
45
46 // ---------------------------------------
47 //              Methodes Inline
48 // ---------------------------------------
49 inline med_int MEDSKYLINEARRAY::getNumberOf() const
50 {
51   return _count ;
52 };
53 inline med_int MEDSKYLINEARRAY::getLength() const
54 {
55   return _length ;
56 };
57 inline const med_int*  MEDSKYLINEARRAY::getIndex() const
58 {
59   return (const med_int*)_index ;
60 } ;
61 inline const med_int*  MEDSKYLINEARRAY::getValue() const
62 {
63   return (const med_int*)_value ;
64 } ;
65 inline med_int MEDSKYLINEARRAY::getNumberOfI(int i) const throw (MEDEXCEPTION)
66 {
67   if (i<1)
68     throw MEDEXCEPTION("MEDSKYLINEARRAY::getNumberOfI : argument must be >= 1");
69   if (i>_count)
70     throw MEDEXCEPTION("MEDSKYLINEARRAY::getNumberOfI : argument is out of range");
71   return _index[i]-_index[i-1] ;
72 } ;
73 inline const med_int* MEDSKYLINEARRAY::getI(int i) const throw (MEDEXCEPTION)
74 {
75     if (i<1)
76       throw MEDEXCEPTION("MEDSKYLINEARRAY::getI : argument must be >= 1");
77     if (i>_count)
78       throw MEDEXCEPTION("MEDSKYLINEARRAY::getI : argument is out of range");
79     return _value+_index[i-1]-1 ;
80 }
81 inline med_int MEDSKYLINEARRAY::getIJ(int i, int j) const throw (MEDEXCEPTION)
82 {
83     if (i<1)
84       throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : first argument must be >= 1");
85     if (j<1)
86       throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : second argument must be >= 1");
87     if (i>_count)
88       throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : first argument is out of range") ;
89     if (j>_index[i])
90       throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : second argument is out of range") ;
91     return _value[_index[i-1]+j-2] ;
92 }
93
94 inline med_int  MEDSKYLINEARRAY::getIndexValue(int i) const throw (MEDEXCEPTION)
95 {
96   if (i<1)
97     throw MEDEXCEPTION("MEDSKYLINEARRAY::getIndexValue : argument must be >= 1");
98   if (i>_index[_count])
99     throw MEDEXCEPTION("MEDSKYLINEARRAY::getIndexValue : argument is out of range") ;
100   return _value[i-1] ;
101 }
102
103 inline void MEDSKYLINEARRAY::setIndex(const med_int* index)
104 {
105   memcpy((med_int*)_index,index,(_count+1)*sizeof(med_int));
106 }
107
108
109 inline void MEDSKYLINEARRAY::setIJ(med_int i, med_int j, med_int value) throw (MEDEXCEPTION)
110 {
111   if (i<1)
112     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : first argument must be >= 1");
113   if (j<1)
114     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : second argument must be >= 1");
115   if (i>_count)
116     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : first argument is out of range") ;
117   if (j>_index[i])
118     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : second argument is out of range") ;
119   
120   _value[_index[i-1]+j-2]=value ;
121
122 }
123
124 inline void MEDSKYLINEARRAY::setI(const med_int i, const med_int * values) throw (MEDEXCEPTION)
125 {
126   if (i<1)
127     throw MEDEXCEPTION("MEDSKYLINEARRAY::setI : index must be >= 1");
128 ;
129   if (i>_count)
130     throw MEDEXCEPTION("MEDSKYLINEARRAY::setI : index is out of range") ;
131
132   memcpy(_value+_index[i-1]-1,values,(_index[i]-_index[i-1])*sizeof(med_int)) ;
133 }
134
135 inline void MEDSKYLINEARRAY::setIndexValue(med_int i, med_int value) throw (MEDEXCEPTION)
136 {
137   if (i<1)
138     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIndexValue : argument must be >= 1");
139   if (i>_index[_count])
140     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIndexValue : argument is out of range") ;
141   _value[i-1]=value ;
142 }
143
144 # endif