Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / ace / ETCL / ETCL_Constraint.cpp
blob74569e80eaeb8b5ff33e67320248cc815f502cdf
1 // -*- C++ -*-
2 #include "ace/ACE.h"
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 ()
23 int
24 ETCL_Constraint::accept (ETCL_Constraint_Visitor * /* visitor */)
26 return 0;
29 // ****************************************************************
31 ETCL_Literal_Constraint::ETCL_Literal_Constraint (
32 const ETCL_Literal_Constraint & lit)
33 : ETCL_Constraint(),
34 type_ (ACE_ETCL_UNKNOWN)
36 this->copy (lit);
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_);
78 int
79 ETCL_Literal_Constraint::accept (ETCL_Constraint_Visitor* visitor)
81 return visitor->visit_literal (this);
84 Literal_Type
85 ETCL_Literal_Constraint::expr_type () const
87 return this->type_;
90 void
91 ETCL_Literal_Constraint::operator= (const ETCL_Literal_Constraint& co)
93 this->copy (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
103 switch (this->type_)
105 case ACE_ETCL_UNSIGNED:
106 return this->op_.uinteger_;
107 case ACE_ETCL_SIGNED:
108 case ACE_ETCL_INTEGER:
109 return
110 (this->op_.integer_ > 0) ? (ACE_CDR::ULong) this->op_.integer_ : 0;
111 case ACE_ETCL_DOUBLE:
112 return
113 (this->op_.double_ > 0) ?
114 ((this->op_.double_ > ACE_UINT32_MAX) ?
115 ACE_UINT32_MAX :
116 (ACE_CDR::ULong) this->op_.double_)
117 : 0;
118 default:
119 return 0;
123 ETCL_Literal_Constraint::operator ACE_CDR::Long () const
125 switch (this->type_)
127 case ACE_ETCL_SIGNED:
128 case ACE_ETCL_INTEGER:
129 return this->op_.integer_;
130 case ACE_ETCL_UNSIGNED:
131 return
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:
135 return
136 (this->op_.double_ > 0) ?
137 ((this->op_.double_ > ACE_INT32_MAX) ?
138 ACE_INT32_MAX :
139 (ACE_CDR::Long) this->op_.double_) :
140 ((this->op_.double_ < ACE_INT32_MIN) ?
141 ACE_INT32_MIN :
142 (ACE_CDR::Long) this->op_.double_);
143 default:
144 return 0;
148 ETCL_Literal_Constraint::operator ACE_CDR::Double () const
150 switch (this->type_)
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_;
159 default:
160 return 0.0;
164 ETCL_Literal_Constraint::operator const char* () const
166 switch (this->type_)
168 case ACE_ETCL_STRING:
169 return this->op_.str_;
170 default:
171 return 0;
175 bool
176 ETCL_Literal_Constraint::operator== (const ETCL_Literal_Constraint & rhs)
178 bool return_value = false;
179 Literal_Type widest_type = this->widest_type (rhs);
181 switch (widest_type)
183 case ACE_ETCL_STRING:
184 return_value = (ACE_OS::strcmp ((const char*) *this, (const char*) rhs) == 0);
185 break;
186 case ACE_ETCL_DOUBLE:
187 return_value = ACE::is_equal ((ACE_CDR::Double) *this, (ACE_CDR::Double) rhs);
188 break;
189 case ACE_ETCL_INTEGER:
190 case ACE_ETCL_SIGNED:
191 return_value = (ACE_CDR::Long) *this == (ACE_CDR::Long) rhs;
192 break;
193 case ACE_ETCL_UNSIGNED:
194 return_value = (ACE_CDR::ULong) *this == (ACE_CDR::ULong) rhs;
195 break;
196 case ACE_ETCL_BOOLEAN:
197 return_value = (ACE_CDR::Boolean) *this == (ACE_CDR::Boolean) rhs;
198 break;
199 default:
200 break;
203 return return_value;
206 bool
207 ETCL_Literal_Constraint::operator< (const ETCL_Literal_Constraint & rhs)
209 bool return_value = false;
210 Literal_Type widest_type = this->widest_type (rhs);
212 switch (widest_type)
214 case ACE_ETCL_STRING:
215 return_value = (ACE_OS::strcmp ((const char*) *this, (const char*) rhs) < 0);
216 break;
217 case ACE_ETCL_DOUBLE:
218 return_value = (ACE_CDR::Double) *this < (ACE_CDR::Double) rhs;
219 break;
220 case ACE_ETCL_INTEGER:
221 case ACE_ETCL_SIGNED:
222 return_value = (ACE_CDR::Long) *this < (ACE_CDR::Long) rhs;
223 break;
224 case ACE_ETCL_UNSIGNED:
225 return_value = (ACE_CDR::ULong) *this < (ACE_CDR::ULong) rhs;
226 break;
227 case ACE_ETCL_BOOLEAN:
228 return_value = (ACE_CDR::Boolean) *this < (ACE_CDR::Boolean) rhs;
229 break;
230 default:
231 break;
234 return return_value;
237 bool
238 ETCL_Literal_Constraint::operator> (const ETCL_Literal_Constraint & rhs)
240 bool return_value = false;
241 Literal_Type widest_type = this->widest_type (rhs);
243 switch (widest_type)
245 case ACE_ETCL_STRING:
246 return_value = (ACE_OS::strcmp ((const char*) *this, (const char*) rhs) > 0);
247 break;
248 case ACE_ETCL_DOUBLE:
249 return_value = (ACE_CDR::Double) *this > (ACE_CDR::Double) rhs;
250 break;
251 case ACE_ETCL_INTEGER:
252 case ACE_ETCL_SIGNED:
253 return_value = (ACE_CDR::Long) *this > (ACE_CDR::Long) rhs;
254 break;
255 case ACE_ETCL_UNSIGNED:
256 return_value = (ACE_CDR::ULong) *this > (ACE_CDR::ULong) rhs;
257 break;
258 default:
259 break;
262 return return_value;
265 ETCL_Literal_Constraint
266 ETCL_Literal_Constraint::operator+ (const ETCL_Literal_Constraint & rhs)
268 Literal_Type widest_type = this->widest_type (rhs);
270 switch (widest_type)
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);
288 default:
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);
298 switch (widest_type)
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);
316 default:
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);
326 switch (widest_type)
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);
344 default:
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);
354 switch (widest_type)
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);
381 default:
382 return ETCL_Literal_Constraint ((ACE_CDR::Long) 0);
386 ETCL_Literal_Constraint
387 ETCL_Literal_Constraint::operator- ()
389 switch (this->type_)
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_);
398 default:
399 return ETCL_Literal_Constraint ((ACE_CDR::Long) 0);
403 Literal_Type
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;
415 else
417 return_value = this->type_;
421 return return_value;
424 void
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_;
434 switch (this->type_)
436 case ACE_ETCL_STRING:
437 this->op_.str_ = ACE::strnew (lit.op_.str_);
438 break;
439 case ACE_ETCL_DOUBLE:
440 this->op_.double_ = lit.op_.double_;
441 break;
442 case ACE_ETCL_UNSIGNED:
443 this->op_.uinteger_ = lit.op_.uinteger_;
444 break;
445 case ACE_ETCL_INTEGER:
446 case ACE_ETCL_SIGNED:
447 this->op_.integer_ = lit.op_.integer_;
448 break;
449 case ACE_ETCL_BOOLEAN:
450 this->op_.bool_ = lit.op_.bool_;
451 break;
452 default:
453 this->type_ = ACE_ETCL_UNKNOWN;
454 break;
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 ()
627 delete this->lhs_;
628 delete this->rhs_;
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