]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
Improve SMDS: replace std::vector with simple array
authormsv <msv@opencascade.com>
Fri, 14 Jan 2005 13:26:34 +0000 (13:26 +0000)
committermsv <msv@opencascade.com>
Fri, 14 Jan 2005 13:26:34 +0000 (13:26 +0000)
for storage of links to nodes in mesh elements

src/SMDS/SMDS_FaceOfEdges.cxx
src/SMDS/SMDS_FaceOfEdges.hxx
src/SMDS/SMDS_FaceOfNodes.cxx
src/SMDS/SMDS_FaceOfNodes.hxx
src/SMDS/SMDS_VolumeOfFaces.cxx
src/SMDS/SMDS_VolumeOfFaces.hxx
src/SMDS/SMDS_VolumeOfNodes.cxx
src/SMDS/SMDS_VolumeOfNodes.hxx

index de9092f447c3d8e6de879f1e82e17452afa76b32..640c55d30194f44cd2835f4164abfaed5bc93a3b 100644 (file)
 // 
 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
 
+#ifdef _MSC_VER
+#pragma warning(disable:4786)
+#endif
+
 #include "SMDS_FaceOfEdges.hxx"
 #include "SMDS_IteratorOfElements.hxx"
 #include "SMDS_MeshNode.hxx"
@@ -32,7 +36,7 @@ using namespace std;
 
 int SMDS_FaceOfEdges::NbEdges() const
 {
-       return myEdges.size();
+       return myNbEdges;
 }
 
 int SMDS_FaceOfEdges::NbFaces() const
@@ -57,17 +61,23 @@ SMDSAbs_ElementType SMDS_FaceOfEdges::GetType() const
        return SMDSAbs_Face;
 }
 
+//=======================================================================
+//function : elementsIterator
+//purpose  : 
+//=======================================================================
+
 class SMDS_FaceOfEdges_MyIterator:public SMDS_ElemIterator
 {
-  const vector<const SMDS_MeshEdge*>& mySet;
+  const SMDS_MeshEdge* const *mySet;
+  int myLength;
   int index;
  public:
-  SMDS_FaceOfEdges_MyIterator(const vector<const SMDS_MeshEdge*>& s):
-    mySet(s),index(0) {}
+  SMDS_FaceOfEdges_MyIterator(const SMDS_MeshEdge* const *s, int l):
+    mySet(s),myLength(l),index(0) {}
 
   bool more()
   {
-    return index<mySet.size();
+    return index<myLength;
   }
 
   const SMDS_MeshElement* next()
@@ -76,30 +86,33 @@ class SMDS_FaceOfEdges_MyIterator:public SMDS_ElemIterator
     return mySet[index-1];
   }    
 };
