4 #include "ace/ETCL/ETCL_Constraint.h"
5 #include "ace/ETCL/ETCL_Constraint_Visitor.h"
7 #if ! defined (__ACE_INLINE__)
8 #include "ace/ETCL/ETCL_Constraint.inl"
9 #endif /* __ACE_INLINE__ */
11 #include "ace/OS_NS_string.h"
13 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
15 ETCL_Constraint::ETCL_Constraint ()
19 ETCL_Constraint::~ETCL_Constraint ()
24 ETCL_Constraint::accept (ETCL_Constraint_Visitor
* /* visitor */)
29 // ****************************************************************
31 ETCL_Literal_Constraint::ETCL_Literal_Constraint (
32 const ETCL_Literal_Constraint
& lit
)
34 type_ (ACE_ETCL_UNKNOWN
)
39 ETCL_Literal_Constraint::ETCL_Literal_Constraint (
40 ACE_CDR::ULong uinteger
) : type_ (ACE_ETCL_UNSIGNED
)
42 this->op_
.uinteger_
= uinteger
;
45 ETCL_Literal_Constraint::ETCL_Literal_Constraint (
46 ACE_CDR::Long integer
) : type_ (ACE_ETCL_SIGNED
)
48 this->op_
.integer_
= integer
;
51 ETCL_Literal_Constraint::ETCL_Literal_Constraint (
52 ACE_CDR::Boolean boolean
)
53 : type_ (ACE_ETCL_BOOLEAN
)
55 this->op_
.bool_
= boolean
;
58 ETCL_Literal_Constraint::ETCL_Literal_Constraint (
59 ACE_CDR::Double doub
) : type_ (ACE_ETCL_DOUBLE
)
61 this->op_
.double_
= doub
;
64 ETCL_Literal_Constraint::ETCL_Literal_Constraint (
65 const char* str
) : type_ (ACE_ETCL_STRING
)
67 this->op_
.str_
= ACE::strnew (str
);
70 ETCL_Literal_Constraint::~ETCL_Literal_Constraint ()
72 if (this->type_
== ACE_ETCL_STRING
)
74 ACE::strdelete (this->op_
.str_
);
79 ETCL_Literal_Constraint::accept (ETCL_Constraint_Visitor
* visitor
)
81 return visitor
->visit_literal (this);
85 ETCL_Literal_Constraint::expr_type () const
91 ETCL_Literal_Constraint::operator= (const ETCL_Literal_Constraint
& co
)
96 ETCL_Literal_Constraint::operator ACE_CDR::Boolean () const
98 return (this->type_
== ACE_ETCL_BOOLEAN
) ? this->op_
.bool_
: false;
101 ETCL_Literal_Constraint::operator ACE_CDR::ULong () const
105 case ACE_ETCL_UNSIGNED
:
106 return this->op_
.uinteger_
;
107 case ACE_ETCL_SIGNED
:
108 case ACE_ETCL_INTEGER
:
110 (this->op_
.integer_
> 0) ? (ACE_CDR::ULong
) this->op_
.integer_
: 0;
111 case ACE_ETCL_DOUBLE
:
113 (this->op_
.double_
> 0) ?
114 ((this->op_
.double_
> ACE_UINT32_MAX
) ?
116 (ACE_CDR::ULong
) this->op_
.double_
)
123 ETCL_Literal_Constraint::operator ACE_CDR::Long () const
127 case ACE_ETCL_SIGNED
:
128 case ACE_ETCL_INTEGER
:
129 return this->op_
.integer_
;
130 case ACE_ETCL_UNSIGNED
:
132 (this->op_
.uinteger_
> (ACE_CDR::ULong
) ACE_INT32_MAX
) ?
133 ACE_INT32_MAX
: (ACE_CDR::Long
) this->op_
.uinteger_
;
134 case ACE_ETCL_DOUBLE
:
136 (this->op_
.double_
> 0) ?
137 ((this->op_
.double_
> ACE_INT32_MAX
) ?
139 (ACE_CDR::Long
) this->op_
.double_
) :
140 ((this->op_
.double_
< ACE_INT32_MIN
) ?
142 (ACE_CDR::Long
) this->op_
.double_
);
148 ETCL_Literal_Constraint::operator ACE_CDR::Double () const
152 case ACE_ETCL_DOUBLE
:
153 return this->op_
.double_
;
154 case ACE_ETCL_SIGNED
:
155 case ACE_ETCL_INTEGER
:
156 return (ACE_CDR::Double
) this->op_
.integer_
;
157 case ACE_ETCL_UNSIGNED
:
158 return (ACE_CDR::Double
) this->op_
.uinteger_
;
164 ETCL_Literal_Constraint::operator const char* () const
168 case ACE_ETCL_STRING
:
169 return this->op_
.str_
;
176 ETCL_Literal_Constraint::operator== (const ETCL_Literal_Constraint
& rhs
)
178 bool return_value
= false;
179 Literal_Type widest_type
= this->widest_type (rhs
);
183 case ACE_ETCL_STRING
:
184 return_value
= (ACE_OS::strcmp ((const char*) *this, (const char*) rhs
) == 0);
186 case ACE_ETCL_DOUBLE
:
187 return_value
= ACE::is_equal ((ACE_CDR::Double
) *this, (ACE_CDR::Double
) rhs
);
189 case ACE_ETCL_INTEGER
:
190 case ACE_ETCL_SIGNED
:
191 return_value
= (ACE_CDR::Long
) *this == (ACE_CDR::Long
) rhs
;
193 case ACE_ETCL_UNSIGNED
:
194 return_value
= (ACE_CDR::ULong
) *this == (ACE_CDR::ULong
) rhs
;
196 case ACE_ETCL_BOOLEAN
:
197 return_value
= (ACE_CDR::Boolean
) *this == (ACE_CDR::Boolean
) rhs
;
207 ETCL_Literal_Constraint::operator< (const ETCL_Literal_Constraint
& rhs
)
209 bool return_value
= false;
210 Literal_Type widest_type
= this->widest_type (rhs
);
214 case ACE_ETCL_STRING
:
215 return_value
= (ACE_OS::strcmp ((const char*) *this, (const char*) rhs
) < 0);
217 case ACE_ETCL_DOUBLE
:
218 return_value
= (ACE_CDR::Double
) *this < (ACE_CDR::Double
) rhs
;
220 case ACE_ETCL_INTEGER
:
221 case ACE_ETCL_SIGNED
:
222 return_value
= (ACE_CDR::Long
) *this < (ACE_CDR::Long
) rhs
;
224 case ACE_ETCL_UNSIGNED
:
225 return_value
= (ACE_CDR::ULong
) *this < (ACE_CDR::ULong
) rhs
;
227 case ACE_ETCL_BOOLEAN
:
228 return_value
= (ACE_CDR::Boolean
) *this < (ACE_CDR::Boolean
) rhs
;
238 ETCL_Literal_Constraint::operator> (const ETCL_Literal_Constraint
& rhs
)
240 bool return_value
= false;
241 Literal_Type widest_type
= this->widest_type (rhs
);
245 case ACE_ETCL_STRING
:
246 return_value
= (ACE_OS::strcmp ((const char*) *this, (const char*) rhs
) > 0);
248 case ACE_ETCL_DOUBLE
:
249 return_value
= (ACE_CDR::Double
) *this > (ACE_CDR::Double
) rhs
;
251 case ACE_ETCL_INTEGER
:
252 case ACE_ETCL_SIGNED
:
253 return_value
= (ACE_CDR::Long
) *this > (ACE_CDR::Long
) rhs
;
255 case ACE_ETCL_UNSIGNED
:
256 return_value
= (ACE_CDR::ULong
) *this > (ACE_CDR::ULong
) rhs
;
265 ETCL_Literal_Constraint
266 ETCL_Literal_Constraint::operator+ (const ETCL_Literal_Constraint
& rhs
)
268 Literal_Type widest_type
= this->widest_type (rhs
);
272 case ACE_ETCL_DOUBLE
:
274 ACE_CDR::Double result
= (ACE_CDR::Double
) *this + (ACE_CDR::Double
) rhs
;
275 return ETCL_Literal_Constraint ((ACE_CDR::Double
) result
);
277 case ACE_ETCL_INTEGER
:
278 case ACE_ETCL_SIGNED
:
280 ACE_CDR::Long result
= (ACE_CDR::Long
) *this + (ACE_CDR::Long
) rhs
;
281 return ETCL_Literal_Constraint ((ACE_CDR::Long
) result
);
283 case ACE_ETCL_UNSIGNED
:
285 ACE_CDR::ULong result
= (ACE_CDR::ULong
) *this + (ACE_CDR::ULong
) rhs
;
286 return ETCL_Literal_Constraint ((ACE_CDR::ULong
) result
);
289 return ETCL_Literal_Constraint ((ACE_CDR::Long
) 0);
293 ETCL_Literal_Constraint
294 ETCL_Literal_Constraint::operator- (const ETCL_Literal_Constraint
& rhs
)
296 Literal_Type widest_type
= this->widest_type (rhs
);
300 case ACE_ETCL_DOUBLE
:
302 ACE_CDR::Double result
= (ACE_CDR::Double
) *this - (ACE_CDR::Double
) rhs
;
303 return ETCL_Literal_Constraint ((ACE_CDR::Double
) result
);
305 case ACE_ETCL_INTEGER
:
306 case ACE_ETCL_SIGNED
:
308 ACE_CDR::Long result
= (ACE_CDR::Long
) *this - (ACE_CDR::Long
) rhs
;
309 return ETCL_Literal_Constraint ((ACE_CDR::Long
) result
);
311 case ACE_ETCL_UNSIGNED
:
313 ACE_CDR::ULong result
= (ACE_CDR::ULong
) *this - (ACE_CDR::ULong
) rhs
;
314 return ETCL_Literal_Constraint ((ACE_CDR::ULong
) result
);
317 return ETCL_Literal_Constraint ((ACE_CDR::Long
) 0);
321 ETCL_Literal_Constraint
322 ETCL_Literal_Constraint::operator* (const ETCL_Literal_Constraint
& rhs
)
324 Literal_Type widest_type
= this->widest_type (rhs
);
328 case ACE_ETCL_DOUBLE
:
330 ACE_CDR::Double result
= (ACE_CDR::Double
) *this * (ACE_CDR::Double
) rhs
;
331 return ETCL_Literal_Constraint ((ACE_CDR::Double
) result
);
333 case ACE_ETCL_INTEGER
:
334 case ACE_ETCL_SIGNED
:
336 ACE_CDR::Long result
= (ACE_CDR::Long
) *this * (ACE_CDR::Long
) rhs
;
337 return ETCL_Literal_Constraint ((ACE_CDR::Long
) result
);
339 case ACE_ETCL_UNSIGNED
:
341 ACE_CDR::ULong result
= (ACE_CDR::ULong
) *this * (ACE_CDR::ULong
) rhs
;
342 return ETCL_Literal_Constraint ((ACE_CDR::ULong
) result
);
345 return ETCL_Literal_Constraint ((ACE_CDR::Long
) 0);
349 ETCL_Literal_Constraint
350 ETCL_Literal_Constraint::operator/ (const ETCL_Literal_Constraint
& rhs
)
352 Literal_Type widest_type
= this->widest_type (rhs
);
356 case ACE_ETCL_DOUBLE
:
358 if (ACE::is_equal ((ACE_CDR::Double
) rhs
, 0.0))
359 return ETCL_Literal_Constraint ((ACE_CDR::Double
) 0.0);
361 ACE_CDR::Double result
= (ACE_CDR::Double
) *this / (ACE_CDR::Double
) rhs
;
362 return ETCL_Literal_Constraint ((ACE_CDR::Double
) result
);
364 case ACE_ETCL_INTEGER
:
365 case ACE_ETCL_SIGNED
:
367 if ((ACE_CDR::Long
) rhs
== 0)
368 return ETCL_Literal_Constraint ((ACE_CDR::Long
) 0);
370 ACE_CDR::Long result
= (ACE_CDR::Long
) *this / (ACE_CDR::Long
) rhs
;
371 return ETCL_Literal_Constraint ((ACE_CDR::Long
) result
);
373 case ACE_ETCL_UNSIGNED
:
375 if ((ACE_CDR::ULong
) rhs
== 0)
376 return ETCL_Literal_Constraint ((ACE_CDR::ULong
) 0);
378 ACE_CDR::ULong result
= (ACE_CDR::ULong
) *this / (ACE_CDR::ULong
) rhs
;
379 return ETCL_Literal_Constraint ((ACE_CDR::ULong
) result
);
382 return ETCL_Literal_Constraint ((ACE_CDR::Long
) 0);
386 ETCL_Literal_Constraint
387 ETCL_Literal_Constraint::operator- ()
391 case ACE_ETCL_DOUBLE
:
392 return ETCL_Literal_Constraint (- this->op_
.double_
);
393 case ACE_ETCL_INTEGER
:
394 case ACE_ETCL_SIGNED
:
395 return ETCL_Literal_Constraint (- this->op_
.integer_
);
396 case ACE_ETCL_UNSIGNED
:
397 return ETCL_Literal_Constraint (- (ACE_CDR::Long
) this->op_
.uinteger_
);
399 return ETCL_Literal_Constraint ((ACE_CDR::Long
) 0);
404 ETCL_Literal_Constraint::widest_type (const ETCL_Literal_Constraint
& rhs
)
406 Literal_Type rhs_type
= rhs
.expr_type ();
407 Literal_Type return_value
= rhs_type
;
409 if (rhs_type
!= this->type_
)
411 if (rhs_type
> this->type_
)
413 return_value
= rhs_type
;
417 return_value
= this->type_
;
425 ETCL_Literal_Constraint::copy (const ETCL_Literal_Constraint
&lit
)
427 if (this->type_
== ACE_ETCL_STRING
)
429 ACE::strdelete (this->op_
.str_
);
432 this->type_
= lit
.type_
;
436 case ACE_ETCL_STRING
:
437 this->op_
.str_
= ACE::strnew (lit
.op_
.str_
);
439 case ACE_ETCL_DOUBLE
:
440 this->op_
.double_
= lit
.op_
.double_
;
442 case ACE_ETCL_UNSIGNED
:
443 this->op_
.uinteger_
= lit
.op_
.uinteger_
;
445 case ACE_ETCL_INTEGER
:
446 case ACE_ETCL_SIGNED
:
447 this->op_
.integer_
= lit
.op_
.integer_
;
449 case ACE_ETCL_BOOLEAN
:
450 this->op_
.bool_
= lit
.op_
.bool_
;
453 this->type_
= ACE_ETCL_UNKNOWN
;
458 // ****************************************************************
461 ETCL_Identifier::accept (ETCL_Constraint_Visitor
*visitor
)
463 return visitor
->visit_identifier (this);
466 // ****************************************************************
468 ETCL_Union_Value::~ETCL_Union_Value ()
470 delete this->string_
;
471 delete this->integer_
;
475 ETCL_Union_Value::accept (ETCL_Constraint_Visitor
*visitor
)
477 return visitor
->visit_union_value (this);
480 // ****************************************************************
482 ETCL_Union_Pos::~ETCL_Union_Pos ()
484 delete this->component_
;
485 delete this->union_value_
;
489 ETCL_Union_Pos::accept (ETCL_Constraint_Visitor
*visitor
)
491 return visitor
->visit_union_pos (this);
494 // ****************************************************************
496 ETCL_Component_Pos::~ETCL_Component_Pos ()
498 delete this->component_
;
499 delete this->integer_
;
503 ETCL_Component_Pos::accept (ETCL_Constraint_Visitor
*visitor
)
505 return visitor
->visit_component_pos (this);
508 // ****************************************************************
510 ETCL_Component_Assoc::~ETCL_Component_Assoc ()
512 delete this->component_
;
513 delete this->identifier_
;
517 ETCL_Component_Assoc::accept (ETCL_Constraint_Visitor
*visitor
)
519 return visitor
->visit_component_assoc (this);
522 // ****************************************************************
524 ETCL_Component_Array::~ETCL_Component_Array ()
526 delete this->component_
;
527 delete this->integer_
;
531 ETCL_Component_Array::accept (ETCL_Constraint_Visitor
*visitor
)
533 return visitor
->visit_component_array (this);
536 // ****************************************************************
539 ETCL_Special::accept (ETCL_Constraint_Visitor
*visitor
)
541 return visitor
->visit_special (this);
544 // ****************************************************************
546 ETCL_Component::~ETCL_Component ()
548 delete this->component_
;
549 delete this->identifier_
;
553 ETCL_Component::accept (ETCL_Constraint_Visitor
*visitor
)
555 return visitor
->visit_component (this);
558 // ****************************************************************
560 ETCL_Dot::~ETCL_Dot ()
562 delete this->component_
;
566 ETCL_Dot::accept (ETCL_Constraint_Visitor
*visitor
)
568 return visitor
->visit_dot (this);
571 // ****************************************************************
573 ETCL_Eval::~ETCL_Eval ()
575 delete this->component_
;
579 ETCL_Eval::accept (ETCL_Constraint_Visitor
*visitor
)
581 return visitor
->visit_eval (this);
584 // ****************************************************************
586 ETCL_Default::~ETCL_Default ()
588 delete this->component_
;
592 ETCL_Default::accept (ETCL_Constraint_Visitor
*visitor
)
594 return visitor
->visit_default (this);
597 // ****************************************************************
599 ETCL_Exist::~ETCL_Exist ()
601 delete this->component_
;
605 ETCL_Exist::accept (ETCL_Constraint_Visitor
*visitor
)
607 return visitor
->visit_exist (this);
610 // ****************************************************************
612 ETCL_Unary_Expr::~ETCL_Unary_Expr ()
614 delete this->subexpr_
;
618 ETCL_Unary_Expr::accept (ETCL_Constraint_Visitor
*visitor
)
620 return visitor
->visit_unary_expr (this);
623 // ****************************************************************
625 ETCL_Binary_Expr::~ETCL_Binary_Expr ()
632 ETCL_Binary_Expr::accept (ETCL_Constraint_Visitor
*visitor
)
634 return visitor
->visit_binary_expr (this);
637 // ****************************************************************
639 ETCL_Preference::~ETCL_Preference ()
641 delete this->subexpr_
;
645 ETCL_Preference::accept (ETCL_Constraint_Visitor
*visitor
)
647 return visitor
->visit_preference (this);
650 ACE_END_VERSIONED_NAMESPACE_DECL