]> SALOME platform Git repositories - modules/yacs.git/commitdiff
Salome HOME
Visitor for AbstractPoint
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 4 Apr 2018 08:57:24 +0000 (10:57 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 4 Apr 2018 08:57:24 +0000 (10:57 +0200)
13 files changed:
src/engine/AbstractPoint.hxx
src/engine/BagPoint.cxx
src/engine/BagPoint.hxx
src/engine/ElementaryPoint.cxx
src/engine/ElementaryPoint.hxx
src/engine/ForkBlocPoint.cxx
src/engine/ForkBlocPoint.hxx
src/engine/LinkedBlocPoint.cxx
src/engine/LinkedBlocPoint.hxx
src/engine/PointVisitor.hxx [new file with mode: 0644]
src/engine/SetOfPoints.cxx
src/engine/SetOfPoints.hxx
src/engine_swig/pilot.i

index 2aceabfdfd03ac02505746ab48b4693c50293dc4..e75f07739ada0e4f0cb2e5ae583a52ad2421a68f 100644 (file)
@@ -39,6 +39,7 @@ namespace YACS
     class BlocPoint;
     class ComposedNode;
     class ForkBlocPoint;
+    class PointVisitor;
     class LinkedBlocPoint;
     
     class YACSLIBENGINE_EXPORT AbstractPoint
@@ -70,6 +71,7 @@ namespace YACS
       virtual void getWeightRegardingDPL(ComplexWeight *weight) = 0;
       virtual void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const = 0;
       virtual std::string getRepr() const = 0;
+      virtual void accept(PointVisitor *pv) = 0;
       virtual ~AbstractPoint();
     public:
       static bool IsGatherB4Ext(Node *node);
index 2492813dfefd7c27bfbbce2256bcbc05b15b52cb..c27ba442670f930b01b0ebf101fb7ad640573cf0 100644 (file)
@@ -64,6 +64,16 @@ AbstractPoint *BagPoint::getUniqueAndReleaseIt()
   return ret;
 }
 
+void BagPoint::accept(PointVisitor *pv)
+{
+  if(_nodes.size()!=1)
+    throw YACS::Exception("BagPoint::accept : simplification has failed !");
+  AbstractPoint *ret(*_nodes.begin());
+  if(!ret)
+    throw YACS::Exception("BagPoint::accept : Ooops !");
+  ret->accept(pv);
+}
+
 Node *BagPoint::getFirstNode()
 {
   return getUnique()->getFirstNode();
index 9e97acd25b72ca8c89c25da834410f75b0679317..b45cece9b597c578d2821a5894486a574b8d91a8 100644 (file)
@@ -41,6 +41,7 @@ namespace YACS
       void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const;
       std::string getRepr() const;
       AbstractPoint *getUniqueAndReleaseIt();
+      void accept(PointVisitor *pv) override;
     public:
       int size() const { return (int)_nodes.size(); }
       void replaceInMe(BlocPoint *aSet);
index 7d161b9c2952cf7ec2a2813a8049d944a56409a3..72dd58c3531b0a0394ecbce56af6156effe8c95a 100644 (file)
@@ -18,6 +18,7 @@
 //
 
 #include "ElementaryPoint.hxx"
+#include "PointVisitor.hxx"
 #include "Node.hxx"
 
 using namespace YACS::ENGINE;
@@ -73,3 +74,9 @@ std::string ElementaryPoint::getRepr() const
 {
   return _node->getName();
 }
+
+void ElementaryPoint::accept(PointVisitor *pv)
+{
+  pv->beginElementaryPoint(this);
+  pv->endElementaryPoint(this);
+}
index f5ac56538e2d397ee3bb1b13fc18da4b492859b6..559a92c99739b189c91a9aca3e6085b060d71d83 100644 (file)
@@ -46,6 +46,7 @@ namespace YACS
       void getWeightRegardingDPL(ComplexWeight *weight);
       void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const;
       std::string getRepr() const;
+      void accept(PointVisitor *pv) override;
       virtual ~ElementaryPoint();
     };
   }
