Version: 9.15.0
XMLCppConv.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2025 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 "TypeConversions.hxx"
21 #include "XMLCppConv.hxx"
22 
23 
24 #include <libxml/parser.h>
25 #include <iostream>
26 #include <sstream>
27 #include "Any.hxx"
28 
29 //#define _DEVDEBUG_
30 #include "YacsTrace.hxx"
31 
32 using namespace std;
33 
34 namespace YACS
35 {
36  namespace ENGINE
37  {
38  Any * convertXmlCpp(const TypeCode *t, xmlDocPtr doc, xmlNodePtr cur)
39  {
40  return convertXmlNeutral(t, doc, cur);
41  }
42 
43  XmlCpp::XmlCpp(InputPort* p)
44  : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode())
45  {
46  }
47 
48  void XmlCpp::put(const void *data)
49  {
50  DEBTRACE(" XmlCpp::put(const void *data)");
51  put((const char *)data);
52  }
53 
55 
59  void XmlCpp::put(const char *data)
60  {
61  DEBTRACE("XmlCpp::put " << data);
62  xmlDocPtr doc;
63  xmlNodePtr cur;
64  Any *ob=NULL;
65  {
66  doc = xmlParseMemory(data, strlen(data));
67  if (doc == NULL )
68  {
69  stringstream msg;
70  msg << "Problem in conversion: XML Document not parsed successfully ";
71  msg << " (" << __FILE__ << ":" << __LINE__ << ")";
72  throw ConversionException(msg.str());
73  }
74  cur = xmlDocGetRootElement(doc);
75  if (cur == NULL)
76  {
77  xmlFreeDoc(doc);
78  stringstream msg;
79  msg << "Problem in conversion: empty XML Document";
80  msg << " (" << __FILE__ << ":" << __LINE__ << ")";
81  throw ConversionException(msg.str());
82  }
83  while (cur != NULL)
84  {
85  if ((!xmlStrcmp(cur->name, (const xmlChar *)"value")))
86  {
87  ob=convertXmlCpp(edGetType(),doc,cur);
88  break;
89  }
90  cur = cur->next;
91  }
92  xmlFreeDoc(doc);
93  if(ob==NULL)
94  {
95  stringstream msg;
96  msg << "Problem in conversion: incorrect XML value";
97  msg << " (" << __FILE__ << ":" << __LINE__ << ")";
98  throw ConversionException(msg.str());
99  }
100  }
101  _port->put(ob);
102  ob->decrRef();
103  }
104 
106  {
107  return isAdaptableNeutralXml(t1, t2);
108  }
109  }
110 }
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
: Interface for management of storage of data formated dynamically in its TypeCode....
Definition: Any.hxx:79
TypeCode * edGetType() const
Definition: DataPort.hxx:53
Base class for Input Ports.
Definition: InputPort.hxx:44
virtual void put(const void *data)=0
Base class for all ports.
Definition: Port.hxx:43
Base class for Proxy Input Ports.
Definition: InputPort.hxx:100
Base class for all type objects.
Definition: TypeCode.hxx:68
virtual void put(const void *data)
Definition: XMLCppConv.cxx:48
Proc * p
Definition: driver.cxx:216
static char doc[]
Definition: driver.cxx:63
Any * convertXmlCpp(const TypeCode *t, xmlDocPtr doc, xmlNodePtr cur)
Definition: XMLCppConv.cxx:38
int isAdaptableCppXml(const TypeCode *t1, const TypeCode *t2)
Definition: XMLCppConv.cxx:105
int isAdaptableNeutralXml(const TypeCode *t1, const TypeCode *t2)
YACS::ENGINE::Any * convertXmlNeutral(const TypeCode *t, xmlDocPtr doc, xmlNodePtr cur)
static std::string t1[]
static std::string t2[]