1 // Copyright (C) 2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : CalciumGenericProvidesPort.hxx
23 // Author : Eric Fayolle (EDF)
27 #ifndef _CALCIUM_GENERIC_PROVIDES_PORT_HXX_
28 #define _CALCIUM_GENERIC_PROVIDES_PORT_HXX_
30 #include "PortProperties_i.hxx"
32 #include "calcium_provides_port.hxx"
34 #include "GenericProvidesPort.hxx"
35 #include "CalciumCouplingPolicy.hxx"
37 #include "CorbaTypes2CalciumTypes.hxx"
38 #include "CalciumTypes2CorbaTypes.hxx"
40 #include "DSC_Exception.hxx"
44 // Cette macro CPP remplace une déclaration : template <typename CorbaInterface, typename CorbaDataManipulator >
45 // mais permet surtout de générer différentes classes (dont le nom est spécifié par specificPortName )
47 // Variante: Creer un trait qui à partir de CorbaInterface déduit CorbaDataManipulator
48 // et simplifier la classe
50 // L'utilisation conjointe du paramètre ... et de __VA_ARGS__ au lieu d'un 'CorbaDataManipulator' permet
51 // d'invoquer la macro avec un troisième token contenant une virgule
52 // (qui est considéré comme un séparateur d'argument par le PP )
54 #define CALCIUM_GENERIC_PROVIDES_PORT_HXX(specificPortName,CorbaInterface,...) \
55 class specificPortName : public virtual CorbaInterface , \
56 public virtual POA_Ports::PortProperties, \
57 public GenericProvidesPort< __VA_ARGS__ , CalciumCouplingPolicy, calcium_provides_port > { \
59 typedef __VA_ARGS__ DataManipulator; \
60 typedef DataManipulator::Type CorbaDataType; \
61 typedef GenericPort< DataManipulator , \
62 CalciumCouplingPolicy > Port; \
64 virtual ~ specificPortName (); \
66 inline void disconnect(bool provideLastGivenValue) { \
67 Port::disconnect(provideLastGivenValue); \
69 inline void setDependencyType(CalciumTypes::DependencyType dependencyType) { \
70 Port::setDependencyType(dependencyType); \
72 inline CalciumTypes::DependencyType getDependencyType () const { \
73 return Port::getDependencyType(); \
75 inline void setStorageLevel (size_t storageLevel) { \
76 Port::setStorageLevel(storageLevel); \
78 inline size_t getStorageLevel () const { \
79 return Port::getStorageLevel(); \
81 inline void setDateCalSchem (CalciumTypes::DateCalSchem dateCalSchem) { \
82 Port::setDateCalSchem (dateCalSchem); \
84 inline CalciumTypes::DateCalSchem getDateCalSchem () const { \
85 return Port::getDateCalSchem (); \
87 inline void setAlpha(double alpha) { \
88 Port::setAlpha(alpha); \
90 inline double getAlpha() const { \
91 return Port::getAlpha(); \
93 inline void setDeltaT(double deltaT ) { \
94 Port::setDeltaT(deltaT); \
96 inline double getDeltaT() const { \
97 return Port::getDeltaT(); \
99 inline void setInterpolationSchem (CalciumTypes::InterpolationSchem interpolationSchem) { \
100 Port::setInterpolationSchem(interpolationSchem); \
102 inline void setExtrapolationSchem (CalciumTypes::ExtrapolationSchem extrapolationSchem) { \
103 Port::setExtrapolationSchem(extrapolationSchem); \
105 inline CalciumTypes::InterpolationSchem getInterpolationSchem() const { \
106 return Port::getInterpolationSchem(); \
108 inline CalciumTypes::ExtrapolationSchem getExtrapolationSchem() const { \
109 return Port::getExtrapolationSchem(); \
112 inline void put( DataManipulator::CorbaInType data, \
113 CORBA::Double time, CORBA::Long tag) { \
114 Port::put(data, time, tag); \
117 inline Ports::Port_ptr get_port_ref() { \
121 Ports::PortProperties_ptr get_port_properties() { \
122 return POA_Ports::PortProperties::_this(); \
125 virtual void set_property(const char * name, const CORBA::Any& value) \
126 throw (Ports::NotDefined, Ports::BadType, Ports::BadValue); \
128 virtual CORBA::Any* get_property(const char* name) \
129 throw (Ports::NotDefined); \
131 virtual void provides_port_changed(int connection_nbr, \
132 const Engines::DSC::Message message) { \
133 if ( !connection_nbr && (message == Engines::DSC::RemovingConnection) ) \
143 #define CALCIUM_GENERIC_PROVIDES_PORT_CXX(specificPortName) \
145 specificPortName::~specificPortName(void) {}; \
147 void specificPortName::set_property(const char * name, const CORBA::Any& value) \
148 throw (Ports::NotDefined, Ports::BadType, Ports::BadValue) { \
150 const std::string key(name); \
152 CORBA::Double alpha,delta; \
153 Ports::Calcium_Ports::DependencyType dt; \
154 Ports::Calcium_Ports::DateCalSchem dcs; \
155 Ports::Calcium_Ports::InterpolationSchem is; \
156 Ports::Calcium_Ports::ExtrapolationSchem es; \
161 if (key == "StorageLevel" ) \
162 {if ( ok=(value >>= sl) ) Port::setStorageLevel(sl);} \
163 else if (key == "Alpha" ) \
164 {if ( ok=(value >>= alpha) ) Port::setAlpha(alpha);} \
165 else if (key == "DeltaT" ) \
166 {if ( ok=(value >>= delta) ) Port::setDeltaT(delta);} \
167 else if (key == "DependencyType" ) \
168 {if ( ok=( value >>= dt) ) Port::setDependencyType(dependencyType[dt]);} \
169 else if (key == "DateCalSchem" ) \
170 {if ( ok=(value >>= dcs) ) \
171 Port::setDateCalSchem(dateCalSchem[dcs]);} \
172 else if (key == "InterpolationSchem") \
173 {if ( ok=(value >>= is) ) \
174 Port::setInterpolationSchem(interpolationSchem[is]);} \
175 else if (key == "ExtrapolationSchem") \
176 {if ( ok=(value >>= es) ) \
177 Port::setExtrapolationSchem(extrapolationSchem[es]);} \
179 throw Ports::NotDefined(); \
180 if (!ok) throw Ports::BadType(); \
182 } catch ( const DSC_Exception & ex ) { \
184 std::cerr << ex.what() << std::endl; \
185 throw Ports::BadValue(); \
190 CORBA::Any* specificPortName::get_property(const char* name) \
191 throw (Ports::NotDefined) { \
192 const std::string key(name); \
193 CORBA::Any* value=new CORBA::Any; \
194 if (key == "StorageLevel" ) \
195 { (*value) <<= static_cast<CORBA::Long>(Port::getStorageLevel()); } \
196 else if (key == "Alpha" ) \
197 { *value <<= (CORBA::Double) Port::getAlpha();} \
198 else if (key == "DeltaT" ) \
199 { *value <<= (CORBA::Double) Port::getDeltaT();} \
200 else if (key == "DependencyType" ) \
201 { *value <<= corbaDependencyType[Port::getDependencyType()];} \
202 else if (key == "DateCalSchem" ) \
203 { *value <<= corbaDateCalSchem[Port::getDateCalSchem()];} \
204 else if (key == "InterpolationSchem") \
205 { *value <<= corbaInterpolationSchem[Port::getInterpolationSchem()];} \
206 else if (key == "ExtrapolationSchem") \
207 { *value <<= corbaExtrapolationSchem[Port::getExtrapolationSchem()];} \
210 throw Ports::NotDefined(); \