Version: 9.16.0
ProcCataLoader.cxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
2//
3// This library is free software; you can redistribute it and/or
4// modify it under the terms of the GNU Lesser General Public
5// License as published by the Free Software Foundation; either
6// version 2.1 of the License, or (at your option) any later version.
7//
8// This library is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// Lesser General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public
14// License along with this library; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20#include "ProcCataLoader.hxx"
21#include "parsers.hxx"
22#include "Proc.hxx"
23#include "Logger.hxx"
24#include "TypeCode.hxx"
25
26#include <set>
27#include <iostream>
28#include <sstream>
29#include <stdexcept>
30
31
32//#define _DEVDEBUG_
33#include "YacsTrace.hxx"
34
35using namespace YACS::ENGINE;
36
37ProcCataLoader::ProcCataLoader(YACS::YACSLoader* xmlLoader,const std::string& path):CatalogLoader(path),_xmlLoader(xmlLoader)
38{
39 //path should be a file path
40}
41
43{
44 DEBTRACE ("ProcCataLoader::~ProcCataLoader");
45}
46
48{
49 DEBTRACE("ProcCataLoader::load");
50 Proc* p;
51 try
52 {
53 p=_xmlLoader->load(_path.c_str());
54 if(p==0)
55 {
56 std::string msg="the file is probably not a YACS schema file";
57 cata->setErrors(msg);
58 std::cerr << msg << std::endl;
59 return;
60 }
61 }
62 catch (YACS::Exception& e)
63 {
64 std::string msg="Caught a YACS exception";
65 msg=msg + e.what();
66 std::cerr << msg << std::endl;
67 cata->setErrors(msg);
68 return ;
69 }
70 catch (const std::invalid_argument& e)
71 {
72 cata->setErrors(e.what());
73 return ;
74 }
75 catch (const std::ios_base::failure&)
76 {
77 std::string msg="Caught an io failure exception";
78 std::cerr << msg << std::endl;
79 cata->setErrors(msg);
80 return ;
81 }
82
83 //Get the parser logger
84 Logger* logger=p->getLogger("parser");
85 //Print errors logged if any
86 if(!logger->isEmpty())
87 {
88 std::string msg=logger->getStr();
89 std::cerr << msg << std::endl;
90 cata->setErrors(msg);
91 }
92
93 std::map<std::string,TypeCode*>& typeMap=cata->_typeMap;
94 std::map<std::string,Node*>& nodeMap=cata->_nodeMap;
95 std::map<std::string,ComposedNode*>& composednodeMap=cata->_composednodeMap;
96 std::map<std::string,ComponentDefinition*>& componentMap=cata->_componentMap;
97
98 std::map<std::string,TypeCode*>::iterator it=p->typeMap.begin();
99 while(it != p->typeMap.end())
100 {
101 typeMap[it->first]=it->second;
102 it->second->incrRef();
103 it++;
104 }
105
106 std::list<Node *> s=p->getChildren();
107 for(std::list<Node *>::iterator iter=s.begin();iter!=s.end();iter++)
108 {
109 YACS::ENGINE::ComposedNode * cnode= dynamic_cast<YACS::ENGINE::ComposedNode *>(*iter);
110 if(cnode)
111 composednodeMap[cnode->getName()]=(YACS::ENGINE::ComposedNode *) cnode->clone(0);
112 else
113 nodeMap[(*iter)->getName()]=(*iter)->clone(0);
114 }
115 delete p;
116}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
std::list< Node * > getChildren() const
Definition: Bloc.hxx:57
class for YACS catalog loader.
Definition: Catalog.hxx:63
class for YACS catalogs.
Definition: Catalog.hxx:42
void setErrors(const std::string &errors)
Definition: Catalog.hxx:48
std::map< std::string, ComposedNode * > _composednodeMap
Definition: Catalog.hxx:52
std::map< std::string, ComponentDefinition * > _componentMap
Definition: Catalog.hxx:50
std::map< std::string, Node * > _nodeMap
Definition: Catalog.hxx:51
std::map< std::string, TypeCode * > _typeMap
Definition: Catalog.hxx:49
Base class for all composed nodes.
std::string getName() const
Class for logging error messages.
Definition: Logger.hxx:38
virtual bool isEmpty()
Definition: Logger.cxx:96
virtual std::string getStr()
Definition: Logger.cxx:85
Node * clone(ComposedNode *father, bool editionOnly=true) const
This method MUST NEVER BE VIRTUAL
Definition: Node.cxx:131
virtual void loadCata(Catalog *cata)
YACS::YACSLoader * _xmlLoader
Base class for all schema objects.
Definition: Proc.hxx:44
virtual Logger * getLogger(const std::string &name)
Definition: Proc.cxx:431
std::map< std::string, TypeCode * > typeMap
Definition: Proc.hxx:90
const char * what(void) const noexcept
Definition: Exception.cxx:50
virtual YACS::ENGINE::Proc * load(const char *filename)
Definition: parsers.cxx:63
Proc * p
Definition: driver.cxx:216