1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 # ifndef __MEDSKYLINEARRAY_H__
23 # define __MEDSKYLINEARRAY_H__
27 #include "MEDMEM_Exception.hxx"
29 #include "MEDMEM_PointerOf.hxx"
30 #include "MEDMEM_define.hxx"
33 class MEDSKYLINEARRAY;
34 ostream& operator<<(ostream &os, const MEDSKYLINEARRAY &sky);
36 class MEDMEM_EXPORT MEDSKYLINEARRAY
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
46 // Attention, avec ce constructeur, il n'est possible de remplir le MEDSKYLINEARRAY
49 // Constructeur par recopie
50 MEDSKYLINEARRAY( const MEDSKYLINEARRAY &myArray );
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 );
60 // Avec ce constructeur le MEDSKYLINEARRAY est complètement initialisé
61 // Si shallowCopy=false (par défaut) les tableaux d'index et de valeurs
63 // Sinon le MEDSKYLINEARRAY prend directement les pointeurs et en devient
65 MEDSKYLINEARRAY( const int count, const int length,
66 const int* index, const int* value, bool shallowCopy=false );
69 //void setMEDSKYLINEARRAY( const int count, const int length, int* index , int* value ) ;
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) ;
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) ;
85 friend ostream& operator<<(ostream &os, const MEDSKYLINEARRAY &sky);
86 MEDSKYLINEARRAY* makeReverseArray();
90 // ---------------------------------------
92 // ---------------------------------------
93 inline int MEDSKYLINEARRAY::getNumberOf() const
97 inline int MEDSKYLINEARRAY::getLength() const
101 inline const int* MEDSKYLINEARRAY::getIndex() const
103 return (const int*)_index ;
105 inline const int* MEDSKYLINEARRAY::getValue() const
107 return (const int*)_value ;
109 inline int MEDSKYLINEARRAY::getNumberOfI(int i) const throw (MEDEXCEPTION)
112 throw MEDEXCEPTION("MEDSKYLINEARRAY::getNumberOfI : argument must be >= 1");
114 throw MEDEXCEPTION("MEDSKYLINEARRAY::getNumberOfI : argument is out of range");
115 return _index[i]-_index[i-1] ;
117 inline const int* MEDSKYLINEARRAY::getI(int i) const throw (MEDEXCEPTION)
120 throw MEDEXCEPTION("MEDSKYLINEARRAY::getI : argument must be >= 1");
122 throw MEDEXCEPTION("MEDSKYLINEARRAY::getI : argument is out of range");
123 return _value+_index[i-1]-1 ;
125 inline int MEDSKYLINEARRAY::getIJ(int i, int j) const throw (MEDEXCEPTION)
128 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : first argument must be >= 1");
130 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : second argument must be >= 1");
132 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : first argument is out of range") ;
134 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : second argument is out of range") ;
135 return _value[_index[i-1]+j-2] ;
138 inline int MEDSKYLINEARRAY::getIndexValue(int i) const throw (MEDEXCEPTION)
141 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIndexValue : argument must be >= 1");
142 if (i>_index[_count])
143 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIndexValue : argument is out of range") ;
147 inline void MEDSKYLINEARRAY::setIndex(const int* index)
149 memcpy((int*)_index,index,(_count+1)*sizeof(int));
153 inline void MEDSKYLINEARRAY::setIJ(int i, int j, int value) throw (MEDEXCEPTION)
156 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : first argument must be >= 1");
158 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : second argument must be >= 1");
160 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : first argument is out of range") ;
162 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : second argument is out of range") ;
164 _value[_index[i-1]+j-2]=value ;
168 inline void MEDSKYLINEARRAY::setI(const int i, const int * values) throw (MEDEXCEPTION)
171 throw MEDEXCEPTION("MEDSKYLINEARRAY::setI : index must be >= 1");
174 throw MEDEXCEPTION("MEDSKYLINEARRAY::setI : index is out of range") ;
176 memcpy(_value+_index[i-1]-1,values,(_index[i]-_index[i-1])*sizeof(int)) ;
179 inline void MEDSKYLINEARRAY::setIndexValue(int i, int value) throw (MEDEXCEPTION)
182 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIndexValue : argument must be >= 1");
183 if (i>_index[_count])
184 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIndexValue : argument is out of range") ;