1 // Copyright (C) 2007-2012 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
23 # ifndef __MEDSKYLINEARRAY_H__
24 # define __MEDSKYLINEARRAY_H__
28 #include "MEDMEM_Exception.hxx"
30 #include "MEDMEM_PointerOf.hxx"
31 #include "MEDMEM_define.hxx"
36 class MEDSKYLINEARRAY;
37 MEDMEM_EXPORT ostream& operator<<(ostream &os, const MEDSKYLINEARRAY &sky);
39 class MEDMEM_EXPORT MEDSKYLINEARRAY
44 PointerOf <int> _index ; // array of size _count+1 : _index[0]=1 and
45 // _index[_count]=length+1
46 PointerOf <int> _value ; // array of size _length
49 // Attention, avec ce constructeur, il n'est possible de remplir le MEDSKYLINEARRAY
52 // Constructeur par recopie
53 MEDSKYLINEARRAY( const MEDSKYLINEARRAY &myArray );
55 // Avec ce constructeur la mémoire pour le tableau de valeur et le
56 // tableau d'index est réservée. Il suffit d'effectuer les séquences
57 // d'appels suivantes pour initialiser le MEDSKYLINEARRAY
58 // 1) setIndex(index) puis <count> fois setI(i,&listValeurN°I) avec i dans 1..count
59 // rem : listValeurN°I est dupliquée
60 // 2) appeler <length> fois setIJ(i,j,valeur) avec i dans 1..count et avec j dans 1..count
61 MEDSKYLINEARRAY( const int count, const int length );
63 // Avec ce constructeur le MEDSKYLINEARRAY est complètement initialisé
64 // Si shallowCopy=false (par défaut) les tableaux d'index et de valeurs
66 // Sinon le MEDSKYLINEARRAY prend directement les pointeurs et en devient
68 MEDSKYLINEARRAY( const int count, const int length,
69 const int* index, const int* value, bool shallowCopy=false );
72 //void setMEDSKYLINEARRAY( const int count, const int length, int* index , int* value ) ;
74 inline int getNumberOf() const;
75 inline int getLength() const;
76 inline const int* getIndex() const;
77 inline const int* getValue() const;
78 inline int getNumberOfI(int i) const throw (MEDEXCEPTION) ;
79 inline const int* getI(int i) const throw (MEDEXCEPTION) ;
80 inline int getIJ(int i, int j) const throw (MEDEXCEPTION) ;
81 inline int getIndexValue(int i) const throw (MEDEXCEPTION) ;
83 inline void setIndex(const int* index) ;
84 inline void setI(const int i, const int* values) throw (MEDEXCEPTION) ;
85 inline void setIJ(int i, int j, int value) throw (MEDEXCEPTION) ;
86 inline void setIndexValue(int i, int value) throw (MEDEXCEPTION) ;
88 friend ostream& operator<<(ostream &os, const MEDSKYLINEARRAY &sky);
89 MEDSKYLINEARRAY* makeReverseArray();
93 // ---------------------------------------
95 // ---------------------------------------
96 inline int MEDSKYLINEARRAY::getNumberOf() const
100 inline int MEDSKYLINEARRAY::getLength() const
104 inline const int* MEDSKYLINEARRAY::getIndex() const
106 return (const int*)_index ;
108 inline const int* MEDSKYLINEARRAY::getValue() const
110 return (const int*)_value ;
112 inline int MEDSKYLINEARRAY::getNumberOfI(int i) const throw (MEDEXCEPTION)
115 throw MEDEXCEPTION("MEDSKYLINEARRAY::getNumberOfI : argument must be >= 1");
117 throw MEDEXCEPTION("MEDSKYLINEARRAY::getNumberOfI : argument is out of range");
118 return _index[i]-_index[i-1] ;
120 inline const int* MEDSKYLINEARRAY::getI(int i) const throw (MEDEXCEPTION)
123 throw MEDEXCEPTION("MEDSKYLINEARRAY::getI : argument must be >= 1");
125 throw MEDEXCEPTION("MEDSKYLINEARRAY::getI : argument is out of range");
126 return _value+_index[i-1]-1 ;
128 inline int MEDSKYLINEARRAY::getIJ(int i, int j) const throw (MEDEXCEPTION)
131 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : first argument must be >= 1");
133 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : second argument must be >= 1");
135 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : first argument is out of range") ;
137 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : second argument is out of range") ;
138 return _value[_index[i-1]+j-2] ;
141 inline int MEDSKYLINEARRAY::getIndexValue(int i) const throw (MEDEXCEPTION)
144 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIndexValue : argument must be >= 1");
145 if (i>_index[_count])
146 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIndexValue : argument is out of range") ;
150 inline void MEDSKYLINEARRAY::setIndex(const int* index)
152 memcpy((int*)_index,index,(_count+1)*sizeof(int));
156 inline void MEDSKYLINEARRAY::setIJ(int i, int j, int value) throw (MEDEXCEPTION)
159 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : first argument must be >= 1");
161 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : second argument must be >= 1");
163 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : first argument is out of range") ;
165 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : second argument is out of range") ;
167 _value[_index[i-1]+j-2]=value ;
171 inline void MEDSKYLINEARRAY::setI(const int i, const int * values) throw (MEDEXCEPTION)
174 throw MEDEXCEPTION("MEDSKYLINEARRAY::setI : index must be >= 1");
177 throw MEDEXCEPTION("MEDSKYLINEARRAY::setI : index is out of range") ;
179 memcpy(_value+_index[i-1]-1,values,(_index[i]-_index[i-1])*sizeof(int)) ;
182 inline void MEDSKYLINEARRAY::setIndexValue(int i, int value) throw (MEDEXCEPTION)
185 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIndexValue : argument must be >= 1");
186 if (i>_index[_count])
187 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIndexValue : argument is out of range") ;