-SMDS_ElemIteratorPtr SMDS_FaceOfEdges::
-       elementsIterator(SMDSAbs_ElementType type) const
+
+SMDS_ElemIteratorPtr SMDS_FaceOfEdges::elementsIterator
+                         (SMDSAbs_ElementType type) const
 {
-       switch(type)
-       {
-       case SMDSAbs_Face:
-          return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
-       case SMDSAbs_Edge:
-          return SMDS_ElemIteratorPtr(new SMDS_FaceOfEdges_MyIterator(myEdges));
-       default:
-          return SMDS_ElemIteratorPtr
-            (new SMDS_IteratorOfElements
-             (this,type, SMDS_ElemIteratorPtr(new SMDS_FaceOfEdges_MyIterator(myEdges))));
-       }
+  switch(type)
+  {
+  case SMDSAbs_Face:
+    return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
+  case SMDSAbs_Edge:
+    return SMDS_ElemIteratorPtr(new SMDS_FaceOfEdges_MyIterator(myEdges,myNbEdges));
+  default:
+    return SMDS_ElemIteratorPtr
+      (new SMDS_IteratorOfElements
+       (this,type, SMDS_ElemIteratorPtr
+        (new SMDS_FaceOfEdges_MyIterator(myEdges,myNbEdges))));
+  }
 }
 
 SMDS_FaceOfEdges::SMDS_FaceOfEdges(const SMDS_MeshEdge* edge1,
                                    const SMDS_MeshEdge* edge2,
                                    const SMDS_MeshEdge* edge3)
 {
-       myEdges.resize(3);
+       myNbEdges = 3;
        myEdges[0]=edge1;
        myEdges[1]=edge2;
        myEdges[2]=edge3;
+       myEdges[3]=0;
 }
 
 SMDS_FaceOfEdges::SMDS_FaceOfEdges(const SMDS_MeshEdge* edge1,
@@ -107,7 +120,7 @@ SMDS_FaceOfEdges::SMDS_FaceOfEdges(const SMDS_MeshEdge* edge1,
                                    const SMDS_MeshEdge* edge3,
                                    const SMDS_MeshEdge* edge4)
 {
-       myEdges.resize(4);
+       myNbEdges = 4;
        myEdges[0]=edge1;
        myEdges[1]=edge2;
        myEdges[2]=edge3;
index 6e8e7b8d620ffec449a973ae1047942c5e1bc2a5..cd8e5dd8f29ee2ca94343860f1ec1b3e86a9191a 100644 (file)
@@ -51,7 +51,8 @@ class SMDS_FaceOfEdges:public SMDS_MeshFace
                elementsIterator(SMDSAbs_ElementType type) const;
 
   private:
-       std::vector<const SMDS_MeshEdge*> myEdges;
+       const SMDS_MeshEdge* myEdges[4];
+        int                  myNbEdges;
 
 };
 
index 2ef48ca8a096e0cdd16ddecb0e561ab480ebaaf2..aa687082475c0633983a49b859093ecbd6b5bdca 100644 (file)
 // 
 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
 
+#ifdef _MSC_VER
+#pragma warning(disable:4786)
+#endif
+
 #include "SMDS_FaceOfNodes.hxx"
 #include "SMDS_IteratorOfElements.hxx"
 #include "SMDS_MeshNode.hxx"
@@ -43,8 +47,9 @@ int SMDS_FaceOfNodes::NbFaces() const
 
 int SMDS_FaceOfNodes::NbNodes() const
 {
-       return myNodes.size();
+       return myNbNodes;
 }
+
 //=======================================================================
 //function : Print
 //purpose  : 
@@ -58,41 +63,49 @@ void SMDS_FaceOfNodes::Print(ostream & OS) const
        OS << myNodes[i] << ") " << endl;
 }
 
+//=======================================================================
+//function : elementsIterator
+//purpose  : 
+//=======================================================================
+
 class SMDS_FaceOfNodes_MyIterator:public SMDS_ElemIterator
 {
-  const vector<const SMDS_MeshNode*>& mySet;
+  const SMDS_MeshNode* const *mySet;
+  int myLength;
   int index;
  public:
-  SMDS_FaceOfNodes_MyIterator(const vector<const SMDS_MeshNode*>& s):
-    mySet(s),index(0) {}
+  SMDS_FaceOfNodes_MyIterator(const SMDS_MeshNode* const *s, int l):
+    mySet(s),myLength(l),index(0) {}
 
   bool more()
   {
-    return index<mySet.size();
+    return index<myLength;
   }
 
   const SMDS_MeshElement* next()
   {
     index++;
     return mySet[index-1];
-  }    
+  }
 };
-SMDS_ElemIteratorPtr SMDS_FaceOfNodes::
-       elementsIterator(SMDSAbs_ElementType type) const
+
+SMDS_ElemIteratorPtr SMDS_FaceOfNodes::elementsIterator
+                         (SMDSAbs_ElementType type) const
 {
   switch(type)
   {
   case SMDSAbs_Face:
     return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
   case SMDSAbs_Node:
-    return SMDS_ElemIteratorPtr(new SMDS_FaceOfNodes_MyIterator(myNodes));
+    return SMDS_ElemIteratorPtr(new SMDS_FaceOfNodes_MyIterator(myNodes,myNbNodes));
   case SMDSAbs_Edge:
     MESSAGE("Error : edge iterator for SMDS_FaceOfNodes not implemented");
     break;
   default:
     return SMDS_ElemIteratorPtr
       (new SMDS_IteratorOfElements
-       (this,type,SMDS_ElemIteratorPtr(new SMDS_FaceOfNodes_MyIterator(myNodes))));
+       (this,type,SMDS_ElemIteratorPtr
+        (new SMDS_FaceOfNodes_MyIterator(myNodes,myNbNodes))));
   }
   return SMDS_ElemIteratorPtr();
 }