index 8b8768f1c3813308fd7424a86e096a3b2bac9dd7..5234cecf379046f35e8b55a4450c369f6683d635 100644 (file)
@@ -18,6 +18,7 @@
 //
 
 #include "ForkBlocPoint.hxx"
+#include "PointVisitor.hxx"
 #include "Exception.hxx"
 
 #include <algorithm>
@@ -109,3 +110,11 @@ std::string ForkBlocPoint::getRepr() const
   ret+="]";
   return ret;
 }
+
+void ForkBlocPoint::accept(PointVisitor *pv)
+{
+  pv->beginForkBlocPoint(this);
+  for(auto it:_nodes)
+    it->accept(pv);
+  pv->endForkBlocPoint(this);
+}
index 2c347caf21aebb1620b028247fd926ef89f418e3..067155d808bce7e0eec98b8c459f0d95ce653d4d 100644 (file)
@@ -37,6 +37,7 @@ namespace YACS
       void getWeightRegardingDPL(ComplexWeight *weight);
       void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const;
       std::string getRepr() const;
+      void accept(PointVisitor *pv) override;
       virtual ~ForkBlocPoint();
     };
   }
index b4d2e7f2f116193d763a731d33de19a433b20565..e9c32e8f5b69c8606a37dda1cfed25e0b5331e5f 100644 (file)
@@ -18,6 +18,7 @@
 //
 
 #include "LinkedBlocPoint.hxx"
+#include "PointVisitor.hxx"
 #include "Exception.hxx"
 
 using namespace YACS::ENGINE;
@@ -79,6 +80,14 @@ std::string LinkedBlocPoint::getRepr() const
   return ret;
 }
 
+void LinkedBlocPoint::accept(PointVisitor *pv)
+{
+  pv->beginLinkedBlocPoint(this);
+  for(auto it:_nodes)
+    it->accept(pv);
+  pv->endLinkedBlocPoint(this);
+}
+
 LinkedBlocPoint::~LinkedBlocPoint()
 {
 }
index 3491ed40712fdf281faef1d4299b50f27bf015a3..d0f5f20ac1144d7afd02fbbe1ceedb0dd982ee67 100644 (file)
@@ -39,6 +39,7 @@ namespace YACS
       void getWeightRegardingDPL(ComplexWeight *weight);
       void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const;
       std::string getRepr() const;
+      void accept(PointVisitor *pv) override;
       virtual ~LinkedBlocPoint();
     };
   }
diff --git a/src/engine/PointVisitor.hxx b/src/engine/PointVisitor.hxx
new file mode 100644 (file)
index 0000000..9d9b17f
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright (C) 2015-2016  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#pragma once
+
+#include "YACSlibEngineExport.hxx"
+
+namespace YACS
+{
+  namespace ENGINE
+  {
+    class ElementaryPoint;
+    class LinkedBlocPoint;
+    class ForkBlocPoint;
+    
+    class YACSLIBENGINE_EXPORT PointVisitor
+    {
+    public:
+      virtual void beginForkBlocPoint(ForkBlocPoint *pt) = 0;
+      virtual void endForkBlocPoint(ForkBlocPoint *pt) = 0;
+      virtual void beginLinkedBlocPoint(LinkedBlocPoint *pt) = 0;
+      virtual void endLinkedBlocPoint(LinkedBlocPoint *pt) = 0;
+      virtual void beginElementaryPoint(ElementaryPoint *pt) = 0;
+      virtual void endElementaryPoint(ElementaryPoint *pt) = 0;
+    };
+  }
+}
index 76f892577b9db0403fa5aaf0eae719728446d1d6..f7b229088c175397c334c071ac65b6ffd7974b7a 100644 (file)
@@ -101,3 +101,8 @@ AbstractPoint *SetOfPoints::getUniqueAndReleaseIt() const
 {
   return _bp->getUniqueAndReleaseIt();
 }
+
+void SetOfPoints::accept(PointVisitor *pv)
+{
+  _bp->accept(pv);
+}
index bc29934b0d56dbc94af04bbcb9c9113394237854..11e07eeef2d765255f0e666162c30e1afee96831 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "YACSlibEngineExport.hxx"
 #include "PlayGround.hxx"
