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