Salome HOME
base64 is used to store pickelized objects into XML
[modules/yacs.git] / src / yacsloader / procParsers.hxx
index 111ab948fe8669b999c8bfc55c60718114452891..c2c112cbb5bc62f84286ef46da2e9b979c4bc0fc 100644 (file)
@@ -1,27 +1,29 @@
-//  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2019  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.
+// 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.
+// 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
+// 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #ifndef _PROCPARSER_HXX_
 #define _PROCPARSER_HXX_
 
 #include "blocParsers.hxx"
 #include "typeParsers.hxx"
 #include "containerParsers.hxx"
+#include "componentinstanceParsers.hxx"
 #include "nodeParsers.hxx"
 
 #include "Proc.hxx"
@@ -49,40 +51,88 @@ struct proctypeParser: bloctypeParser<T>
   virtual void onEnd(const char *el,parser* child);
   virtual void buildAttr(const XML_Char** attr)
     {
+         if (!attr)
+               return;
       for (int i = 0; attr[i]; i += 2) 
         {
-          if(std::string(attr[i]) == "state")this->state(attr[i+1]);
+          if(std::string(attr[i]) == "state")
+            this->state(attr[i+1]);
+          if(std::string(attr[i]) == "name")
+            name(attr[i+1]);
         }
     }
-  virtual void pre ()
+  virtual void pre()
     {
         std::string name("proc");
         currentProc=theRuntime->createProc(name);
         this->_bloc=currentProc;
         currentProc->names.push_back("");
     }
-  virtual void type (const mytype& t)
+
+  virtual void name(const std::string& name)
+    {
+      currentProc->setName(name);
+    }
+
+  virtual void type(const mytype& t)
     {
         DEBTRACE( "type_set" );
         YACS::ENGINE::TypeCode* tt=currentProc->createType(t._name,t._kind);
         tt->decrRef();
     }
-  virtual void sequence (ENGINE::TypeCode* const& t)
+  virtual void sequence(ENGINE::TypeCode* const& t)
     {
         DEBTRACE( "sequence_set" );
         t->decrRef();
     }
-  virtual void objref (ENGINE::TypeCode* const& t)
+  virtual void objref(ENGINE::TypeCode* const& t)
     {
         DEBTRACE( "objref_set" );
         t->decrRef();
     }
-  virtual void struct_ (ENGINE::TypeCode* const& t)
+  virtual void struct_(ENGINE::TypeCode* const& t)
     {
         DEBTRACE( "struct_set" );
         t->decrRef();
     }
-  virtual void container (const mycontainer& t)
+
+  virtual void componentinstance(const mycomponentinstance& t)
+    {
+      DEBTRACE( "componentinstance: " << t._name );
+      YACS::ENGINE::ComponentInstance* inst=currentProc->createComponentInstance(t._component,t._name,t._kind);
+
+      // Set all properties for this component instance
+      std::map<std::string, std::string>::const_iterator pt;
+      for(pt=t._props.begin();pt!=t._props.end();pt++)
+        inst->setProperty((*pt).first,(*pt).second);
+
+      //associate a container to the component instance
+      if(currentProc->containerMap.count(t._container) != 0)
+        {
+          inst->setContainer(currentProc->containerMap[t._container]);
+        }
+      else if(t._container == "")
+        {
+          if(currentProc->containerMap.count("DefaultContainer") != 0)
+          {
+            //a default container is defined : use it if supported
+            try
+            {
+              currentProc->containerMap["DefaultContainer"]->checkCapabilityToDealWith(inst);
+              inst->setContainer(currentProc->containerMap["DefaultContainer"]);
+            }
+            catch(YACS::Exception){}
+          }
+        }
+      else
+        {
+          std::cerr << "WARNING: Unknown container " << t._container << " ignored" << std::endl;
+        }
+
+      inst->decrRef();
+    }
+
+  virtual void container(const mycontainer& t)
     {
       DEBTRACE( "container_set: " << t._name )             
       std::vector<machine>::const_iterator iter;
@@ -91,23 +141,26 @@ struct proctypeParser: bloctypeParser<T>
           DEBTRACE( "machine name: " << (*iter)._name )             
         }
 
