Back to index

salome-med  6.5.0
MEDMEMTest_Family_fault.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDMEM_define.hxx"
00021 #include "MEDMEM_Family.hxx"
00022 #include "MEDMEM_MedMeshDriver.hxx"
00023 #include "MEDMEM_Mesh.hxx"
00024 #include "MEDMEMTest_Utils.hxx"
00025 
00026 using namespace std;
00027 using namespace MEDMEM;
00028 
00029 int main (int argc, char** argv)
00030 {
00031   string filename = getResourceFile("pointe.med");
00032   string meshname = "maa1";
00033 
00034   MESH * aMesh = new MESH;
00035   aMesh->setName(meshname);
00036   MED_MESH_RDONLY_DRIVER aMeshDriver (filename, aMesh);
00037   aMeshDriver.setMeshName(meshname);
00038   aMeshDriver.open();
00039   aMeshDriver.read();
00040   aMeshDriver.close();
00041 
00042   const FAMILY * aFamily1 = aMesh->getFamily(MED_EN::MED_NODE, 1);
00043 
00044   // check default constructor and operator=
00045   FAMILY *aFamily4=new FAMILY;
00046 
00047   // (BUG) Wrong implementation or usage of PointerOf<string>.
00048   //       Do not use memcpy() with array of std::string!
00049   //       Impossible to use FAMILY::operator=!
00050   *aFamily4 = *aFamily1;
00051   aFamily4->removeReference();
00052 
00053   /*{
00054     int nb = 3;
00055     string * str = new string[nb];
00056 
00057     char tmp_str [32];
00058     for (int i = 0; i < nb; i++) {
00059       sprintf(tmp_str, "My String N %d", i+1);
00060       str[i] = tmp;
00061     }
00062 
00063     // bad
00064     string* _pointer;
00065     _pointer = new string[3];
00066     // This is wrong, because class string is not simple type
00067     // and can have pointers to some data, deallocated in it's destructor,
00068     // which (data) will not be copied by this operation.
00069     memcpy(_pointer, str, 3*sizeof(string));
00070     delete [] _pointer;
00071 
00072     // good
00073     //PointerOf<int> p1 (1);
00074     //PointerOf<int> p2 (20);
00075     //p2 = newAttributeValue;
00076     //p1.set(3, p2);
00077 
00078     // bad
00079     //PointerOf<string> p1 (1);
00080     //PointerOf<string> p2 (20);
00081     //p2 = str;
00082     //p1.set(3, p2);
00083 
00084     delete [] str;
00085   }
00086   */
00087 
00088   aMesh->removeReference();
00089 }