Back to index

salome-med  6.5.0
MEDMEM_SkyLineArray.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "MEDMEM_SkyLineArray.hxx"
00024 #include "MEDMEM_Utilities.hxx"
00025 #include <map>
00026 
00027 using namespace std;
00028 using namespace MEDMEM;
00029 
00030 MEDSKYLINEARRAY::MEDSKYLINEARRAY(): _count(0), _length(0),
00031                                 _index((int*)NULL),_value((int*)NULL)
00032 {
00033   MESSAGE_MED("Constructeur MEDSKYLINEARRAY sans parametre");
00034 }
00035 
00036 MEDSKYLINEARRAY::MEDSKYLINEARRAY(const MEDSKYLINEARRAY &myArray):
00037                                 _count(myArray._count),_length(myArray._length),
00038                                 _index(_count+1),_value(_length)
00039 {
00040   const char* LOC = "MEDSKYLINEARRAY(const MEDSKYLINEARRAY &)";
00041   BEGIN_OF_MED(LOC);
00042   if ( myArray._index )
00043     memcpy(_index,myArray._index,sizeof(int)*(_count+1));
00044   if ( myArray._value )
00045     memcpy(_value,myArray._value,sizeof(int)*_length);
00046   END_OF_MED(LOC);
00047 }
00048 
00049 MEDSKYLINEARRAY::~MEDSKYLINEARRAY()
00050 {
00051   MESSAGE_MED("Destructeur ~MEDSKYLINEARRAY");
00052 
00053   //if (_index != NULL) delete [] _index;
00054   //if (_value != NULL) delete [] _value;
00055 }
00056 
00057 MEDSKYLINEARRAY::MEDSKYLINEARRAY(const int count, const int length):
00058                                 _count(count), _length(length),
00059                                 _index(_count+1),_value(_length)
00060 {
00061         MESSAGE_MED("Constructeur MEDSKYLINEARRAY(count="<<count<<", length="<<length<<") avec parametres");
00062 }
00063 
00064 MEDSKYLINEARRAY::MEDSKYLINEARRAY(const int count, const int length,
00065                                  const int* index, const int* value,bool shallowCopy):
00066                                 _count(count), _length(length)
00067 {
00068 //      MESSAGE_MED("Constructeur MEDSKYLINEARRAY(count="<<count<<", length="<<length<<") avec parametres");
00069                 if(shallowCopy)
00070           {
00071             _index.setShallowAndOwnership(index);
00072             _value.setShallowAndOwnership(value);
00073           }
00074         else
00075           {
00076             _index.set(_count+1,index);
00077             _value.set(_length,value);
00078           }
00079 }
00080 
00081 //creates the reverse array
00082 //creates an array with count maxvalue, where maxvalue
00083 //is the maximum of the value_ of the present array
00084 //length is the same as present array
00085 //
00086 // For instance
00087 // 1 : 2 4
00088 // 2 : 1 2
00089 //
00090 //will give
00091 // 1 : 2
00092 // 2 : 1 2
00093 // 3 :
00094 // 4 : 1
00095 
00096 MEDSKYLINEARRAY* MEDSKYLINEARRAY::makeReverseArray()
00097 {
00098         multimap<int,int > reverse;
00099         int size=0;
00100   for (int i=0; i<_count;i++)
00101                 for (int j=_index[i];j<_index[i+1];j++)
00102                         {
00103                                 int value=_value[j-1];
00104                                 reverse.insert(make_pair(value,i+1));
00105                                 if (value>size) size=value;
00106                         }
00107         int* r_index=new int [size+1];
00108         int* r_value=new int [_length];
00109         r_index[0]=1;
00110         pair<multimap<int,int>::iterator,multimap<int,int>::iterator>piter;
00111         int* ptr_value=r_value;
00112         for (int i=0; i<size;i++)
00113                 {
00114                         piter=reverse.equal_range(i);
00115                         int index_incr=0;
00116                         for (multimap<int,int>::iterator iter=piter.first; iter!=piter.second; iter++)
00117                                 {
00118                                         *ptr_value++=iter->second;
00119                                         index_incr++;
00120                                 }
00121                         r_index[i+1]=r_index[i]+index_incr;
00122                 }
00123         return new MEDSKYLINEARRAY(size,_length,r_index,r_value,true);
00124 }
00125 ostream& MEDMEM::operator<<(ostream &os, const MEDSKYLINEARRAY &sky) {
00126   os << "_count : " << sky._count << " ,_length : " << sky._length;
00127   for (int i = 0; i < sky._count ; i++) {
00128     os << endl << "Values of type n" << i+1 << " (index["<<i<<"]="<< sky._index[i]<<") :" << endl;
00129     for (int j=sky._index[i]-1;j < sky._index[i+1]-1;j++)
00130       os << sky._value[j] << " " ;
00131   }
00132   return os;
00133 }
00134 
00135 //  void MEDSKYLINEARRAY::setMEDSKYLINEARRAY( const int count , const int length, int* index , int* value )
00136 //  {
00137 //    MESSAGE_MED("void MEDSKYLINEARRAY::setMEDSKYLINEARRAY(count, length, index, value)");
00138 //    _count  = count  ;
00139 //    _length = length ;
00140 
00141 //    //if (_index != NULL) delete [] _index;
00142 //    //if (_value != NULL) delete [] _value;
00143 
00144 //        _index.set(index);
00145 //        _value.set(value);
00146 //  }