Salome HOME
updated copyright message
[modules/yacs.git] / src / engine / InPropertyPort.cxx
1 // Copyright (C) 2006-2023  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 "InPropertyPort.hxx"
21 #include "Node.hxx"
22 #include "TypeCode.hxx"
23
24 //#define _DEVDEBUG_
25 #include "YacsTrace.hxx"
26
27 using namespace YACS::ENGINE;
28 using namespace std;
29
30 const char InPropertyPort::NAME[]="InPropertyPort";
31
32 InPropertyPort::InPropertyPort(const InPropertyPort& other, Node *newHelder)
33   : InputPort(other, newHelder),
34     DataPort(other, newHelder),
35     Port(other, newHelder),
36     _property_data(NULL), _init_property_data(NULL)
37 {}
38
39 InPropertyPort::InPropertyPort(const std::string& name, Node *node, TypeCode* type, bool canBeNull)
40   : InputPort(name, node, type, canBeNull),
41     DataPort(name, node, type),
42     Port(node),
43     _property_data(NULL), _init_property_data(NULL)
44 {
45 }
46
47 InPropertyPort::~InPropertyPort() {}
48
49 string InPropertyPort::getNameOfTypeOfCurrentInstance() const
50 {
51   return NAME;
52 }
53
54 void
55 InPropertyPort::exNewPropertyValue(const std::string & name, const std::string & value)
56 {
57   DEBTRACE("Adding new Property to the node " << name << " " << value);
58   _node->setProperty(name, value);
59 }
60
61 void
62 InPropertyPort::exSaveInit()
63 {
64   _init_property_data = _property_data;
65 }
66
67 void
68 InPropertyPort::exRestoreInit()
69 {
70   if(!_init_property_data)return;
71   _property_data = _init_property_data;
72 }
73
74 InPropertyPort *
75 InPropertyPort::clone(Node *newHelder) const
76 {
77   return new InPropertyPort(*this,newHelder);
78 }
79
80 void *
81 InPropertyPort::get() const
82 {
83   return (void*) _property_data;
84 }
85
86 void
87 InPropertyPort::put(const void *data)
88 {
89   put((YACS::ENGINE::Any *)data);
90 }
91
92 void InPropertyPort::releaseData()
93 {
94   if(_property_data)
95     _property_data->decrRef();
96   _property_data = nullptr;
97 }
98
99 void
100 InPropertyPort::put(YACS::ENGINE::Any *data)
101 {
102   // Add new properties to the node
103   YACS::ENGINE::SequenceAny * seq_data = static_cast<YACS::ENGINE::SequenceAny*>(data);
104   for (int i = 0; i < seq_data->size(); i++)
105   {
106     std::string key = ((*seq_data)[i]["name"])->getStringValue();
107     std::string value = ((*seq_data)[i]["value"])->getStringValue();
108     exNewPropertyValue(key, value);
109   }
110   InPropertyPort::releaseData();
111   _property_data = data;
112   _property_data->incrRef();
113   DEBTRACE("value ref count: " << _property_data->getRefCnt());
114 }