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/ or email : webmaster.salome@opencascade.com
20 # ifndef __MEDSKYLINEARRAY_H__
21 # define __MEDSKYLINEARRAY_H__
25 #include "MEDMEM_Exception.hxx"
27 #include "MEDMEM_PointerOf.hxx"
28 #include "MEDMEM_define.hxx"
31 class MEDSKYLINEARRAY;
32 ostream& operator<<(ostream &os, const MEDSKYLINEARRAY &sky);
34 class MEDMEM_EXPORT MEDSKYLINEARRAY
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
44 // Attention, avec ce constructeur, il n'est possible de remplir le MEDSKYLINEARRAY
47 // Constructeur par recopie
48 MEDSKYLINEARRAY( const MEDSKYLINEARRAY &myArray );
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 );
58 // Avec ce constructeur le MEDSKYLINEARRAY est complètement initialisé
59 // Si shallowCopy=false (par défaut) les tableaux d'index et de valeurs
61 // Sinon le MEDSKYLINEARRAY prend directement les pointeurs et en devient
63 MEDSKYLINEARRAY( const int count, const int length,
64 const int* index, const int* value, bool shallowCopy=false );
67 //void setMEDSKYLINEARRAY( const int count, const int length, int* index , int* value ) ;
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) ;
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) ;
83 friend ostream& operator<<(ostream &os, const MEDSKYLINEARRAY &sky);
86 // ---------------------------------------
88 // ---------------------------------------
89 inline int MEDSKYLINEARRAY::getNumberOf() const
93 inline int MEDSKYLINEARRAY::getLength() const
97 inline const int* MEDSKYLINEARRAY::getIndex() const
99 return (const int*)_index ;
101 inline const int* MEDSKYLINEARRAY::getValue() const
103 return (const int*)_value ;
105 inline int MEDSKYLINEARRAY::getNumberOfI(int i) const throw (MEDEXCEPTION)
108 throw MEDEXCEPTION("MEDSKYLINEARRAY::getNumberOfI : argument must be >= 1");
110 throw MEDEXCEPTION("MEDSKYLINEARRAY::getNumberOfI : argument is out of range");
111 return _index[i]-_index[i-1] ;
113 inline const int* MEDSKYLINEARRAY::getI(int i) const throw (MEDEXCEPTION)
116 throw MEDEXCEPTION("MEDSKYLINEARRAY::getI : argument must be >= 1");
118 throw MEDEXCEPTION("MEDSKYLINEARRAY::getI : argument is out of range");
119 return _value+_index[i-1]-1 ;
121 inline int MEDSKYLINEARRAY::getIJ(int i, int j) const throw (MEDEXCEPTION)
124 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : first argument must be >= 1");
126 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : second argument must be >= 1");
128 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : first argument is out of range") ;
130 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : second argument is out of range") ;
131 return _value[_index[i-1]+j-2] ;
134 inline int MEDSKYLINEARRAY::getIndexValue(int i) const throw (MEDEXCEPTION)
137 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIndexValue : argument must be >= 1");
138 if (i>_index[_count])
139 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIndexValue : argument is out of range") ;
143 inline void MEDSKYLINEARRAY::setIndex(const int* index)
145 memcpy((int*)_index,index,(_count+1)*sizeof(int));
149 inline void MEDSKYLINEARRAY::setIJ(int i, int j, int value) throw (MEDEXCEPTION)
152 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : first argument must be >= 1");
154 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : second argument must be >= 1");
156 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : first argument is out of range") ;
158 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : second argument is out of range") ;
160 _value[_index[i-1]+j-2]=value ;
164 inline void MEDSKYLINEARRAY::setI(const int i, const int * values) throw (MEDEXCEPTION)
167 throw MEDEXCEPTION("MEDSKYLINEARRAY::setI : index must be >= 1");
170 throw MEDEXCEPTION("MEDSKYLINEARRAY::setI : index is out of range") ;
172 memcpy(_value+_index[i-1]-1,values,(_index[i]-_index[i-1])*sizeof(int)) ;
175 inline void MEDSKYLINEARRAY::setIndexValue(int i, int value) throw (MEDEXCEPTION)
178 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIndexValue : argument must be >= 1");
179 if (i>_index[_count])
180 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIndexValue : argument is out of range") ;