+#include "PointVisitor.hxx"
 #include "AutoRefCnt.hxx"
 
 #include <map>
@@ -50,6 +51,7 @@ namespace YACS
       void getWeightRegardingDPL(ComplexWeight *weight);
       void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const;
       AbstractPoint *getUniqueAndReleaseIt() const;
+      void accept(PointVisitor *pv);
     private:
       BagPoint *_bp;
     };
index b89d32ab72b726cd3c3b1fe355e0dc305ded81e4..96c467d8cb60a1edf0fc581edbf4bef99a0de789 100644 (file)
 #include "DataNode.hxx"
 #include "PlayGround.hxx"
 #include "SetOfPoints.hxx"
+#include "PointVisitor.hxx"
+#include "ForkBlocPoint.hxx"
+#include "LinkedBlocPoint.hxx"
+#include "ElementaryPoint.hxx"
   
 using namespace YACS::ENGINE;
 
@@ -453,6 +457,48 @@ namespace YACS
 {
   namespace ENGINE
   {
+    class AbstractPoint
+    {
+    protected:
+      virtual ~AbstractPoint();
+      AbstractPoint();
+      AbstractPoint(const AbstractPoint&);
+    };
+
+    class ElementaryPoint : public AbstractPoint
+    {
+    public:
+      Node *getFirstNode();
+    private:
+      ~ElementaryPoint();
+      ElementaryPoint();
+      ElementaryPoint(const ElementaryPoint&);
+    };
+
+    class BlocPoint : public AbstractPoint
+    {
+    protected:
+      ~BlocPoint();
+      BlocPoint();
+      BlocPoint(const BlocPoint&);
+    };
+
+    class LinkedBlocPoint : public BlocPoint
+    {
+    private:
+      ~LinkedBlocPoint();
+      LinkedBlocPoint();
+      LinkedBlocPoint(const LinkedBlocPoint&);
+    };
+
+    class ForkBlocPoint : public BlocPoint
+    {
+    private:
+      ~ForkBlocPoint();
+      ForkBlocPoint();
+      ForkBlocPoint(const ForkBlocPoint&);
+    };
+    
     class SetOfPoints
     {
     public:
@@ -460,6 +506,63 @@ namespace YACS
       ~SetOfPoints();
       void simplify();
       std::string getRepr() const;
+      %extend
+      {
+      void accept(PyObject *pv)
+      {
+        class MyPointVisitor : public YACS::ENGINE::PointVisitor
+        {
+        public:
+          MyPointVisitor(PyObject *py):_py(py) { }
+          void beginForkBlocPoint(ForkBlocPoint *pt)
+          {
+            PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__ForkBlocPoint,0));
+            PyObject *meth(PyString_FromString("beginForkBlocPoint"));
+            PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
+            Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
+          }
+          void endForkBlocPoint(ForkBlocPoint *pt)
+          {
+            PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__ForkBlocPoint,0));
+            PyObject *meth(PyString_FromString("endForkBlocPoint"));
+            PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
+            Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
+          }
+          void beginLinkedBlocPoint(LinkedBlocPoint *pt)
+          {
+            PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__LinkedBlocPoint,0));
+            PyObject *meth(PyString_FromString("beginLinkedBlocPoint"));
+            PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
+            Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
+          }
+          void endLinkedBlocPoint(LinkedBlocPoint *pt)
+          {
+            PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__LinkedBlocPoint,0));
+            PyObject *meth(PyString_FromString("endLinkedBlocPoint"));
+            PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
+            Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
+          }
+          void beginElementaryPoint(ElementaryPoint *pt)
+          {
+            PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__ElementaryPoint,0));//$descriptor(YACS::ENGINE::ElementaryPoint *)
+            PyObject *meth(PyString_FromString("beginElementaryPoint"));
+            PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
+            Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
+          }
+          void endElementaryPoint(ElementaryPoint *pt)
+          {
+            PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__ElementaryPoint,0));
+            PyObject *meth(PyString_FromString("endElementaryPoint"));
+            PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
+            Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
+          }
+        private:
+          PyObject *_py;
+        };
+        MyPointVisitor mpv(pv);
+        self->accept(&mpv);
+        }
+      }
     };
   }
 }