]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphBase/DataFlowBase_DataPort.cxx
Salome HOME
NRI : First integration.
[modules/superv.git] / src / GraphBase / DataFlowBase_DataPort.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : DataFlowBase_DataPort.cxx
4 // Created   : 2002
5 // Author    : Jean Rahuel, CEA
6 // Project   : SALOME
7 // $Header:
8 //=============================================================================
9
10 #include "DataFlowBase_DataPort.hxx"
11
12 GraphBase::DataPort::DataPort(
13          const char *const * NodeName  ,
14          const SALOME_ModuleCatalog::ServicesParameter aserviceParameter ) :
15               Port( NodeName , aserviceParameter ) {
16   InitialValues( CORBA::Any() ) ;
17 }
18
19 GraphBase::DataPort::~DataPort() {
20 }
21
22 void GraphBase::DataPort::InitialValues(CORBA::Any aValue ) {
23   _theValue = new CORBA::Any( aValue ) ;
24   string _Type = CORBA::string_dup(GetServicesParameter().Parametertype) ;
25   const char * Type = _Type.c_str();
26   CORBA::Any InitialValue ;
27   cdebug << "InitialValues " << NodeName() << " " << PortName() << " " << PortType()
28          << " : " ;
29   if ( !strcmp( Type , "string" ) ) {
30     cdebug << "string" << endl ;
31     InitialValue <<= (char *) NULL ;
32   }
33   else if ( !strcmp( Type , "double" ) ) {
34     cdebug << "double" << endl ;
35     InitialValue <<= 0. ;
36   }
37   else if ( !strcmp( Type , "long" ) ) {
38     cdebug << "long" << endl ;
39     InitialValue <<= (long ) 0 ;
40   }
41   else if ( !strcmp( Type , "objref" ) ) {
42     cdebug << "objref" << endl ;
43     InitialValue.replace(CORBA::_tc_Object, NULL);
44   }
45   else {
46     cdebug << "InitialValues ERROR (other) " << Type << endl ;
47     InitialValue <<= (long ) 0 ;
48   }
49   _InitialValue = new CORBA::Any( InitialValue ) ;
50   _Value = &_InitialValue ;
51 }
52
53 void GraphBase::DataPort::Value( const CORBA::Any & aDataValue ) {
54   Value( new CORBA::Any( aDataValue ) ) ;
55 }
56
57 void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) {
58   delete _theValue ;
59   _theValue = aDataValue ;
60   *_Value = aDataValue ;
61 //  Done( true ) ;
62
63 //#if 0
64   cdebug << "NewValue " << NodeName() << " " << PortName() << " " << PortType()
65          << " : " << _Value << " *_Value " << *_Value  << " " ;
66   switch (_theValue->type()->kind()) {
67   case CORBA::tk_string: {
68     char * t;
69     *_theValue >>= t;
70     cdebug << "Value( " << t << ") (string)";
71     break;
72   }
73   case CORBA::tk_double: {
74     double d;
75     *_theValue >>= d;
76     cdebug << "Value( " << d << ") (double)";
77     break;
78   }
79   case CORBA::tk_long: {
80     long l;
81     *_theValue >>= l;
82     cdebug << "Value( " << l << ") (long)";
83     break;
84   }
85   case CORBA::tk_objref: {
86     cdebug << "Value( " << ") (object reference)";
87     break;
88   }
89   default: {
90     cdebug << "Value" << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR";
91     break;
92   }
93   }
94   cdebug << endl;
95 //#endif
96
97 }
98
99 void GraphBase::DataPort::Value( const CORBA::Any ** aDataSharedValue ) {
100   delete _theValue ;
101   _theValue = *aDataSharedValue ;
102   _Value = aDataSharedValue ;
103 //  Done( true ) ;
104
105 #if 0
106   MESSAGE( NodePortName() << " : " << hex << _Value << " " );
107   switch (_theValue->type()->kind()) {
108   case CORBA::tk_string:
109     char * t;
110     *_theValue >>= t;
111     MESSAGE( "Value( " << t << ") (string)");
112     break;
113   case CORBA::tk_double:
114     double d;
115     *_theValue >>= d;
116     MESSAGE( "Value( " << d << ") (double)");
117     break;
118   case CORBA::tk_long:
119     long l;
120     *_theValue >>= l;
121     MESSAGE( "Value( " << l << ") (long)");
122     break;
123   case CORBA::tk_objref:
124     MESSAGE( "Value( " << ") (object reference)");
125     break;
126   default:
127     MESSAGE( "Value" << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR");
128     break;
129   }
130   MESSAGE();
131 #endif
132 }
133
134 CORBA::Any const * GraphBase::DataPort::Value() const {
135   const CORBA::Any *const Value = *_Value ;
136   CORBA::Any * theValue ;
137   cdebug  << "Value " << NodeName() << " " << PortName() << " " << PortType()
138          << " _Value " << _Value << " *_Value " << *_Value  << " " ;
139   if ( Done() ) {
140     theValue = new CORBA::Any( *Value ) ;
141     switch (theValue->type()->kind()) {
142     case CORBA::tk_string: {
143       char * t;
144       *theValue >>= t;
145       cdebug << "GraphBase::DataPort::Value() : " << t << " (string) " << endl;
146       break;
147     }
148     case CORBA::tk_double: {
149       double d;
150       *theValue >>= d;
151       cdebug << "GraphBase::DataPort::Value() : " << d << " (double) " << endl;
152       break;
153     }
154     case CORBA::tk_long: {
155       long l;
156       *theValue >>= l;
157       cdebug << "GraphBase::DataPort::Value() : " << l << " (long) " << endl;
158       break;
159     }
160     case CORBA::tk_objref: {
161       CORBA::Object_ptr obj ;
162       char * retstr ;
163       try {
164         *theValue >>= obj ;
165         retstr = ObjectToString( obj );
166         cdebug << "GraphBase::DataPort::Value() : " << retstr
167                << "(object reference) " << endl;
168       }
169       catch( ... ) {
170         cdebug << "ToString( object ) Catched ERROR" << endl ;
171       }
172       break;
173     }
174     default: {
175       cdebug << "GraphBase::DataPort::Value() : "
176              << "(other(tk_string,tk_double,tk_long,tk_objref)) ERROR" << endl;
177       break;
178     }
179     }
180   }
181   else {
182     cdebug << "GraphBase::DataPort::InitialValue() " << endl;
183     theValue = new CORBA::Any( *Value ) ;
184   }
185     
186   return theValue ;
187 }
188
189 bool GraphBase::DataPort::BoolValue() const {
190   bool RetVal = false ;
191   long val ;
192   if ( (*_Value)->type()->kind() == CORBA::tk_long ) {
193     **_Value >>= val ;
194     if ( val ) {
195       RetVal = true ;
196     }
197   }
198   return RetVal ;
199 }
200
201 const CORBA::Any ** GraphBase::DataPort::ValuePtr() const {
202   return _Value ;
203 }
204
205 void GraphBase::DataPort::StringValue(ostream & f ) const {
206   if ( Done() ) {
207     cdebug << "StringValue " << NodeName() << " " << PortName() << " " << PortType()
208            << " _Value "  << _Value << " *_Value "
209            << *_Value  << " " << endl ;
210     const CORBA::Any * theValue = *_Value ;
211     switch (theValue->type()->kind()) {
212     case CORBA::tk_string:
213       char * t;
214       *theValue >>= t;
215       f << t << " (string)" ;
216       break;
217     case CORBA::tk_double:
218       double d;
219       *theValue >>= d;
220       f << d << " (double)" ;
221       break;
222     case CORBA::tk_long:
223       long l;
224       *theValue >>= l;
225       f << l << " (long)" ;
226       break;
227     case CORBA::tk_objref:
228       f << "(object reference)" ;
229       break;
230     default:
231       f << "(other ERROR)" ;
232       break;
233     }
234   }
235   else {
236     f << "Default(undefined)"  ;
237   }
238     
239 }
240
241