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