-      if(currentProc->containerMap.count(t._name) == 0)
+      if(currentProc->containerMap.count(t._name) != 0 && t._name != "DefaultContainer")
         {
-          YACS::ENGINE::Container* cont=theRuntime->createContainer();
-          cont->setName(t._name);
-          // Set all properties for this container
-          std::map<std::string, std::string>::const_iterator pt;
-          for(pt=t._props.begin();pt!=t._props.end();pt++)
-            cont->setProperty((*pt).first,(*pt).second);
-          currentProc->containerMap[t._name]=cont;
+          std::cerr << "Warning: container " << t._name << " already defined. It will be ignored" << std::endl;
         }
       else
         {
-          std::cerr << "Warning: container " << t._name << " already defined. It will be ignored" << std::endl;
+          // Set all properties for this container
+          std::string kindOfContainer;
+          std::map<std::string, std::string>::const_iterator pt(t._props.find(std::string(ENGINE::Container::KIND_ENTRY)));
+          if(pt!=t._props.end())
+            kindOfContainer=pt->second;
+          YACS::ENGINE::Container *cont(currentProc->createContainer(t._name,kindOfContainer));
+          for(pt=t._props.begin();pt!=t._props.end();pt++)
+            if((*pt).second!=ENGINE::Container::KIND_ENTRY)
+              cont->setProperty((*pt).first,(*pt).second);
+          cont->decrRef();
         }
     }
 
-  T post(){return this->_bloc;}
+  T post() { return this->_bloc; }
 };
 
 template <class T> proctypeParser<T> proctypeParser<T>::procParser;
@@ -129,10 +182,13 @@ void proctypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
     else if(element == "objref")pp=&objtypeParser::objParser;
     else if(element == "struct")pp=&structtypeParser::structParser;
     else if(element == "container")pp=&containertypeParser::containerParser;
+    else if(element == "componentinstance")pp=&componentinstancetypeParser::componentinstanceParser;
 
     else if(element == "inline")pp=&inlinetypeParser<>::inlineParser;
     else if(element == "sinline")pp=&sinlinetypeParser<>::sinlineParser;
     else if(element == "service")pp=&servicetypeParser<>::serviceParser;
+    else if(element == "server")pp=&servertypeParser<>::serverParser;
+    else if(element == "remote")pp=&remotetypeParser<>::remoteParser;
     else if(element == "node")pp=&nodetypeParser<>::nodeParser;
     else if(element == "datanode")pp=&presettypeParser<>::presetParser;
     else if(element == "outnode")pp=&outnodetypeParser<>::outnodeParser;
@@ -140,6 +196,7 @@ void proctypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
     else if(element == "bloc")pp=&bloctypeParser<>::blocParser;
     else if(element == "forloop")pp=&forlooptypeParser<>::forloopParser;
     else if(element == "foreach")pp=&foreachlooptypeParser<>::foreachloopParser;
+    else if(element == "optimizer")pp=&optimizerlooptypeParser<>::optimizerloopParser;
     else if(element == "while")pp=&whilelooptypeParser<>::whileloopParser;
     else if(element == "switch")pp=&switchtypeParser::switchParser;
 
@@ -160,7 +217,7 @@ void proctypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
               }
             else
               {
-                std::cerr << "There is no parser for this element type. It will be ignored!" << std::endl;
+                std::cerr << "There is no parser for this element type. It will be ignored! " << element << std::endl;
               }
           }
       }
@@ -181,10 +238,13 @@ void proctypeParser<T>::onEnd(const char *el,parser* child)
       else if(element == "objref")objref(((objtypeParser*)child)->post());
       else if(element == "struct")struct_(((structtypeParser*)child)->post());
       else if(element == "container")container(((containertypeParser*)child)->post());
+      else if(element == "componentinstance")componentinstance(((componentinstancetypeParser*)child)->post());
 
       else if(element == "inline")this->inline_(((inlinetypeParser<>*)child)->post());
       else if(element == "sinline")this->sinline(((sinlinetypeParser<>*)child)->post());
       else if(element == "service")this->service(((servicetypeParser<>*)child)->post());
+      else if(element == "server")this->server(((servertypeParser<>*)child)->post());
+      else if(element == "remote")this->remote(((remotetypeParser<>*)child)->post());
       else if(element == "node")this->node(((nodetypeParser<>*)child)->post());
       else if(element == "datanode")this->preset(((presettypeParser<>*)child)->post());
       else if(element == "outnode")this->outnode(((outnodetypeParser<>*)child)->post());
@@ -192,6 +252,7 @@ void proctypeParser<T>::onEnd(const char *el,parser* child)
       else if(element == "bloc")this->bloc(((bloctypeParser<>*)child)->post());
       else if(element == "forloop")this->forloop(((forlooptypeParser<>*)child)->post());
       else if(element == "foreach")this->foreach(((foreachlooptypeParser<>*)child)->post());
+      else if(element == "optimizer")this->optimizer(((optimizerlooptypeParser<>*)child)->post());
       else if(element == "while")this->while_(((whilelooptypeParser<>*)child)->post());
       else if(element == "switch")this->switch_(((switchtypeParser*)child)->post());