Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 # ifndef __MEDSKYLINEARRAY_H__
00024 # define __MEDSKYLINEARRAY_H__
00025
00026 #include "MEDMEM.hxx"
00027
00028 #include "MEDMEM_Exception.hxx"
00029
00030 #include "MEDMEM_PointerOf.hxx"
00031 #include "MEDMEM_define.hxx"
00032
00033 #include <cstring>
00034
00035 namespace MEDMEM {
00036 class MEDSKYLINEARRAY;
00037 MEDMEM_EXPORT ostream& operator<<(ostream &os, const MEDSKYLINEARRAY &sky);
00038
00039 class MEDMEM_EXPORT MEDSKYLINEARRAY
00040 {
00041 private :
00042 int _count ;
00043 int _length ;
00044 PointerOf <int> _index ;
00045
00046 PointerOf <int> _value ;
00047
00048 public :
00049
00050 MEDSKYLINEARRAY();
00051
00052
00053 MEDSKYLINEARRAY( const MEDSKYLINEARRAY &myArray );
00054
00055
00056
00057
00058
00059
00060
00061 MEDSKYLINEARRAY( const int count, const int length );
00062
00063
00064
00065
00066
00067
00068 MEDSKYLINEARRAY( const int count, const int length,
00069 const int* index, const int* value, bool shallowCopy=false );
00070
00071 ~MEDSKYLINEARRAY();
00072
00073
00074 inline int getNumberOf() const;
00075 inline int getLength() const;
00076 inline const int* getIndex() const;
00077 inline const int* getValue() const;
00078 inline int getNumberOfI(int i) const throw (MEDEXCEPTION) ;
00079 inline const int* getI(int i) const throw (MEDEXCEPTION) ;
00080 inline int getIJ(int i, int j) const throw (MEDEXCEPTION) ;
00081 inline int getIndexValue(int i) const throw (MEDEXCEPTION) ;
00082
00083 inline void setIndex(const int* index) ;
00084 inline void setI(const int i, const int* values) throw (MEDEXCEPTION) ;
00085 inline void setIJ(int i, int j, int value) throw (MEDEXCEPTION) ;
00086 inline void setIndexValue(int i, int value) throw (MEDEXCEPTION) ;
00087
00088 friend ostream& operator<<(ostream &os, const MEDSKYLINEARRAY &sky);
00089 MEDSKYLINEARRAY* makeReverseArray();
00090
00091 };
00092
00093
00094
00095
00096 inline int MEDSKYLINEARRAY::getNumberOf() const
00097 {
00098 return _count ;
00099 }
00100 inline int MEDSKYLINEARRAY::getLength() const
00101 {
00102 return _length ;
00103 }
00104 inline const int* MEDSKYLINEARRAY::getIndex() const
00105 {
00106 return (const int*)_index ;
00107 }
00108 inline const int* MEDSKYLINEARRAY::getValue() const
00109 {
00110 return (const int*)_value ;
00111 }
00112 inline int MEDSKYLINEARRAY::getNumberOfI(int i) const throw (MEDEXCEPTION)
00113 {
00114 if (i<1)
00115 throw MEDEXCEPTION("MEDSKYLINEARRAY::getNumberOfI : argument must be >= 1");
00116 if (i>_count)
00117 throw MEDEXCEPTION("MEDSKYLINEARRAY::getNumberOfI : argument is out of range");
00118 return _index[i]-_index[i-1] ;
00119 }
00120 inline const int* MEDSKYLINEARRAY::getI(int i) const throw (MEDEXCEPTION)
00121 {
00122 if (i<1)
00123 throw MEDEXCEPTION("MEDSKYLINEARRAY::getI : argument must be >= 1");
00124 if (i>_count)
00125 throw MEDEXCEPTION("MEDSKYLINEARRAY::getI : argument is out of range");
00126 return _value+_index[i-1]-1 ;
00127 }
00128 inline int MEDSKYLINEARRAY::getIJ(int i, int j) const throw (MEDEXCEPTION)
00129 {
00130 if (i<1)
00131 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : first argument must be >= 1");
00132 if (j<1)
00133 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : second argument must be >= 1");
00134 if (i>_count)
00135 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : first argument is out of range") ;
00136 if (j>_index[i])
00137 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIJ : second argument is out of range") ;
00138 return _value[_index[i-1]+j-2] ;
00139 }
00140
00141 inline int MEDSKYLINEARRAY::getIndexValue(int i) const throw (MEDEXCEPTION)
00142 {
00143 if (i<1)
00144 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIndexValue : argument must be >= 1");
00145 if (i>_index[_count])
00146 throw MEDEXCEPTION("MEDSKYLINEARRAY::getIndexValue : argument is out of range") ;
00147 return _value[i-1] ;
00148 }
00149
00150 inline void MEDSKYLINEARRAY::setIndex(const int* index)
00151 {
00152 memcpy((int*)_index,index,(_count+1)*sizeof(int));
00153 }
00154
00155
00156 inline void MEDSKYLINEARRAY::setIJ(int i, int j, int value) throw (MEDEXCEPTION)
00157 {
00158 if (i<1)
00159 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : first argument must be >= 1");
00160 if (j<1)
00161 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : second argument must be >= 1");
00162 if (i>_count)
00163 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : first argument is out of range") ;
00164 if (j>_index[i])
00165 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIJ : second argument is out of range") ;
00166
00167 _value[_index[i-1]+j-2]=value ;
00168
00169 }
00170
00171 inline void MEDSKYLINEARRAY::setI(const int i, const int * values) throw (MEDEXCEPTION)
00172 {
00173 if (i<1)
00174 throw MEDEXCEPTION("MEDSKYLINEARRAY::setI : index must be >= 1");
00175 ;
00176 if (i>_count)
00177 throw MEDEXCEPTION("MEDSKYLINEARRAY::setI : index is out of range") ;
00178
00179 memcpy(_value+_index[i-1]-1,values,(_index[i]-_index[i-1])*sizeof(int)) ;
00180 }
00181
00182 inline void MEDSKYLINEARRAY::setIndexValue(int i, int value) throw (MEDEXCEPTION)
00183 {
00184 if (i<1)
00185 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIndexValue : argument must be >= 1");
00186 if (i>_index[_count])
00187 throw MEDEXCEPTION("MEDSKYLINEARRAY::setIndexValue : argument is out of range") ;
00188 _value[i-1]=value ;
00189 }
00190 }
00191 # endif