]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_SkyLineArray.hxx
Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[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_Exception.hxx"
24
25 #include "MEDMEM_PointerOf.hxx"
26 #include "MEDMEM_define.hxx"
27
28 namespace MEDMEM {
29 class MEDSKYLINEARRAY
30 {
31 private :
32   int   _count ;
33   int   _length ;
34   PointerOf <int> _index ; // array of size _count+1 : _index[0]=1 and
35                            // _index[_count]=length+1
36   PointerOf <int> _value ; // array of size _length
37
38 public :
39   // Attention, avec ce constructeur, il n'est possible de remplir le MEDSKYLINEARRAY 
40   MEDSKYLINEARRAY();
41
42   // Constructeur par recopie
43   MEDSKYLINEARRAY( const MEDSKYLINEARRAY &myArray );
44
45   // Avec ce constructeur la mémoire pour le tableau  de valeur et le
46   // tableau d'index est réservée. Il suffit d'effectuer les séquences
47   // d'appels suivantes pour initialiser le MEDSKYLINEARRAY
48   // 1) setIndex(index) puis <count> fois setI(i,&listValeurN°I) avec i dans 1..count
49   //    rem :   listValeurN°I est dupliquée
50   // 2) appeler <length> fois setIJ(i,j,valeur) avec i dans 1..count et avec j dans 1..count
51   MEDSKYLINEARRAY( const int count, const int length );
52
53   // Avec ce constructeur le MEDSKYLINEARRAY est complètement initialisé
54   // Si shallowCopy=false (par défaut) les tableaux d'index et de valeurs
55   // sont dupliqués
56   // Sinon le MEDSKYLINEARRAY prend directement les pointeurs et en devient 
57   // propriétaire
58   MEDSKYLINEARRAY( const int count, const int length,
59                    const int* index, const int* value, bool shallowCopy=false );
60
61   ~MEDSKYLINEARRAY();
62   //void setMEDSKYLINEARRAY( const int count, const int length, int* index , int* value ) ;
63
64   inline int  getNumberOf()       const;
65   inline int  getLength()         const;
66   inline const int*  getIndex()   const;
67   inline const int*  getValue()   const;
68   inline int  getNumberOfI(int i) const throw (MEDEXCEPTION) ;
69   inline const int*  getI(int i)  const throw (MEDEXCEPTION) ;
70   inline int  getIJ(int i, int j) const throw (MEDEXCEPTION) ;
71   inline int  getIndexValue(int i) const throw (MEDEXCEPTION) ;
72
73   inline void setIndex(const int* index) ;
74   inline void setI(const int i, const int* values) throw (MEDEXCEPTION) ;
75   inline void setIJ(int i, int j, int value) throw (MEDEXCEPTION) ;
76   inline void setIndexValue(int i, int value) throw (MEDEXCEPTION) ;
77
78   friend ostream& operator<<(ostream &os, const MEDSKYLINEARRAY &sky);
79 };
80
81 // ---------------------------------------
82 //              Methodes Inline
83 // ---------------------------------------
84 inline int MEDSKYLINEARRAY::getNumberOf() const
85 {
86   return _count ;
87 };
88 inline int MEDSKYLINEARRAY::getLength() const
89 {
90   return _length ;
91 };
92 inline const int*  MEDSKYLINEARRAY::getIndex() const
93 {
94   return (const int*)_index ;
95 } ;
96 inline const int*  MEDSKYLINEARRAY::getValue() const
97 {
98   return (const int*)_value ;
99 } ;
100 inline int MEDSKYLINEARRAY::getNumberOfI(int i) const throw (MEDEXCEPTION)
101 {
102   if (i<1)
103     throw MEDEXCEPTION("MEDSKYLINEARRAY::getNumberOfI : argument must be >= 1");
104   if (i>_count)
105     throw MEDEXCEPTION("MEDSKYLINEARRAY::getNumberOfI : argument is out of range");
106   return _index[i]-_index[i-1] ;
107 } ;
108 inline const int* MEDSKYLINEARRAY::getI(int i) const throw (MEDEXCEPTION)
109 {
110     if (i<1)
111       throw MEDEXCEPTION("MEDSKYLINEARRAY::getI : argument must be >= 1");
112     if (i>_count)
113       throw MEDEXCEPTION("MEDSKYLINEARRAY::getI : argument is out of range");
114     return _value+_index[i-1]-1 ;
115 }
116 inline int MEDSKYLINEARRAY::getIJ(int i, int j) const throw (MEDEXCEPTION)
117 {
118     if (i<1)
119       throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : first argument must be >= 1");
120     if (j<1)
121       throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : second argument must be >= 1");
122     if (i>_count)
123       throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : first argument is out of range") ;
124     if (j>_index[i])
125       throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : second argument is out of range") ;
126     return _value[_index[i-1]+j-2] ;
127 }
128
129 inline int  MEDSKYLINEARRAY::getIndexValue(int i) const throw (MEDEXCEPTION)
130 {
131   if (i<1)
132     throw MEDEXCEPTION("MEDSKYLINEARRAY::getIndexValue : argument must be >= 1");
133   if (i>_index[_count])
134     throw MEDEXCEPTION("MEDSKYLINEARRAY::getIndexValue : argument is out of range") ;
135   return _value[i-1] ;
136 }
137
138 inline void MEDSKYLINEARRAY::setIndex(const int* index)
139 {
140   memcpy((int*)_index,index,(_count+1)*sizeof(int));
141 }
142
143
144 inline void MEDSKYLINEARRAY::setIJ(int i, int j, int value) throw (MEDEXCEPTION)
145 {
146   if (i<1)
147     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : first argument must be >= 1");
148   if (j<1)
149     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : second argument must be >= 1");
150   if (i>_count)
151     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : first argument is out of range") ;
152   if (j>_index[i])
153     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : second argument is out of range") ;
154   
155   _value[_index[i-1]+j-2]=value ;
156
157 }
158
159 inline void MEDSKYLINEARRAY::setI(const int i, const int * values) throw (MEDEXCEPTION)
160 {
161   if (i<1)
162     throw MEDEXCEPTION("MEDSKYLINEARRAY::setI : index must be >= 1");
163 ;
164   if (i>_count)
165     throw MEDEXCEPTION("MEDSKYLINEARRAY::setI : index is out of range") ;
166
167   memcpy(_value+_index[i-1]-1,values,(_index[i]-_index[i-1])*sizeof(int)) ;
168 }
169
170 inline void MEDSKYLINEARRAY::setIndexValue(int i, int value) throw (MEDEXCEPTION)
171 {
172   if (i<1)
173     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIndexValue : argument must be >= 1");
174   if (i>_index[_count])
175     throw MEDEXCEPTION("MEDSKYLINEARRAY::setIndexValue : argument is out of range") ;
176   _value[i-1]=value ;
177 }
178 }
179 # endif