2 #include "ace/ETCL/ETCL_Constraint_Visitor.h"
4 #include "tao/AnyTypeCode/AnyTypeCode_methods.h"
5 #include "tao/AnyTypeCode/Any_Unknown_IDL_Type.h"
6 #include "tao/AnyTypeCode/TypeCode.h"
7 #include "tao/AnyTypeCode/Any.h"
9 #include "tao/SystemException.h"
11 #include "tao/ETCL/TAO_ETCL_Constraint.h"
13 #if ! defined (__ACE_INLINE__)
14 #include "tao/ETCL/TAO_ETCL_Constraint.inl"
15 #endif /* __ACE_INLINE__ */
17 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
19 TAO_ETCL_Literal_Constraint::TAO_ETCL_Literal_Constraint (
20 const TAO_ETCL_Literal_Constraint
& lit
)
21 : ETCL_Literal_Constraint (),
27 TAO_ETCL_Literal_Constraint::TAO_ETCL_Literal_Constraint (CORBA::Any
* any
)
30 CORBA::Any
& any_ref
= *any
;
31 CORBA::TypeCode_var type
= any_ref
.type ();
32 CORBA::TCKind corba_type
= CORBA::tk_null
;
36 corba_type
= type
->kind ();
38 catch (const CORBA::Exception
&)
40 // @@ Seth: Don't know what else to do. Make sure we can tell
41 // when this constructor fails.
46 TAO_ETCL_Literal_Constraint::comparable_type (type
.in ());
51 this->op_
.integer_
= 0;
53 if (corba_type
== CORBA::tk_short
)
57 this->op_
.integer_
= (CORBA::Long
) sh
;
61 any_ref
>>= this->op_
.integer_
;
65 case ACE_ETCL_UNSIGNED
:
66 this->op_
.uinteger_
= 0;
68 if (corba_type
== CORBA::tk_ushort
)
72 this->op_
.uinteger_
= (CORBA::ULong
) sh
;
74 else if (corba_type
== CORBA::tk_enum
)
76 TAO::Any_Impl
*impl
= any
->impl ();
80 TAO::Unknown_IDL_Type
*unk
=
81 dynamic_cast<TAO::Unknown_IDL_Type
*> (impl
);
85 throw CORBA::INTERNAL ();
88 // We don't want unk's rd_ptr to move, in case we are shared by
89 // another Any, so we use this to copy the state, not the buffer.
90 TAO_InputCDR
for_reading (unk
->_tao_get_cdr ());
91 for_reading
.read_ulong (this->op_
.uinteger_
);
96 impl
->marshal_value (out
);
97 TAO_InputCDR
in (out
);
98 in
.read_ulong (this->op_
.uinteger_
);
103 any_ref
>>= this->op_
.uinteger_
;
107 case ACE_ETCL_DOUBLE
:
108 if (corba_type
== CORBA::tk_float
)
112 this->op_
.double_
= (CORBA::Double
) fl
;
116 (*any
) >>= this->op_
.double_
;
120 case ACE_ETCL_BOOLEAN
:
122 CORBA::Any::to_boolean
tmp (this->op_
.bool_
);
126 case ACE_ETCL_STRING
:
130 this->op_
.str_
= CORBA::string_dup (s
);
133 case ACE_ETCL_COMPONENT
:
134 this->any_
= any
->impl ();
135 this->any_
->_add_ref ();
140 TAO_ETCL_Literal_Constraint::~TAO_ETCL_Literal_Constraint ()
144 this->any_
->_remove_ref ();
149 TAO_ETCL_Literal_Constraint::operator= (const TAO_ETCL_Literal_Constraint
& co
)
154 TAO_ETCL_Literal_Constraint::operator CORBA::Boolean () const
156 return this->ETCL_Literal_Constraint::operator ACE_CDR::Boolean ();
159 TAO_ETCL_Literal_Constraint::operator CORBA::ULong () const
163 case ACE_ETCL_COMPONENT
:
165 CORBA::ULong retval
= 0;
167 tmp
.replace (this->any_
);
168 this->any_
->_add_ref ();
173 return this->ETCL_Literal_Constraint::operator ACE_CDR::ULong ();
177 TAO_ETCL_Literal_Constraint::operator CORBA::Long () const
181 case ACE_ETCL_COMPONENT
:
183 CORBA::Long retval
= 0;
185 tmp
.replace (this->any_
);
186 this->any_
->_add_ref ();
191 return this->ETCL_Literal_Constraint::operator ACE_CDR::Long ();
195 TAO_ETCL_Literal_Constraint::operator CORBA::Double () const
199 case ACE_ETCL_COMPONENT
:
201 CORBA::Double retval
= 0.0;
203 tmp
.replace (this->any_
);
204 this->any_
->_add_ref ();
209 return this->ETCL_Literal_Constraint::operator ACE_CDR::Double ();
213 TAO_ETCL_Literal_Constraint::operator const char* () const
217 case ACE_ETCL_COMPONENT
:
219 const char *retval
= 0;
221 tmp
.replace (this->any_
);
222 this->any_
->_add_ref ();
227 return this->ETCL_Literal_Constraint::operator const char * ();
231 TAO_ETCL_Literal_Constraint::operator TAO::Any_Impl
* () const
233 return (this->type_
== ACE_ETCL_COMPONENT
) ? this->any_
: 0;
237 TAO_ETCL_Literal_Constraint::comparable_type (CORBA::TypeCode_ptr type
)
239 // Convert a CORBA::TCKind into a Literal_Type
240 Literal_Type return_value
= ACE_ETCL_UNKNOWN
;
241 CORBA::TCKind kind
= CORBA::tk_null
;
245 kind
= type
->kind ();
246 CORBA::TypeCode_var tmp
= CORBA::TypeCode::_duplicate (type
);
248 while (kind
== CORBA::tk_alias
)
250 tmp
= tmp
->content_type ();
255 catch (const CORBA::Exception
&)
259 // Since this is a top level try block, no need to check again.
263 case CORBA::tk_ushort
:
264 case CORBA::tk_ulong
:
266 case CORBA::tk_ulonglong
:
267 return_value
= ACE_ETCL_UNSIGNED
;
269 case CORBA::tk_short
:
271 case CORBA::tk_longlong
:
272 return_value
= ACE_ETCL_SIGNED
;
274 case CORBA::tk_boolean
:
275 return_value
= ACE_ETCL_BOOLEAN
;
277 case CORBA::tk_float
:
278 case CORBA::tk_double
:
279 return_value
= ACE_ETCL_DOUBLE
;
281 case CORBA::tk_string
:
282 return_value
= ACE_ETCL_STRING
;
285 return_value
= ACE_ETCL_COMPONENT
;
292 TAO_ETCL_Literal_Constraint
293 TAO_ETCL_Literal_Constraint::operator+ (const TAO_ETCL_Literal_Constraint
& rhs
)
295 Literal_Type widest_type
= this->widest_type (rhs
);
299 case ACE_ETCL_DOUBLE
:
301 CORBA::Double result
= (CORBA::Double
) *this + (CORBA::Double
) rhs
;
302 return TAO_ETCL_Literal_Constraint ((CORBA::Double
) result
);
304 case ACE_ETCL_INTEGER
:
305 case ACE_ETCL_SIGNED
:
307 CORBA::Long result
= (CORBA::Long
) *this + (CORBA::Long
) rhs
;
308 return TAO_ETCL_Literal_Constraint ((CORBA::Long
) result
);
310 case ACE_ETCL_UNSIGNED
:
312 CORBA::ULong result
= (CORBA::ULong
) *this + (CORBA::ULong
) rhs
;
313 return TAO_ETCL_Literal_Constraint ((CORBA::ULong
) result
);
316 return TAO_ETCL_Literal_Constraint ((CORBA::Long
) 0);
320 TAO_ETCL_Literal_Constraint
321 TAO_ETCL_Literal_Constraint::operator- (const TAO_ETCL_Literal_Constraint
& rhs
)
323 Literal_Type widest_type
= this->widest_type (rhs
);
327 case ACE_ETCL_DOUBLE
:
329 CORBA::Double result
= (CORBA::Double
) *this - (CORBA::Double
) rhs
;
330 return TAO_ETCL_Literal_Constraint ((CORBA::Double
) result
);
332 case ACE_ETCL_INTEGER
:
333 case ACE_ETCL_SIGNED
:
335 CORBA::Long result
= (CORBA::Long
) *this - (CORBA::Long
) rhs
;
336 return TAO_ETCL_Literal_Constraint ((CORBA::Long
) result
);
338 case ACE_ETCL_UNSIGNED
:
340 CORBA::ULong result
= (CORBA::ULong
) *this - (CORBA::ULong
) rhs
;
341 return TAO_ETCL_Literal_Constraint ((CORBA::ULong
) result
);
344 return TAO_ETCL_Literal_Constraint ((CORBA::Long
) 0);
348 TAO_ETCL_Literal_Constraint
349 TAO_ETCL_Literal_Constraint::operator* (const TAO_ETCL_Literal_Constraint
& rhs
)
351 Literal_Type widest_type
= this->widest_type (rhs
);
355 case ACE_ETCL_DOUBLE
:
357 CORBA::Double result
= (CORBA::Double
) *this * (CORBA::Double
) rhs
;
358 return TAO_ETCL_Literal_Constraint ((CORBA::Double
) result
);
360 case ACE_ETCL_INTEGER
:
361 case ACE_ETCL_SIGNED
:
363 CORBA::Long result
= (CORBA::Long
) *this * (CORBA::Long
) rhs
;
364 return TAO_ETCL_Literal_Constraint ((CORBA::Long
) result
);
366 case ACE_ETCL_UNSIGNED
:
368 CORBA::ULong result
= (CORBA::ULong
) *this * (CORBA::ULong
) rhs
;
369 return TAO_ETCL_Literal_Constraint ((CORBA::ULong
) result
);
372 return TAO_ETCL_Literal_Constraint ((CORBA::Long
) 0);
376 TAO_ETCL_Literal_Constraint
377 TAO_ETCL_Literal_Constraint::operator/ (const TAO_ETCL_Literal_Constraint
& rhs
)
379 Literal_Type widest_type
= this->widest_type (rhs
);
383 case ACE_ETCL_DOUBLE
:
385 if (ACE::is_equal ((ACE_CDR::Double
) rhs
, 0.0))
386 return TAO_ETCL_Literal_Constraint ((ACE_CDR::Double
) 0.0);
388 CORBA::Double result
= (CORBA::Double
) *this / (CORBA::Double
) rhs
;
389 return TAO_ETCL_Literal_Constraint ((CORBA::Double
) result
);
391 case ACE_ETCL_INTEGER
:
392 case ACE_ETCL_SIGNED
:
394 if ((ACE_CDR::Long
) rhs
== 0)
395 return TAO_ETCL_Literal_Constraint ((ACE_CDR::Long
) 0);
397 CORBA::Long result
= (CORBA::Long
) *this / (CORBA::Long
) rhs
;
398 return TAO_ETCL_Literal_Constraint ((CORBA::Long
) result
);
400 case ACE_ETCL_UNSIGNED
:
402 if ((ACE_CDR::ULong
) rhs
== 0)
403 return TAO_ETCL_Literal_Constraint ((ACE_CDR::ULong
) 0);
405 CORBA::ULong result
= (CORBA::ULong
) *this / (CORBA::ULong
) rhs
;
406 return TAO_ETCL_Literal_Constraint ((CORBA::ULong
) result
);
409 return TAO_ETCL_Literal_Constraint ((CORBA::Long
) 0);
413 TAO_ETCL_Literal_Constraint
414 TAO_ETCL_Literal_Constraint::operator- ()
418 case ACE_ETCL_DOUBLE
:
419 return TAO_ETCL_Literal_Constraint (- this->op_
.double_
);
420 case ACE_ETCL_INTEGER
:
421 case ACE_ETCL_SIGNED
:
422 return TAO_ETCL_Literal_Constraint (- this->op_
.integer_
);
423 case ACE_ETCL_UNSIGNED
:
424 return TAO_ETCL_Literal_Constraint (- (CORBA::Long
) this->op_
.uinteger_
);
426 return TAO_ETCL_Literal_Constraint ((CORBA::Long
) 0);
431 TAO_ETCL_Literal_Constraint::widest_type (
432 const ETCL_Literal_Constraint
& rhs
)
434 Literal_Type rhs_type
= rhs
.expr_type ();
435 Literal_Type return_value
= rhs_type
;
437 if (rhs_type
== ACE_ETCL_COMPONENT
)
439 const TAO_ETCL_Literal_Constraint
& actual
=
440 dynamic_cast<const TAO_ETCL_Literal_Constraint
&> (rhs
);
441 CORBA::TypeCode_var tc
= actual
.any_
->type ();
442 rhs_type
= TAO_ETCL_Literal_Constraint::comparable_type (tc
.in ());
446 return this->ETCL_Literal_Constraint::widest_type (rhs
);
450 TAO_ETCL_Literal_Constraint::copy (const TAO_ETCL_Literal_Constraint
&lit
)
452 if (this->type_
== ACE_ETCL_COMPONENT
&& this->any_
!= 0)
454 this->any_
->_remove_ref ();
460 case ACE_ETCL_COMPONENT
:
461 this->type_
= ACE_ETCL_COMPONENT
;
462 this->any_
= lit
.any_
;
463 this->any_
->_add_ref ();
466 this->ETCL_Literal_Constraint::copy (lit
);
471 TAO_END_VERSIONED_NAMESPACE_DECL