1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/
20 # ifndef __MEDSKYLINEARRAY_H__
21 # define __MEDSKYLINEARRAY_H__
23 #include "MEDMEM_Exception.hxx"
25 #include "MEDMEM_PointerOf.hxx"
26 #include "MEDMEM_define.hxx"
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
39 // Attention, avec ce constructeur, il n'est possible de remplir le MEDSKYLINEARRAY
42 // Constructeur par recopie
43 MEDSKYLINEARRAY( const MEDSKYLINEARRAY &myArray );
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 );
53 // Avec ce constructeur le MEDSKYLINEARRAY est complètement initialisé
54 // Si shallowCopy=false (par défaut) les tableaux d'index et de valeurs
56 // Sinon le MEDSKYLINEARRAY prend directement les pointeurs et en devient
58 MEDSKYLINEARRAY( const int count, const int length,
59 const int* index, const int* value, bool shallowCopy=false );
62 //void setMEDSKYLINEARRAY( const int count, const int length, int* index , int* value ) ;
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) ;
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) ;
78 friend ostream& operator<<(ostream &os, const MEDSKYLINEARRAY &sky);
81 // ---------------------------------------
83 // ---------------------------------------
84 inline int MEDSKYLINEARRAY::getNumberOf() const
88 inline int MEDSKYLINEARRAY::getLength() const
92 inline const int* MEDSKYLINEARRAY::getIndex() const
94 return (const int*)_index ;
96 inline const int* MEDSKYLINEARRAY::getValue() const
98 return (const int*)_value ;
100 inline int MEDSKYLINEARRAY::getNumberOfI(int i) const throw (MEDEXCEPTION)
103 throw MEDEXCEPTION("MEDSKYLINEARRAY::getNumberOfI : argument must be >= 1");
105 throw MEDEXCEPTION("MEDSKYLINEARRAY::getNumberOfI : argument is out of range");
106 return _index[i]-_index[i-1] ;
108 inline const int* MEDSKYLINEARRAY::getI(int i) const throw (MEDEXCEPTION)
111 throw MEDEXCEPTION("MEDSKYLINEARRAY::getI : argument must be >= 1");
113 throw MEDEXCEPTION("MEDSKYLINEARRAY::getI : argument is out of range");
114 return _value+_index[i-1]-1 ;
116 inline int MEDSKYLINEARRAY::getIJ(int i, int j) const throw (MEDEXCEPTION)
119 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : first argument must be >= 1");
121 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : second argument must be >= 1");
123 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : first argument is out of range") ;
125 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : second argument is out of range") ;
126 return _value[_index[i-1]+j-2] ;
129 inline int MEDSKYLINEARRAY::getIndexValue(int i) const throw (MEDEXCEPTION)
132 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIndexValue : argument must be >= 1");
133 if (i>_index[_count])
134 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIndexValue : argument is out of range") ;
138 inline void MEDSKYLINEARRAY::setIndex(const int* index)
140 memcpy((int*)_index,index,(_count+1)*sizeof(int));
144 inline void MEDSKYLINEARRAY::setIJ(int i, int j, int value) throw (MEDEXCEPTION)
147 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : first argument must be >= 1");
149 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : second argument must be >= 1");
151 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : first argument is out of range") ;
153 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : second argument is out of range") ;
155 _value[_index[i-1]+j-2]=value ;
159 inline void MEDSKYLINEARRAY::setI(const int i, const int * values) throw (MEDEXCEPTION)
162 throw MEDEXCEPTION("MEDSKYLINEARRAY::setI : index must be >= 1");
165 throw MEDEXCEPTION("MEDSKYLINEARRAY::setI : index is out of range") ;
167 memcpy(_value+_index[i-1]-1,values,(_index[i]-_index[i-1])*sizeof(int)) ;
170 inline void MEDSKYLINEARRAY::setIndexValue(int i, int value) throw (MEDEXCEPTION)
173 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIndexValue : argument must be >= 1");
174 if (i>_index[_count])
175 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIndexValue : argument is out of range") ;