Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MEDMEM / MEDMEM_SkyLineArray.hxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 # ifndef __MEDSKYLINEARRAY_H__
21 # define __MEDSKYLINEARRAY_H__
22
23 #include "MEDMEM.hxx"
24
25 #include "MEDMEM_Exception.hxx"
26
27 #include "MEDMEM_PointerOf.hxx"
28 #include "MEDMEM_define.hxx"
29
30 namespace MEDMEM {
31   class MEDSKYLINEARRAY;
32   ostream& operator<<(ostream &os, const MEDSKYLINEARRAY &sky);
33
34 class MEDMEM_EXPORT MEDSKYLINEARRAY
35 {
36 private :
37   int   _count ;
38   int   _length ;
39   PointerOf <int> _index ; // array of size _count+1 : _index[0]=1 and
40                            // _index[_count]=length+1
41   PointerOf <int> _value ; // array of size _length
42
43 public :
44   // Attention, avec ce constructeur, il n'est possible de remplir le MEDSKYLINEARRAY 
45   MEDSKYLINEARRAY();
46
47   // Constructeur par recopie
48   MEDSKYLINEARRAY( const MEDSKYLINEARRAY &myArray );
49
50   // Avec ce constructeur la mémoire pour le tableau  de valeur et le
51   // tableau d'index est réservée. Il suffit d'effectuer les séquences
52   // d'appels suivantes pour initialiser le MEDSKYLINEARRAY
53   // 1) setIndex(index) puis <count> fois setI(i,&listValeurN°I) avec i dans 1..count
54   //    rem :   listValeurN°I est dupliquée
55   // 2) appeler <length> fois setIJ(i,j,valeur) avec i dans 1..count et avec j dans 1..count
56   MEDSKYLINEARRAY( const int count, const int length );
57
58   // Avec ce constructeur le MEDSKYLINEARRAY est complètement initialisé
59   // Si shallowCopy=false (par défaut) les tableaux d'index et de valeurs
60   // sont dupliqués
61   // Sinon le MEDSKYLINEARRAY prend directement les pointeurs et en devient 
62   // propriétaire
63   MEDSKYLINEARRAY( const int count, const int length,
64                    const int* index, const int* value, bool shallowCopy=false );
65
66   ~MEDSKYLINEARRAY();
67   //void setMEDSKYLINEARRAY( const int count, const int length, int* index , int* value ) ;
68
69   inline int  getNumberOf()       const;
70   inline int  getLength()         const;
71   inline const int*  getIndex()   const;
72   inline const int*  getValue()   const;
73   inline int  getNumberOfI(int i) const throw (MEDEXCEPTION) ;
74   inline const int*  getI(int i)  const throw (MEDEXCEPTION) ;
75   inline int  getIJ(int i, int j) const throw (MEDEXCEPTION) ;
76   inline int  getIndexValue(int i) const throw (MEDEXCEPTION) ;
77
78   inline void setIndex(const int* index) ;
79   inline void setI(const int i, const int* values) throw (MEDEXCEPTION) ;
80   inline void setIJ(int i, int j, int value) throw (MEDEXCEPTION) ;
81   inline void setIndexValue(int i, int value) throw (MEDEXCEPTION) ;
82
83   friend ostream& operator<<(ostream &os, const MEDSKYLINEARRAY &sky);
84 };
85
86 // ---------------------------------------
87 //              Methodes Inline
88 // ---------------------------------------
89 inline int MEDSKYLINEARRAY::getNumberOf() const
90 {
91   return _count ;
92 };
93 inline int MEDSKYLINEARRAY::getLength() const
94 {
95   return _length ;
96 };
97 inline const int*  MEDSKYLINEARRAY::getIndex() const
98 {
99   return (const int*)_index ;
100 } ;
101 inline const int*  MEDSKYLINEARRAY::getValue() const
102 {
103   return (const int*)_value ;
104 } ;
105 inline int MEDSKYLINEARRAY::getNumberOfI(int i) const throw (MEDEXCEPTION)
106 {
107   if (i<1)
108     throw MEDEXCEPTION("MEDSKYLINEARRAY::getNumberOfI : argument must be >= 1");
109   if (i>_count)
110     throw MEDEXCEPTION("MEDSKYLINEARRAY::getNumberOfI : argument is out of range");
111   return _index[i]-_index[i-1] ;
112 } ;
113 inline const int* MEDSKYLINEARRAY::getI(int i) const throw (MEDEXCEPTION)
114 {
115     if (i<1)
116       throw MEDEXCEPTION("MEDSKYLINEARRAY::getI : argument must be >= 1");
117     if (i>_count)
118       throw MEDEXCEPTION("MEDSKYLINEARRAY::getI : argument is out of range");
119     return _value+_index[i-1]-1 ;
120 }
121 inline int MEDSKYLINEARRAY::getIJ(int i, int j) const throw (MEDEXCEPTION)
122 {
123     if (i<1)
124       throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : first argument must be >= 1");
125     if (j<1)
126       throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : second argument must be >= 1");
127     if (i>_count)
128       throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : first argument is out of range") ;
129     if (j>_index[i])
130       throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : second argument is out of range") ;
131     return _value[_index[i-1]+j-2] ;
132 }
133
134 inline int  MEDSKYLINEARRAY::getIndexValue(int i) const throw (MEDEXCEPTION)
135 {
136   if (i<1)
137     throw MEDEXCEPTION("MEDSKYLINEARRAY::getIndexValue : argument must be >= 1");
138   if (i>_index[_count])
139     throw MEDEXCEPTION("MEDSKYLINEARRAY::getIndexValue : argument is out of range") ;
140   return _value[i-1] ;
141 }
142
143 inline void MEDSKYLINEARRAY::setIndex(const int* index)
144 {
145   memcpy((int*)_index,index,(_count+1)*sizeof(int));
146 }
147
148
149 inline void MEDSKYLINEARRAY::setIJ(int i, int j, int value) throw (MEDEXCEPTION)
150 {
151   if (i<1)
152     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : first argument must be >= 1");
153   if (j<1)
154     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : second argument must be >= 1");
155   if (i>_count)
156     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : first argument is out of range") ;
157   if (j>_index[i])
158     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : second argument is out of range") ;
159   
160   _value[_index[i-1]+j-2]=value ;
161
162 }
163
164 inline void MEDSKYLINEARRAY::setI(const int i, const int * values) throw (MEDEXCEPTION)
165 {
166   if (i<1)
167     throw MEDEXCEPTION("MEDSKYLINEARRAY::setI : index must be >= 1");
168 ;
169   if (i>_count)
170     throw MEDEXCEPTION("MEDSKYLINEARRAY::setI : index is out of range") ;
171
172   memcpy(_value+_index[i-1]-1,values,(_index[i]-_index[i-1])*sizeof(int)) ;
173 }
174
175 inline void MEDSKYLINEARRAY::setIndexValue(int i, int value) throw (MEDEXCEPTION)
176 {
177   if (i<1)
178     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIndexValue : argument must be >= 1");
179   if (i>_index[_count])
180     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIndexValue : argument is out of range") ;
181   _value[i-1]=value ;
182 }
183 }
184 # endif