@@ -101,10 +114,11 @@ SMDS_FaceOfNodes::SMDS_FaceOfNodes(const SMDS_MeshNode* node1,
                                    const SMDS_MeshNode* node2,
                                    const SMDS_MeshNode* node3)
 {
-       myNodes.resize(3);
+       myNbNodes = 3;
        myNodes[0]=node1;
        myNodes[1]=node2;
        myNodes[2]=node3;
+       myNodes[3]=0;
 }
 
 SMDS_FaceOfNodes::SMDS_FaceOfNodes(const SMDS_MeshNode* node1,
@@ -112,7 +126,7 @@ SMDS_FaceOfNodes::SMDS_FaceOfNodes(const SMDS_MeshNode* node1,
                                    const SMDS_MeshNode* node3,
                                    const SMDS_MeshNode* node4)
 {
-       myNodes.resize(4);
+       myNbNodes = 4;
        myNodes[0]=node1;
        myNodes[1]=node2;
        myNodes[2]=node3;
@@ -121,20 +135,13 @@ SMDS_FaceOfNodes::SMDS_FaceOfNodes(const SMDS_MeshNode* node1,
 bool SMDS_FaceOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[],
                                    const int            nbNodes)
 {
-  if (nbNodes == 3) {
-    myNodes.resize(3);
-    myNodes[0]=nodes[0];
-    myNodes[1]=nodes[1];
-    myNodes[2]=nodes[2];
-  }
-  else if ( nbNodes == 4) {
-    myNodes.resize(4);
-    myNodes[0]=nodes[0];
-    myNodes[1]=nodes[1];
-    myNodes[2]=nodes[2];
+  myNbNodes = nbNodes;
+  myNodes[0]=nodes[0];
+  myNodes[1]=nodes[1];
+  myNodes[2]=nodes[2];
+  if (nbNodes == 4)
     myNodes[3]=nodes[3];
-  }
-  else
+  else if (nbNodes != 3)
     return false;
 
   return true;
index 0203c1b105895b5cc4d71e4c5166bd07fe310920..290195107d4844fbd2be02cfd5770209232a703c 100644 (file)
@@ -49,7 +49,8 @@ class SMDS_FaceOfNodes:public SMDS_MeshFace
                elementsIterator(SMDSAbs_ElementType type) const;
 
   private:
-       std::vector<const SMDS_MeshNode*> myNodes;
+       const SMDS_MeshNode* myNodes[4];
+        int                  myNbNodes;
 
 };
 
index a710a8ffeb61a9c3d19590fd4ac0bb032ed926e3..51e71f86c5596dd50d302f716fa5a00490c655d3 100644 (file)
 //  Author : Jean-Michel BOULCOURT
 //  Module : SMESH
 
+#ifdef _MSC_VER
+#pragma warning(disable:4786)
+#endif
+
 #include "SMDS_VolumeOfFaces.hxx"
 #include "SMDS_IteratorOfElements.hxx"
 
@@ -39,27 +43,28 @@ void SMDS_VolumeOfFaces::Print(ostream & OS) const
 {
        OS << "volume <" << GetID() << "> : ";
        int i;
-       for (i = 0; i < myFaces.size()-1; ++i) OS << myFaces[i] << ",";
+       for (i = 0; i < NbFaces()-1; ++i) OS << myFaces[i] << ",";
        OS << myFaces[i]<< ") " << endl;
 }
 
 
 int SMDS_VolumeOfFaces::NbFaces() const
 {
-       return myFaces.size();
+       return myNbFaces;
 }
 
 class SMDS_VolumeOfFaces_MyIterator:public SMDS_ElemIterator
 {
-  const vector<const SMDS_MeshFace*>& mySet;
+  const SMDS_MeshFace* const *mySet;
+  int myLength;
   int index;
  public:
-  SMDS_VolumeOfFaces_MyIterator(const vector<const SMDS_MeshFace*>& s):
-    mySet(s),index(0) {}
+  SMDS_VolumeOfFaces_MyIterator(const SMDS_MeshFace* const *s, int l):
+    mySet(s),myLength(l),index(0) {}
 
   bool more()
   {
-    return index<mySet.size();
+    return index<myLength;
   }
 
   const SMDS_MeshElement* next()
@@ -77,11 +82,12 @@ SMDS_ElemIteratorPtr SMDS_VolumeOfFaces::
   case SMDSAbs_Volume:
     return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
   case SMDSAbs_Face:
-    return SMDS_ElemIteratorPtr(new SMDS_VolumeOfFaces_MyIterator(myFaces));
+    return SMDS_ElemIteratorPtr(new SMDS_VolumeOfFaces_MyIterator(myFaces,myNbFaces));
   default:
     return SMDS_ElemIteratorPtr
       (new SMDS_IteratorOfElements
-       (this,type,SMDS_ElemIteratorPtr(new SMDS_VolumeOfFaces_MyIterator(myFaces))));
+       (this,type,SMDS_ElemIteratorPtr
+        (new SMDS_VolumeOfFaces_MyIterator(myFaces,myNbFaces))));
   }
 }
 
