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