1 // Copyright (C) 2007-2008 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
22 #include "MEDMEM_SkyLineArray.hxx"
23 #include "MEDMEM_Utilities.hxx"
27 using namespace MEDMEM;
29 MEDSKYLINEARRAY::MEDSKYLINEARRAY(): _count(0), _length(0),
30 _index((int*)NULL),_value((int*)NULL)
32 MESSAGE_MED("Constructeur MEDSKYLINEARRAY sans parametre");
35 MEDSKYLINEARRAY::MEDSKYLINEARRAY(const MEDSKYLINEARRAY &myArray):
36 _count(myArray._count),_length(myArray._length),
37 _index(_count+1),_value(_length)
39 const char* LOC = "MEDSKYLINEARRAY(const MEDSKYLINEARRAY &)";
41 memcpy(_index,myArray._index,sizeof(int)*(_count+1));
42 memcpy(_value,myArray._value,sizeof(int)*_length);
46 MEDSKYLINEARRAY::~MEDSKYLINEARRAY()
48 MESSAGE_MED("Destructeur ~MEDSKYLINEARRAY");
50 //if (_index != NULL) delete [] _index;
51 //if (_value != NULL) delete [] _value;
54 MEDSKYLINEARRAY::MEDSKYLINEARRAY(const int count, const int length):
55 _count(count), _length(length),
56 _index(_count+1),_value(_length)
58 MESSAGE_MED("Constructeur MEDSKYLINEARRAY(count="<<count<<", length="<<length<<") avec parametres");
61 MEDSKYLINEARRAY::MEDSKYLINEARRAY(const int count, const int length,
62 const int* index, const int* value,bool shallowCopy):
63 _count(count), _length(length)
65 // MESSAGE_MED("Constructeur MEDSKYLINEARRAY(count="<<count<<", length="<<length<<") avec parametres");
68 _index.setShallowAndOwnership(index);
69 _value.setShallowAndOwnership(value);
73 _index.set(_count+1,index);
74 _value.set(_length,value);
78 //creates the reverse array
79 //creates an array with count maxvalue, where maxvalue
80 //is the maximum of the value_ of the present array
81 //length is the same as present array
93 MEDSKYLINEARRAY* MEDSKYLINEARRAY::makeReverseArray()
95 multimap<int,int > reverse;
97 for (int i=0; i<_count;i++)
98 for (int j=_index[i];j<_index[i+1];j++)
100 int value=_value[j-1];
101 reverse.insert(make_pair(value,i+1));
102 if (value>size) size=value;
104 int* r_index=new int [size+1];
105 int* r_value=new int [_length];
107 pair<multimap<int,int>::iterator,multimap<int,int>::iterator>piter;
108 int* ptr_value=r_value;
109 for (int i=0; i<size;i++)
111 piter=reverse.equal_range(i);
113 for (multimap<int,int>::iterator iter=piter.first; iter!=piter.second; iter++)
115 *ptr_value++=iter->second;
118 r_index[i+1]=r_index[i]+index_incr;
120 return new MEDSKYLINEARRAY(size,_length,r_index,r_value,true);
122 ostream& MEDMEM::operator<<(ostream &os, const MEDSKYLINEARRAY &sky) {
123 os << "_count : " << sky._count << " ,_length : " << sky._length;
124 for (int i = 0; i < sky._count ; i++) {
125 os << endl << "Values of type n°" << i+1 << " (index["<<i<<"]="<< sky._index[i]<<") :" << endl;
126 for (int j=sky._index[i]-1;j < sky._index[i+1]-1;j++)
127 os << sky._value[j] << " " ;
132 // void MEDSKYLINEARRAY::setMEDSKYLINEARRAY( const int count , const int length, int* index , int* value )
134 // MESSAGE_MED("void MEDSKYLINEARRAY::setMEDSKYLINEARRAY(count, length, index, value)");
136 // _length = length ;
138 // //if (_index != NULL) delete [] _index;
139 // //if (_value != NULL) delete [] _value;
141 // _index.set(index);
142 // _value.set(value);