@@ -90,11 +96,13 @@ SMDS_VolumeOfFaces::SMDS_VolumeOfFaces(const SMDS_MeshFace * face1,
                                        const SMDS_MeshFace * face3,
                                        const SMDS_MeshFace * face4)
 {
-       myFaces.resize(4);
+       myNbFaces = 4;
        myFaces[0]=face1;
        myFaces[1]=face2;
        myFaces[2]=face3;
        myFaces[3]=face4;
+       myFaces[4]=0;
+       myFaces[5]=0;
 }
 
 SMDS_VolumeOfFaces::SMDS_VolumeOfFaces(const SMDS_MeshFace * face1,
@@ -103,12 +111,13 @@ SMDS_VolumeOfFaces::SMDS_VolumeOfFaces(const SMDS_MeshFace * face1,
                                        const SMDS_MeshFace * face4,
                                        const SMDS_MeshFace * face5)
 {
-       myFaces.resize(5);
+       myNbFaces = 5;
        myFaces[0]=face1;
        myFaces[1]=face2;
        myFaces[2]=face3;
        myFaces[3]=face4;
        myFaces[4]=face5;
+       myFaces[5]=0;
 }
 
 SMDS_VolumeOfFaces::SMDS_VolumeOfFaces(const SMDS_MeshFace * face1,
@@ -118,7 +127,7 @@ SMDS_VolumeOfFaces::SMDS_VolumeOfFaces(const SMDS_MeshFace * face1,
                                        const SMDS_MeshFace * face5,
                                        const SMDS_MeshFace * face6)
 {
-       myFaces.resize(6);
+       myNbFaces = 6;
        myFaces[0]=face1;
        myFaces[1]=face2;
        myFaces[2]=face3;
index 4a78e366ed86fa4baedc7f4a26b90680d5194768..ae3b288819bac9e0bb5372219d528694baf992f0 100644 (file)
@@ -30,7 +30,6 @@
 #include "SMDS_MeshVolume.hxx"
 #include "SMDS_MeshFace.hxx"
 #include "SMDS_Iterator.hxx"
-#include <vector>
 #include <iostream>
 
 
@@ -61,6 +60,7 @@ class SMDS_VolumeOfFaces:public SMDS_MeshVolume
   protected:
        SMDS_ElemIteratorPtr
                elementsIterator(SMDSAbs_ElementType type) const;
-       std::vector<const SMDS_MeshFace *> myFaces;
+       const SMDS_MeshFace * myFaces[6];
+       int                   myNbFaces;
 };
 #endif
index 25c0bf567dee9412ea162930edff5233dbc6a181..cd893f484a87e45a70059e678810ce358bb25271 100644 (file)
 // 
 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
 
+#ifdef _MSC_VER
+#pragma warning(disable:4786)
+#endif
+
 #include "SMDS_VolumeOfNodes.hxx"
 #include "SMDS_MeshNode.hxx"
 #include "utilities.h"
@@ -39,7 +43,8 @@ SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
                const SMDS_MeshNode * node7,
                const SMDS_MeshNode * node8)
 {
-       myNodes.resize(8);
+       myNbNodes = 8;
+       myNodes = new const SMDS_MeshNode* [myNbNodes];
        myNodes[0]=node1;
        myNodes[1]=node2;
        myNodes[2]=node3;
@@ -56,7 +61,8 @@ SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
                const SMDS_MeshNode * node3,
                const SMDS_MeshNode * node4)
 {
-       myNodes.resize(4);
+       myNbNodes = 4;
+       myNodes = new const SMDS_MeshNode* [myNbNodes];
        myNodes[0]=node1;
        myNodes[1]=node2;
        myNodes[2]=node3;
@@ -70,7 +76,8 @@ SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
                const SMDS_MeshNode * node4,
                const SMDS_MeshNode * node5)
 {
-       myNodes.resize(5);
+       myNbNodes = 5;
+       myNodes = new const SMDS_MeshNode* [myNbNodes];
        myNodes[0]=node1;
        myNodes[1]=node2;
        myNodes[2]=node3;
@@ -86,7 +93,8 @@ SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
                const SMDS_MeshNode * node5,
                const SMDS_MeshNode * node6)
 {
-       myNodes.resize(6);
+       myNbNodes = 6;
+       myNodes = new const SMDS_MeshNode* [myNbNodes];
        myNodes[0]=node1;
        myNodes[1]=node2;
        myNodes[2]=node3;
@@ -94,18 +102,30 @@ SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
        myNodes[4]=node5;
        myNodes[5]=node6;
 }
+
 bool SMDS_VolumeOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[],
                                      const int            nbNodes)
 {
   if (nbNodes < 4 || nbNodes > 8 || nbNodes == 7)
     return false;
 
-  myNodes.resize( nbNodes );
+  delete [] myNodes;
+  myNbNodes = nbNodes;
+  myNodes = new const SMDS_MeshNode* [myNbNodes];
   for ( int i = 0; i < nbNodes; i++ )
     myNodes[ i ] = nodes [ i ];
 
   return true;
 }
