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 #include "MEDMEM_SkyLineArray.hxx"
24 #include "MEDMEM_Utilities.hxx"
28 using namespace MEDMEM;
30 MEDSKYLINEARRAY::MEDSKYLINEARRAY(): _count(0), _length(0),
31 _index((int*)NULL),_value((int*)NULL)
33 MESSAGE_MED("Constructeur MEDSKYLINEARRAY sans parametre");
36 MEDSKYLINEARRAY::MEDSKYLINEARRAY(const MEDSKYLINEARRAY &myArray):
37 _count(myArray._count),_length(myArray._length),
38 _index(_count+1),_value(_length)
40 const char* LOC = "MEDSKYLINEARRAY(const MEDSKYLINEARRAY &)";
43 memcpy(_index,myArray._index,sizeof(int)*(_count+1));
45 memcpy(_value,myArray._value,sizeof(int)*_length);
49 MEDSKYLINEARRAY::~MEDSKYLINEARRAY()
51 MESSAGE_MED("Destructeur ~MEDSKYLINEARRAY");
53 //if (_index != NULL) delete [] _index;
54 //if (_value != NULL) delete [] _value;
57 MEDSKYLINEARRAY::MEDSKYLINEARRAY(const int count, const int length):
58 _count(count), _length(length),
59 _index(_count+1),_value(_length)
61 MESSAGE_MED("Constructeur MEDSKYLINEARRAY(count="<<count<<", length="<<length<<") avec parametres");
64 MEDSKYLINEARRAY::MEDSKYLINEARRAY(const int count, const int length,
65 const int* index, const int* value,bool shallowCopy):
66 _count(count), _length(length)
68 // MESSAGE_MED("Constructeur MEDSKYLINEARRAY(count="<<count<<", length="<<length<<") avec parametres");
71 _index.setShallowAndOwnership(index);
72 _value.setShallowAndOwnership(value);
76 _index.set(_count+1,index);
77 _value.set(_length,value);
81 //creates the reverse array
82 //creates an array with count maxvalue, where maxvalue
83 //is the maximum of the value_ of the present array
84 //length is the same as present array
96 MEDSKYLINEARRAY* MEDSKYLINEARRAY::makeReverseArray()
98 multimap<int,int > reverse;
100 for (int i=0; i<_count;i++)
101 for (int j=_index[i];j<_index[i+1];j++)
103 int value=_value[j-1];
104 reverse.insert(make_pair(value,i+1));
105 if (value>size) size=value;
107 int* r_index=new int [size+1];
108 int* r_value=new int [_length];
110 pair<multimap<int,int>::iterator,multimap<int,int>::iterator>piter;
111 int* ptr_value=r_value;
112 for (int i=0; i<size;i++)
114 piter=reverse.equal_range(i);
116 for (multimap<int,int>::iterator iter=piter.first; iter!=piter.second; iter++)
118 *ptr_value++=iter->second;
121 r_index[i+1]=r_index[i]+index_incr;
123 return new MEDSKYLINEARRAY(size,_length,r_index,r_value,true);
125 ostream& MEDMEM::operator<<(ostream &os, const MEDSKYLINEARRAY &sky) {
126 os << "_count : " << sky._count << " ,_length : " << sky._length;
127 for (int i = 0; i < sky._count ; i++) {
128 os << endl << "Values of type n°" << i+1 << " (index["<<i<<"]="<< sky._index[i]<<") :" << endl;
129 for (int j=sky._index[i]-1;j < sky._index[i+1]-1;j++)
130 os << sky._value[j] << " " ;
135 // void MEDSKYLINEARRAY::setMEDSKYLINEARRAY( const int count , const int length, int* index , int* value )
137 // MESSAGE_MED("void MEDSKYLINEARRAY::setMEDSKYLINEARRAY(count, length, index, value)");
139 // _length = length ;
141 // //if (_index != NULL) delete [] _index;
142 // //if (_value != NULL) delete [] _value;
144 // _index.set(index);
145 // _value.set(value);