+
+SMDS_VolumeOfNodes::~SMDS_VolumeOfNodes()
+{
+  if (myNodes != NULL) {
+    delete [] myNodes;
+    myNodes = NULL;
+  }
+}
+
 //=======================================================================
 //function : Print
 //purpose  : 
@@ -134,7 +154,7 @@ int SMDS_VolumeOfNodes::NbFaces() const
 
 int SMDS_VolumeOfNodes::NbNodes() const
 {
-       return myNodes.size();
+       return myNbNodes;
 }
 
 int SMDS_VolumeOfNodes::NbEdges() const
@@ -152,15 +172,16 @@ int SMDS_VolumeOfNodes::NbEdges() const
 
 class SMDS_VolumeOfNodes_MyIterator:public SMDS_ElemIterator
 {
-  const vector<const SMDS_MeshNode*>& mySet;
+  const SMDS_MeshNode* const* mySet;
+  int myLength;
   int index;
  public:
-  SMDS_VolumeOfNodes_MyIterator(const vector<const SMDS_MeshNode*>& s):
-    mySet(s),index(0) {}
+  SMDS_VolumeOfNodes_MyIterator(const SMDS_MeshNode* const* s, int l):
+    mySet(s),myLength(l),index(0) {}
 
   bool more()
   {
-    return index<mySet.size();
+    return index<myLength;
   }
 
   const SMDS_MeshElement* next()
@@ -178,7 +199,7 @@ SMDS_ElemIteratorPtr SMDS_VolumeOfNodes::
   case SMDSAbs_Volume:
     return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
   case SMDSAbs_Node:
-    return SMDS_ElemIteratorPtr(new SMDS_VolumeOfNodes_MyIterator(myNodes));
+    return SMDS_ElemIteratorPtr(new SMDS_VolumeOfNodes_MyIterator(myNodes,myNbNodes));
   default:
     MESSAGE("ERROR : Iterator not implemented");
     return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL);
index b2a6c038ece7e2dd861aa761ff1e2469592e6bd9..bb553a03a003518bf96b42dd530591fc59f3ece9 100644 (file)
@@ -28,7 +28,6 @@
 #define _SMDS_VolumeOfNodes_HeaderFile
 
 #include "SMDS_MeshVolume.hxx"
-#include <vector>
 
 
 class SMDS_VolumeOfNodes:public SMDS_MeshVolume
@@ -64,6 +63,7 @@ class SMDS_VolumeOfNodes:public SMDS_MeshVolume
                const SMDS_MeshNode * node8);
         bool ChangeNodes(const SMDS_MeshNode* nodes[],
                          const int            nbNodes);
+        ~SMDS_VolumeOfNodes();
 
        void Print(std::ostream & OS) const;
        int NbFaces() const;
@@ -73,6 +73,7 @@ class SMDS_VolumeOfNodes:public SMDS_MeshVolume
   protected:
        SMDS_ElemIteratorPtr
                elementsIterator(SMDSAbs_ElementType type) const;
-       std::vector<const SMDS_MeshNode *> myNodes;
+       const SMDS_MeshNode** myNodes;
+       int                   myNbNodes;
 };
 #endif