GME
13
|
00001 //############################################################################################################################################### 00002 // 00003 // Object Constraint Language Generic Manager 00004 // OCLTypeExBasic.cpp 00005 // 00006 //############################################################################################################################################### 00007 #include "Solve4786.h" 00008 #include "OCLTypeExBasic.h" 00009 00010 #include "OCLObjectExBasic.h" 00011 #include "math.h" 00012 #include <algorithm> // needed for ms stl 00013 #include <string> 00014 #include <cctype> 00015 00016 00017 namespace OclBasic 00018 { 00019 typedef OclCommon::FormalParameterVector FPV; 00020 typedef OclCommon::FormalParameter FP; 00021 typedef TypeSeq TS; 00022 00023 typedef OclImplementation::Iterator OclIterator; 00024 00025 //############################################################################################################################################## 00026 // 00027 // F U N C T I O N S 00028 // 00029 //############################################################################################################################################## 00030 00031 //############################################################################################################################################## 00032 // 00033 // T Y P E O F ocl::Any 00034 // 00035 //############################################################################################################################################## 00036 00037 OPERATOR( TAny_Equals ) 00038 { 00039 void operator()() 00040 { 00041 SetResult( CREATE_BOOLEAN( GetTypeManager(), GetArgument( 0 ).Equals( GetArgument( 1 ) ) ) ); 00042 } 00043 }; 00044 00045 OPERATOR( TAny_NotEquals ) 00046 { 00047 void operator()() 00048 { 00049 SetResult( CREATE_BOOLEAN( GetTypeManager(), ! GetArgument( 0 ).Equals( GetArgument( 1 ) ) ) ); 00050 } 00051 }; 00052 00053 OPERATOR( TAny_IdentityEquals ) 00054 { 00055 void operator()() 00056 { 00057 SetResult( CREATE_BOOLEAN( GetTypeManager(), GetArgument( 0 ).GetImplementation() == GetArgument( 1 ).GetImplementation() ) ); 00058 } 00059 }; 00060 00061 OPERATOR( TAny_IdentityNotEquals ) 00062 { 00063 void operator()() 00064 { 00065 SetResult( CREATE_BOOLEAN( GetTypeManager(), GetArgument( 0 ).GetImplementation() != GetArgument( 1 ).GetImplementation() ) ); 00066 } 00067 }; 00068 00069 METHOD( TAny_IsTypeOf ) 00070 { 00071 void operator()() 00072 { 00073 DECL_TYPE( strType, GetArgument( 0 ) ); 00074 SetResult( CREATE_BOOLEAN( GetTypeManager(), GetTypeManager()->IsTypeA( GetThis().GetTypeName(), strType ) == 0 ) ); 00075 } 00076 }; 00077 00078 METHOD( TAny_IsKindOf ) 00079 { 00080 void operator()() 00081 { 00082 DECL_TYPE( strType, GetArgument( 0 ) ); 00083 SetResult( CREATE_BOOLEAN( GetTypeManager(), GetTypeManager()->IsTypeA( GetThis().GetTypeName(), strType ) >= 0 ) ); 00084 } 00085 }; 00086 00087 void TAny_MethodFactory::GetFeatures( const OclSignature::Method& signature, OclMeta::MethodVector& vecFeatures ) 00088 { 00089 std::string strName = signature.GetName(); 00090 int iCount = signature.GetParameterCount(); 00091 FPV vecParams; 00092 TS vecType; 00093 00094 if ( ( strName == "isTypeOf" || strName == "oclIsTypeOf" ) && iCount == 1 ) { 00095 vecParams.push_back( FP( "type", "ocl::Type", true ) ); 00096 vecType.push_back( "ocl::Boolean" ); 00097 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TAny_IsTypeOf(), false ) ); 00098 return; 00099 } 00100 00101 if ( ( strName == "isKindOf" || strName == "oclIsKindOf" ) && iCount == 1 ) { 00102 vecParams.push_back( FP( "type", "ocl::Type", true ) ); 00103 vecType.push_back( "ocl::Boolean" ); 00104 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TAny_IsKindOf(), false ) ); 00105 return; 00106 } 00107 } 00108 00109 //############################################################################################################################################## 00110 // 00111 // T Y P E O F ocl::String 00112 // 00113 //############################################################################################################################################## 00114 00115 OPERATOR( TString_Less ) 00116 { 00117 void operator()() 00118 { 00119 DECL_STRING( strThis, GetArgument( 0 ) ); 00120 DECL_STRING( strValue, GetArgument( 1 ) ); 00121 SetResult( CREATE_BOOLEAN( GetTypeManager(), strThis < strValue ) ); 00122 } 00123 }; 00124 00125 OPERATOR( TString_LessEquals ) 00126 { 00127 void operator()() 00128 { 00129 DECL_STRING( strThis, GetArgument( 0 ) ); 00130 DECL_STRING( strValue, GetArgument( 1 ) ); 00131 SetResult( CREATE_BOOLEAN( GetTypeManager(), strThis <= strValue ) ); 00132 } 00133 }; 00134 00135 OPERATOR( TString_Greater ) 00136 { 00137 void operator()() 00138 { 00139 DECL_STRING( strThis, GetArgument( 0 ) ); 00140 DECL_STRING( strValue, GetArgument( 1 ) ); 00141 SetResult( CREATE_BOOLEAN( GetTypeManager(), strThis > strValue ) ); 00142 } 00143 }; 00144 00145 OPERATOR( TString_GreaterEquals ) 00146 { 00147 void operator()() 00148 { 00149 DECL_STRING( strThis, GetArgument( 0 ) ); 00150 DECL_STRING( strValue, GetArgument( 1 ) ); 00151 SetResult( CREATE_BOOLEAN( GetTypeManager(), strThis >= strValue ) ); 00152 } 00153 }; 00154 00155 OPERATOR( TString_Plus ) 00156 { 00157 void operator()() 00158 { 00159 DECL_STRING( strThis, GetArgument( 0 ) ); 00160 DECL_STRING( strValue, GetArgument( 1 ) ); 00161 SetResult( CREATE_STRING( GetTypeManager(), strThis + strValue ) ); 00162 } 00163 }; 00164 00165 ATTRIBUTE( TString_Size ) 00166 { 00167 void operator()() 00168 { 00169 DECL_STRING( strValue, GetThis() ); 00170 SetResult( CREATE_INTEGER( GetTypeManager(), strValue.length() ) ); 00171 } 00172 }; 00173 00174 METHOD( TString_ToUpper ) 00175 { 00176 void operator()() 00177 { 00178 DECL_STRING( strValue, GetThis() ); 00179 std::transform(strValue.begin(), strValue.end(), strValue.begin(), std::toupper); 00180 SetResult( CREATE_STRING( GetTypeManager(), strValue ) ); 00181 } 00182 }; 00183 00184 METHOD( TString_ToLower ) 00185 { 00186 void operator()() 00187 { 00188 DECL_STRING( strValue, GetThis() ); 00189 std::transform(strValue.begin(), strValue.end(), strValue.begin(), std::tolower); 00190 SetResult( CREATE_STRING( GetTypeManager(), strValue ) ); 00191 } 00192 }; 00193 00194 METHOD( TString_Concat ) 00195 { 00196 void operator()() 00197 { 00198 DECL_STRING( strThis, GetThis() ); 00199 DECL_STRING( strValue, GetArgument( 0 ) ); 00200 SetResult( CREATE_STRING( GetTypeManager(), strThis + strValue ) ); 00201 } 00202 }; 00203 00204 METHOD( TString_Substring ) 00205 { 00206 void operator()() 00207 { 00208 DECL_STRING( strThis, GetThis() ); 00209 DECL_INTEGER( iFrom, GetArgument( 0 ) ); 00210 if ( iFrom < 0 ) { 00211 ThrowException( "Argument 'from' is less than 0." ); 00212 return; 00213 } 00214 if ( iFrom >= (int) strThis.length() ) { 00215 ThrowException( "Argument 'from' equals to or is greater than size of string." ); 00216 return; 00217 } 00218 if ( GetArgumentCount() == 1 ) { 00219 SetResult( CREATE_STRING( GetTypeManager(), strThis.substr( iFrom ) ) ); 00220 return; 00221 } 00222 DECL_INTEGER( iTo, GetArgument( 1 ) ); 00223 if ( iTo < iFrom ) { 00224 ThrowException( "Argument 'to' greater than Argument 'from'." ); 00225 return; 00226 } 00227 if ( iTo > (int) strThis.length() ) { 00228 ThrowException( "Argument 'to' is greater than size of string." ); 00229 return; 00230 } 00231 std::string res = strThis.substr( iFrom, iTo-iFrom ); 00232 SetResult( CREATE_STRING( GetTypeManager(), res ) ); 00233 } 00234 }; 00235 00236 METHOD( TString_ToInteger ) 00237 { 00238 void operator()() 00239 { 00240 DECL_STRING( strThis, GetThis() ); 00241 Trim( strThis ); 00242 unsigned int i = 0; 00243 if (strThis[ i ] == '-' || strThis[ i ] == '+') 00244 i++; 00245 if (i >= strThis.length()) 00246 ThrowException( "String cannot be converted to ocl::Integer." ); 00247 for ( ; i < strThis.length() ; i ++ ) 00248 if ( strThis[ i ] < '0' || strThis[ i ] > '9' ) 00249 ThrowException( "String cannot be converted to ocl::Integer." ); 00250 long lValue = atol( strThis.c_str() ); 00251 SetResult( CREATE_INTEGER( GetTypeManager(), lValue ) ); 00252 } 00253 }; 00254 00255 METHOD( TString_ToReal ) 00256 { 00257 void operator()() 00258 { 00259 DECL_STRING( strThis, GetThis() ); 00260 char* pchStop; 00261 double dValue = strtod( strThis.c_str(), &pchStop ); 00262 if ( fabs( dValue ) == HUGE_VAL ) 00263 ThrowException( "String cannot be converted to ocl::Real." ); 00264 SetResult( CREATE_REAL( GetTypeManager(), dValue ) ); 00265 } 00266 }; 00267 00268 METHOD( TString_Trim ) 00269 { 00270 void operator()() 00271 { 00272 DECL_STRING( strThis, GetThis() ); 00273 Trim( strThis ); 00274 SetResult( CREATE_STRING( GetTypeManager(), strThis ) ); 00275 } 00276 }; 00277 00278 void TString_AttributeFactory::GetFeatures( const OclSignature::Attribute& signature, OclMeta::AttributeVector& vecFeatures ) 00279 { 00280 std::string strName = signature.GetName(); 00281 TS vecType; 00282 00283 if ( strName == "size" ) { 00284 vecType.push_back( "ocl::Integer" ); 00285 vecFeatures.push_back( new OclMeta::Attribute( strName, vecType, new TString_Size(), false ) ); 00286 return; 00287 } 00288 } 00289 00290 void TString_MethodFactory::GetFeatures( const OclSignature::Method& signature, OclMeta::MethodVector& vecFeatures ) 00291 { 00292 std::string strName = signature.GetName(); 00293 int iCount = signature.GetParameterCount(); 00294 FPV vecParams; 00295 TS vecType; 00296 00297 if ( ( strName == "toUpper" ) && iCount == 0 ) { 00298 vecType.push_back( "ocl::String" ); 00299 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TString_ToUpper(), false ) ); 00300 return; 00301 } 00302 00303 if ( ( strName == "toLower" ) && iCount == 0 ) { 00304 vecType.push_back( "ocl::String" ); 00305 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TString_ToLower(), false ) ); 00306 return; 00307 } 00308 00309 if ( ( strName == "concat" ) && iCount == 1 ) { 00310 vecParams.push_back( FP( "string", "ocl::String", true ) ); 00311 vecType.push_back( "ocl::String" ); 00312 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TString_Concat(), false ) ); 00313 return; 00314 } 00315 00316 if ( ( strName == "toReal" ) && iCount == 0 ) { 00317 vecType.push_back( "ocl::Real" ); 00318 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TString_ToReal(), false ) ); 00319 return; 00320 } 00321 00322 if ( ( strName == "toInteger" ) && iCount == 0 ) { 00323 vecType.push_back( "ocl::Integer" ); 00324 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TString_ToInteger(), false ) ); 00325 return; 00326 } 00327 00328 if ( ( strName == "substring" ) && iCount >= 1 && iCount <= 2 ) { 00329 vecParams.push_back( FP( "iFrom", "ocl::Integer", true ) ); 00330 vecParams.push_back( FP( "iTo", "ocl::Integer", false ) ); 00331 vecType.push_back( "ocl::String" ); 00332 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TString_Substring(), false ) ); 00333 return; 00334 } 00335 00336 if ( ( strName == "trim" && iCount == 0 ) ){ 00337 vecType.push_back( "ocl::String" ); 00338 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TString_Trim(), false ) ); 00339 return; 00340 } 00341 } 00342 00343 //############################################################################################################################################## 00344 // 00345 // T Y P E O F ocl::Enumeration 00346 // 00347 //############################################################################################################################################## 00348 00349 METHOD( TEnumeration_ToString ) 00350 { 00351 void operator()() 00352 { 00353 DECL_ENUMERATION( enumThis, GetThis() ); 00354 SetResult( CREATE_STRING( GetTypeManager(), enumThis ) ); 00355 } 00356 }; 00357 00358 void TEnumeration_MethodFactory::GetFeatures( const OclSignature::Method& signature, OclMeta::MethodVector& vecFeatures ) 00359 { 00360 std::string strName = signature.GetName(); 00361 int iCount = signature.GetParameterCount(); 00362 FPV vecParams; 00363 TS vecType; 00364 00365 if ( ( strName == "toString" ) && iCount == 0 ) { 00366 vecType.push_back( "ocl::String" ); 00367 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TEnumeration_ToString(), false ) ); 00368 return; 00369 } 00370 } 00371 00372 //############################################################################################################################################## 00373 // 00374 // T Y P E O F ocl::Boolean 00375 // 00376 //############################################################################################################################################## 00377 00378 OPERATOR( TBoolean_And ) 00379 { 00380 void operator()() 00381 { 00382 DECL_BOOLEAN( bArg1, GetArgument( 0 ) ); 00383 DECL_BOOLEAN( bArg2, GetArgument( 1 ) ); 00384 SetResult( CREATE_BOOLEAN( GetTypeManager(), bArg1 && bArg2 ) ); 00385 } 00386 }; 00387 00388 OPERATOR( TBoolean_Or ) 00389 { 00390 void operator()() 00391 { 00392 DECL_BOOLEAN( bArg1, GetArgument( 0 ) ); 00393 DECL_BOOLEAN( bArg2, GetArgument( 1 ) ); 00394 SetResult( CREATE_BOOLEAN( GetTypeManager(), bArg1 || bArg2 ) ); 00395 } 00396 }; 00397 00398 OPERATOR( TBoolean_Not ) 00399 { 00400 void operator()() 00401 { 00402 DECL_BOOLEAN( bArg, GetArgument( 0 ) ); 00403 SetResult( CREATE_BOOLEAN( GetTypeManager(), ! bArg ) ); 00404 } 00405 }; 00406 00407 OPERATOR( TBoolean_Implies ) 00408 { 00409 void operator()() 00410 { 00411 DECL_BOOLEAN( bArg1, GetArgument( 0 ) ); 00412 DECL_BOOLEAN( bArg2, GetArgument( 1 ) ); 00413 SetResult( CREATE_BOOLEAN( GetTypeManager(), ! bArg1 || bArg2 ) ); 00414 } 00415 }; 00416 00417 OPERATOR( TBoolean_Xor ) 00418 { 00419 void operator()() 00420 { 00421 DECL_BOOLEAN( bArg1, GetArgument( 0 ) ); 00422 DECL_BOOLEAN( bArg2, GetArgument( 1 ) ); 00423 SetResult( CREATE_BOOLEAN( GetTypeManager(), bArg1 && ! bArg2 || ! bArg1 && bArg2 ) ); 00424 } 00425 }; 00426 00427 //############################################################################################################################################## 00428 // 00429 // T Y P E O F ocl::Real 00430 // 00431 //############################################################################################################################################## 00432 00433 OPERATOR( TReal_Equals ) 00434 { 00435 void operator()() 00436 { 00437 DECL_REAL( dThis, GetArgument( 0 ) ); 00438 DECL_REAL( dValue, GetArgument( 1 ) ); 00439 SetResult( CREATE_BOOLEAN( GetTypeManager(), dThis == dValue ) ); 00440 } 00441 }; 00442 00443 OPERATOR( TReal_NotEquals ) 00444 { 00445 void operator()() 00446 { 00447 DECL_REAL( dThis, GetArgument( 0 ) ); 00448 DECL_REAL( dValue, GetArgument( 1 ) ); 00449 SetResult( CREATE_BOOLEAN( GetTypeManager(), dThis != dValue ) ); 00450 } 00451 }; 00452 00453 OPERATOR( TReal_Minus1 ) 00454 { 00455 void operator()() 00456 { 00457 DECL_REAL( dArg, GetArgument( 0 ) ); 00458 SetResult( CREATE_REAL( GetTypeManager(), - dArg ) ); 00459 } 00460 }; 00461 00462 OPERATOR( TReal_Plus ) 00463 { 00464 void operator()() 00465 { 00466 DECL_REAL( dArg1, GetArgument( 0 ) ); 00467 DECL_REAL( dArg2, GetArgument( 1 ) ); 00468 SetResult( CREATE_REAL( GetTypeManager(), dArg1 + dArg2 ) ); 00469 } 00470 }; 00471 00472 OPERATOR( TReal_Minus2 ) 00473 { 00474 void operator()() 00475 { 00476 DECL_REAL( dArg1, GetArgument( 0 ) ); 00477 DECL_REAL( dArg2, GetArgument( 1 ) ); 00478 SetResult( CREATE_REAL( GetTypeManager(), dArg1 - dArg2 ) ); 00479 } 00480 }; 00481 00482 OPERATOR( TReal_Slash ) 00483 { 00484 void operator()() 00485 { 00486 DECL_REAL( dArg1, GetArgument( 0 ) ); 00487 DECL_REAL( dArg2, GetArgument( 1 ) ); 00488 SetResult( CREATE_REAL( GetTypeManager(), dArg1 / dArg2 ) ); 00489 } 00490 }; 00491 00492 OPERATOR( TReal_Times ) 00493 { 00494 void operator()() 00495 { 00496 DECL_REAL( dArg1, GetArgument( 0 ) ); 00497 DECL_REAL( dArg2, GetArgument( 1 ) ); 00498 SetResult( CREATE_REAL( GetTypeManager(), dArg1 * dArg2 ) ); 00499 } 00500 }; 00501 00502 OPERATOR( TReal_Less ) 00503 { 00504 void operator()() 00505 { 00506 DECL_REAL( dArg1, GetArgument( 0 ) ); 00507 DECL_REAL( dArg2, GetArgument( 1 ) ); 00508 SetResult( CREATE_BOOLEAN( GetTypeManager(), dArg1 < dArg2 ) ); 00509 } 00510 }; 00511 00512 OPERATOR( TReal_Greater ) 00513 { 00514 void operator()() 00515 { 00516 DECL_REAL( dArg1, GetArgument( 0 ) ); 00517 DECL_REAL( dArg2, GetArgument( 1 ) ); 00518 SetResult( CREATE_BOOLEAN( GetTypeManager(), dArg1 > dArg2 ) ); 00519 } 00520 }; 00521 00522 OPERATOR( TReal_LessEquals ) 00523 { 00524 void operator()() 00525 { 00526 DECL_REAL( dArg1, GetArgument( 0 ) ); 00527 DECL_REAL( dArg2, GetArgument( 1 ) ); 00528 SetResult( CREATE_BOOLEAN( GetTypeManager(), dArg1 <= dArg2 ) ); 00529 } 00530 }; 00531 00532 OPERATOR( TReal_GreaterEquals ) 00533 { 00534 void operator()() 00535 { 00536 DECL_REAL( dArg1, GetArgument( 0 ) ); 00537 DECL_REAL( dArg2, GetArgument( 1 ) ); 00538 SetResult( CREATE_BOOLEAN( GetTypeManager(), dArg1 >= dArg2 ) ); 00539 } 00540 }; 00541 00542 FUNCTION( TReal_Abs ) 00543 { 00544 void operator()() 00545 { 00546 DECL_REAL( dArg, GetArgument( 0 ) ); 00547 SetResult( CREATE_REAL( GetTypeManager(), fabs( dArg ) ) ); 00548 } 00549 }; 00550 00551 FUNCTION( TReal_Floor ) 00552 { 00553 void operator()() 00554 { 00555 DECL_REAL( dArg, GetArgument( 0 ) ); 00556 SetResult( CREATE_INTEGER( GetTypeManager(), (long)floor( dArg ) ) ); 00557 } 00558 }; 00559 00560 FUNCTION( TReal_Round ) 00561 { 00562 void operator()() 00563 { 00564 DECL_REAL( dArg, GetArgument( 0 ) ); 00565 long lFloor = (long)floor( dArg ); 00566 SetResult( CREATE_INTEGER( GetTypeManager(), lFloor + ( ( lFloor + 0.5 <= dArg && dArg >= 0 ) ? 1 : 0 ) ) ); 00567 } 00568 }; 00569 00570 FUNCTION( TReal_Max ) 00571 { 00572 void operator()() 00573 { 00574 DECL_REAL( dArg1, GetArgument( 0 ) ); 00575 DECL_REAL( dArg2, GetArgument( 1 ) ); 00576 SetResult( CREATE_REAL( GetTypeManager(), max( dArg1, dArg2 ) ) ); 00577 } 00578 }; 00579 00580 FUNCTION( TReal_Min ) 00581 { 00582 void operator()() 00583 { 00584 DECL_REAL( dArg1, GetArgument( 0 ) ); 00585 DECL_REAL( dArg2, GetArgument( 1 ) ); 00586 SetResult( CREATE_REAL( GetTypeManager(), min( dArg1, dArg2 ) ) ); 00587 } 00588 }; 00589 00590 METHOD( TReal_Abs_Method ) 00591 { 00592 void operator()() 00593 { 00594 DECL_REAL( dThis, GetThis() ); 00595 SetResult( CREATE_REAL( GetTypeManager(), fabs( dThis ) ) ); 00596 } 00597 }; 00598 00599 METHOD( TReal_Floor_Method ) 00600 { 00601 void operator()() 00602 { 00603 DECL_REAL( dThis, GetThis() ); 00604 SetResult( CREATE_INTEGER( GetTypeManager(), (long)floor( dThis ) ) ); 00605 } 00606 }; 00607 00608 METHOD( TReal_Round_Method ) 00609 { 00610 void operator()() 00611 { 00612 DECL_REAL( dThis, GetThis() ); 00613 long lFloor = (long)floor( dThis ); 00614 SetResult( CREATE_INTEGER( GetTypeManager(), lFloor + ( ( lFloor + 0.5 <= dThis && dThis >= 0 ) ? 1 : 0 ) ) ); 00615 } 00616 }; 00617 00618 METHOD( TReal_Max_Method ) 00619 { 00620 void operator()() 00621 { 00622 DECL_REAL( dThis, GetThis() ); 00623 DECL_REAL( dArg, GetArgument( 0 ) ); 00624 SetResult( CREATE_REAL( GetTypeManager(), max( dThis, dArg ) ) ); 00625 } 00626 }; 00627 00628 METHOD( TReal_Min_Method ) 00629 { 00630 void operator()() 00631 { 00632 DECL_REAL( dThis, GetThis() ); 00633 DECL_REAL( dArg, GetArgument( 0 ) ); 00634 SetResult( CREATE_REAL( GetTypeManager(), min( dThis, dArg ) ) ); 00635 } 00636 }; 00637 00638 void TReal_MethodFactory::GetFeatures( const OclSignature::Method& signature, OclMeta::MethodVector& vecFeatures ) 00639 { 00640 std::string strName = signature.GetName(); 00641 int iCount = signature.GetParameterCount(); 00642 FPV vecParams; 00643 TS vecType; 00644 00645 if ( ( strName == "abs" ) && iCount == 0 ) { 00646 vecType.push_back( "ocl::Real" ); 00647 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TReal_Abs_Method(), false ) ); 00648 return; 00649 } 00650 00651 if ( ( strName == "floor" ) && iCount == 0 ) { 00652 vecType.push_back( "ocl::Integer" ); 00653 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TReal_Floor_Method(), false ) ); 00654 return; 00655 } 00656 00657 if ( ( strName == "round" ) && iCount == 0 ) { 00658 vecType.push_back( "ocl::Integer" ); 00659 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TReal_Round_Method(), false ) ); 00660 return; 00661 } 00662 00663 if ( ( strName == "max" ) && iCount == 1 ) { 00664 vecParams.push_back( FP( "real", "ocl::Real", true ) ); 00665 vecType.push_back( "ocl::Real" ); 00666 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TReal_Max_Method(), false ) ); 00667 return; 00668 } 00669 00670 if ( ( strName == "min" ) && iCount == 1 ) { 00671 vecParams.push_back( FP( "real", "ocl::Real", true ) ); 00672 vecType.push_back( "ocl::Real" ); 00673 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TReal_Min_Method(), false ) ); 00674 return; 00675 } 00676 } 00677 00678 //############################################################################################################################################## 00679 // 00680 // T Y P E O F ocl::Integer 00681 // 00682 //############################################################################################################################################## 00683 00684 OPERATOR( TInteger_Minus1 ) 00685 { 00686 void operator()() 00687 { 00688 DECL_INTEGER( lArg, GetArgument( 0 ) ); 00689 SetResult( CREATE_INTEGER( GetTypeManager(), - lArg ) ); 00690 } 00691 }; 00692 00693 OPERATOR( TInteger_Plus ) 00694 { 00695 void operator()() 00696 { 00697 DECL_INTEGER( lArg1, GetArgument( 0 ) ); 00698 DECL_INTEGER( lArg2, GetArgument( 1 ) ); 00699 SetResult( CREATE_INTEGER( GetTypeManager(), lArg1 + lArg2 ) ); 00700 } 00701 }; 00702 00703 OPERATOR( TInteger_Minus2 ) 00704 { 00705 void operator()() 00706 { 00707 DECL_INTEGER( lArg1, GetArgument( 0 ) ); 00708 DECL_INTEGER( lArg2, GetArgument( 1 ) ); 00709 SetResult( CREATE_INTEGER( GetTypeManager(), lArg1 - lArg2 ) ); 00710 } 00711 }; 00712 00713 OPERATOR( TInteger_Div ) 00714 { 00715 void operator()() 00716 { 00717 DECL_INTEGER( lArg1, GetArgument( 0 ) ); 00718 DECL_INTEGER( lArg2, GetArgument( 1 ) ); 00719 SetResult( CREATE_INTEGER( GetTypeManager(), lArg1 / lArg2 ) ); 00720 } 00721 }; 00722 00723 OPERATOR( TInteger_Times ) 00724 { 00725 void operator()() 00726 { 00727 DECL_INTEGER( lArg1, GetArgument( 0 ) ); 00728 DECL_INTEGER( lArg2, GetArgument( 1 ) ); 00729 SetResult( CREATE_INTEGER( GetTypeManager(), lArg1 * lArg2 ) ); 00730 } 00731 }; 00732 00733 OPERATOR( TInteger_Mod ) 00734 { 00735 void operator()() 00736 { 00737 DECL_INTEGER( lArg1, GetArgument( 0 ) ); 00738 DECL_INTEGER( lArg2, GetArgument( 1 ) ); 00739 SetResult( CREATE_INTEGER( GetTypeManager(), lArg1 % lArg2 ) ); 00740 } 00741 }; 00742 00743 OPERATOR( TInteger_Less ) 00744 { 00745 void operator()() 00746 { 00747 DECL_INTEGER( lArg1, GetArgument( 0 ) ); 00748 DECL_INTEGER( lArg2, GetArgument( 1 ) ); 00749 SetResult( CREATE_BOOLEAN( GetTypeManager(), lArg1 < lArg2 ) ); 00750 } 00751 }; 00752 00753 OPERATOR( TInteger_Greater ) 00754 { 00755 void operator()() 00756 { 00757 DECL_INTEGER( lArg1, GetArgument( 0 ) ); 00758 DECL_INTEGER( lArg2, GetArgument( 1 ) ); 00759 SetResult( CREATE_BOOLEAN( GetTypeManager(), lArg1 > lArg2 ) ); 00760 } 00761 }; 00762 00763 OPERATOR( TInteger_LessEquals ) 00764 { 00765 void operator()() 00766 { 00767 DECL_INTEGER( lArg1, GetArgument( 0 ) ); 00768 DECL_INTEGER( lArg2, GetArgument( 1 ) ); 00769 SetResult( CREATE_BOOLEAN( GetTypeManager(), lArg1 <= lArg2 ) ); 00770 } 00771 }; 00772 00773 OPERATOR( TInteger_GreaterEquals ) 00774 { 00775 void operator()() 00776 { 00777 DECL_INTEGER( lArg1, GetArgument( 0 ) ); 00778 DECL_INTEGER( lArg2, GetArgument( 1 ) ); 00779 SetResult( CREATE_BOOLEAN( GetTypeManager(), lArg1 >= lArg2 ) ); 00780 } 00781 }; 00782 00783 FUNCTION( TInteger_Abs ) 00784 { 00785 void operator()() 00786 { 00787 DECL_INTEGER( lArg, GetArgument( 0 ) ); 00788 SetResult( CREATE_INTEGER( GetTypeManager(), labs( lArg ) ) ); 00789 } 00790 }; 00791 00792 FUNCTION( TInteger_Max ) 00793 { 00794 void operator()() 00795 { 00796 DECL_INTEGER( lArg1, GetArgument( 0 ) ); 00797 DECL_INTEGER( lArg2, GetArgument( 1 ) ); 00798 SetResult( CREATE_INTEGER( GetTypeManager(), max( lArg1, lArg2 ) ) ); 00799 } 00800 }; 00801 00802 FUNCTION( TInteger_Min ) 00803 { 00804 void operator()() 00805 { 00806 DECL_INTEGER( lArg1, GetArgument( 0 ) ); 00807 DECL_INTEGER( lArg2, GetArgument( 1 ) ); 00808 SetResult( CREATE_INTEGER( GetTypeManager(), min( lArg1, lArg2 ) ) ); 00809 } 00810 }; 00811 00812 METHOD( TInteger_Abs_Method ) 00813 { 00814 void operator()() 00815 { 00816 DECL_INTEGER( lThis, GetThis() ); 00817 SetResult( CREATE_INTEGER( GetTypeManager(), labs( lThis ) ) ); 00818 } 00819 }; 00820 00821 METHOD( TInteger_Max_Method ) 00822 { 00823 void operator()() 00824 { 00825 DECL_INTEGER( lThis, GetThis() ); 00826 DECL_INTEGER( lArg, GetArgument( 0 ) ); 00827 SetResult( CREATE_INTEGER( GetTypeManager(), max( lThis, lArg ) ) ); 00828 } 00829 }; 00830 00831 METHOD( TInteger_Min_Method ) 00832 { 00833 void operator()() 00834 { 00835 DECL_INTEGER( lThis, GetThis() ); 00836 DECL_INTEGER( lArg, GetArgument( 0 ) ); 00837 SetResult( CREATE_INTEGER( GetTypeManager(), min( lThis, lArg ) ) ); 00838 } 00839 }; 00840 00841 void TInteger_MethodFactory::GetFeatures( const OclSignature::Method& signature, OclMeta::MethodVector& vecFeatures ) 00842 { 00843 std::string strName = signature.GetName(); 00844 int iCount = signature.GetParameterCount(); 00845 FPV vecParams; 00846 TS vecType; 00847 00848 if ( ( strName == "abs" ) && iCount == 0 ) { 00849 vecType.push_back( "ocl::Integer" ); 00850 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TReal_Abs_Method(), false ) ); 00851 return; 00852 } 00853 00854 if ( ( strName == "max" ) && iCount == 1 ) { 00855 vecParams.push_back( FP( "integer", "ocl::Integer", true ) ); 00856 vecType.push_back( "ocl::Integer" ); 00857 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TReal_Max_Method(), false ) ); 00858 return; 00859 } 00860 00861 if ( ( strName == "min" ) && iCount == 1 ) { 00862 vecParams.push_back( FP( "integer", "ocl::Integer", true ) ); 00863 vecType.push_back( "ocl::Integer" ); 00864 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TReal_Min_Method(), false ) ); 00865 return; 00866 } 00867 } 00868 00869 //############################################################################################################################################## 00870 // 00871 // T Y P E O F ocl::Type 00872 // 00873 //############################################################################################################################################## 00874 00875 //############################################################################################################################################## 00876 // 00877 // C O M M O N F E A T U R E S O F ocl::Set , ocl::Bag , ocl::Sequence , ocl::OrderedSet 00878 // 00879 //############################################################################################################################################## 00880 00881 ATTRIBUTE( TCollection_Size ) 00882 { 00883 void operator()() 00884 { 00885 DECL_COLLECTION( collThis, GetThis() ); 00886 SetResult( CREATE_INTEGER( GetTypeManager(), collThis.size() ) ); 00887 } 00888 }; 00889 00890 METHOD( TCollection_IsEmpty ) 00891 { 00892 void operator()() 00893 { 00894 DECL_COLLECTION( collThis, GetThis() ); 00895 SetResult( CREATE_BOOLEAN( GetTypeManager(), collThis.empty() ) ); 00896 } 00897 }; 00898 00899 METHOD( TCollection_NotEmpty ) 00900 { 00901 void operator()() 00902 { 00903 DECL_COLLECTION( collThis, GetThis() ); 00904 SetResult( CREATE_BOOLEAN( GetTypeManager(), ! collThis.empty() ) ); 00905 } 00906 }; 00907 00908 METHOD( TCollection_Includes ) 00909 { 00910 void operator()() 00911 { 00912 DECL_COLLECTION( collThis, GetThis() ); 00913 SetResult( CREATE_BOOLEAN( GetTypeManager(), std::find( collThis.begin(), collThis.end(), GetArgument( 0 ) ) != collThis.end() ) ); 00914 } 00915 }; 00916 00917 METHOD( TCollection_Excludes ) 00918 { 00919 void operator()() 00920 { 00921 DECL_COLLECTION( collThis, GetThis() ); 00922 SetResult( CREATE_BOOLEAN( GetTypeManager(), std::find( collThis.begin(), collThis.end(), GetArgument( 0 ) ) == collThis.end() ) ); 00923 } 00924 }; 00925 00926 METHOD( TCollection_Count ) 00927 { 00928 void operator()() 00929 { 00930 DECL_COLLECTION( collThis, GetThis() ); 00931 long lResult = 0; 00932 for ( unsigned int i = 0 ; i < collThis.size() ; i++ ) 00933 if ( collThis[ i ] == GetArgument( 0 ) ) 00934 lResult++; 00935 SetResult( CREATE_INTEGER( GetTypeManager(), lResult ) ); 00936 } 00937 }; 00938 00939 METHOD( TCollection_IncludesAll ) 00940 { 00941 void operator()() 00942 { 00943 DECL_COLLECTION( collThis, GetThis() ); 00944 DECL_ITERATOR( spIterator, GetArgument( 0 ) ); 00945 while ( spIterator->HasNext() ) { 00946 OclMeta::ObjectVector::iterator i = std::find( collThis.begin(), collThis.end(), spIterator->GetNext() ); 00947 if ( i == collThis.end() ) { 00948 SetResult( CREATE_BOOLEAN( GetTypeManager(), false ) ); 00949 return; 00950 } 00951 collThis.erase( i ); 00952 } 00953 SetResult( CREATE_BOOLEAN( GetTypeManager(), true ) ); 00954 } 00955 }; 00956 00957 METHOD( TCollection_ExcludesAll ) 00958 { 00959 void operator()() 00960 { 00961 DECL_COLLECTION( collThis, GetThis() ); 00962 DECL_ITERATOR( spIterator, GetArgument( 0 ) ); 00963 while ( spIterator->HasNext() ) 00964 if ( std::find( collThis.begin(), collThis.end(), spIterator->GetNext() ) != collThis.end() ) { 00965 SetResult( CREATE_BOOLEAN( GetTypeManager(), false ) ); 00966 return; 00967 } 00968 SetResult( CREATE_BOOLEAN( GetTypeManager(), true ) ); 00969 } 00970 }; 00971 00972 METHOD( TCollection_AsSet ) 00973 { 00974 void operator()() 00975 { 00976 if ( GetThis().GetTypeName() == "ocl::Set" ) { 00977 SetResult( GetThis() ); 00978 return; 00979 } 00980 DECL_COLLECTION( collThis, GetThis() ); 00981 SetResult( CREATE_SET( GetTypeManager(), collThis ) ); 00982 } 00983 }; 00984 00985 METHOD( TCollection_AsSequence ) 00986 { 00987 void operator()() 00988 { 00989 if ( GetThis().GetTypeName() == "ocl::Sequence" ) { 00990 SetResult( GetThis() ); 00991 return; 00992 } 00993 DECL_COLLECTION( collThis, GetThis() ); 00994 SetResult( CREATE_SEQUENCE( GetTypeManager(), collThis ) ); 00995 } 00996 }; 00997 00998 METHOD( TCollection_AsBag ) 00999 { 01000 void operator()() 01001 { 01002 if ( GetThis().GetTypeName() == "ocl::Bag" ) { 01003 SetResult( GetThis() ); 01004 return; 01005 } 01006 DECL_COLLECTION( collThis, GetThis() ); 01007 SetResult( CREATE_BAG( GetTypeManager(), collThis ) ); 01008 } 01009 }; 01010 01011 // -- 01012 METHOD( TCollection_AsOrderedSet ) 01013 { 01014 void operator()() 01015 { 01016 if ( GetThis().GetTypeName() == "ocl::OrderedSet" ) { 01017 SetResult( GetThis() ); 01018 return; 01019 } 01020 DECL_COLLECTION( collThis, GetThis() ); 01021 SetResult( CREATE_ORDEREDSET( GetTypeManager(), collThis ) ); 01022 } 01023 }; 01024 // -- 01025 ITERATOR( TCollection_Exists ) // true - if the collection contains at least one element - for which the condition evaluates to true 01026 { 01027 private: 01028 int iAccumulator; 01029 01030 void Initialize() 01031 { 01032 OclIterator::Initialize(); 01033 iAccumulator = -1; 01034 } 01035 01036 void operator()() 01037 { 01038 if ( iAccumulator != 1 && ! GetSubResult().IsUndefined() ) { 01039 DECL_BOOLEAN( bArg, GetSubResult() ); 01040 if ( bArg ) { 01041 iAccumulator = 1; 01042 SetDoStop( true ); 01043 } 01044 else 01045 iAccumulator = 0; 01046 } 01047 } 01048 01049 OclMeta::Object GetResult() const 01050 { 01051 return CREATE_BOOLEAN( GetTypeManager(), iAccumulator == 1 ); 01052 } 01053 }; 01054 01055 ITERATOR( TCollection_ForAll ) 01056 { 01057 private: 01058 int iAccumulator; 01059 01060 void Initialize() 01061 { 01062 OclIterator::Initialize(); 01063 iAccumulator = 1; 01064 } 01065 01066 void operator()() 01067 { 01068 SetDoSnapshot( false ); 01069 if ( iAccumulator != -1 ) { 01070 if ( GetSubResult().IsUndefined() ) { 01071 iAccumulator = -1; 01072 SetDoStop( true ); 01073 } 01074 else { 01075 DECL_BOOLEAN( bArg, GetSubResult() ); 01076 if ( ! bArg ) { 01077 iAccumulator = 0; 01078 SetDoStop( true ); 01079 SetDoSnapshot( true ); 01080 } 01081 } 01082 } 01083 } 01084 01085 OclMeta::Object GetResult() const 01086 { 01087 return CREATE_BOOLEAN( GetTypeManager(), iAccumulator != 0 ); 01088 } 01089 }; 01090 01091 ITERATOR( TCollection_IsUnique ) 01092 { 01093 private : 01094 OclMeta::ObjectVector vecObjects; 01095 bool bResult; 01096 01097 void Initialize() 01098 { 01099 OclIterator::Initialize(); 01100 vecObjects.clear(); 01101 bResult = true; 01102 } 01103 01104 void operator()() 01105 { 01106 if ( bResult ) { 01107 if ( std::find( vecObjects.begin(), vecObjects.end(), GetSubResult() ) != vecObjects.end() ) { 01108 bResult = false; 01109 SetDoStop( true ); 01110 } 01111 else 01112 vecObjects.push_back( GetSubResult() ); 01113 } 01114 } 01115 01116 OclMeta::Object GetResult() const 01117 { 01118 return CREATE_BOOLEAN( GetTypeManager(), bResult ); 01119 } 01120 01121 void Finalize() 01122 { 01123 vecObjects.clear(); 01124 OclIterator::Finalize(); 01125 } 01126 }; 01127 01128 ITERATOR( TCollection_Any ) // returns one element - the condition evaluates to true for that element 01129 { 01130 private : 01131 OclMeta::ObjectVector vecObjects; 01132 01133 void Initialize() 01134 { 01135 OclIterator::Initialize(); 01136 vecObjects.clear(); 01137 } 01138 01139 void operator()() 01140 { 01141 if ( GetSubResult().IsUndefined() ) 01142 return; 01143 DECL_BOOLEAN( bResult, GetSubResult() ); 01144 if ( bResult ) { 01145 vecObjects.push_back( GetArgument( 0 ) ); 01146 SetDoStop( true ); 01147 } 01148 } 01149 01150 OclMeta::Object GetResult() const 01151 { 01152 return ( vecObjects.empty() ) ? OclMeta::Object::UNDEFINED : vecObjects[ 0 ]; 01153 } 01154 01155 void Finalize() 01156 { 01157 vecObjects.clear(); 01158 OclIterator::Finalize(); 01159 } 01160 }; 01161 01162 ITERATOR( TCollection_One ) // true - if the collection contains just one element - for which the condition evaluates to true 01163 { 01164 private : 01165 int iCount; 01166 01167 void Initialize() 01168 { 01169 OclIterator::Initialize(); 01170 iCount = 0; 01171 } 01172 01173 void operator()() 01174 { 01175 if ( GetSubResult().IsUndefined() ) 01176 return; 01177 DECL_BOOLEAN( bResult, GetSubResult() ); 01178 if ( bResult ) { 01179 iCount++; 01180 if ( iCount > 1 ) 01181 SetDoStop( true ); 01182 } 01183 } 01184 01185 OclMeta::Object GetResult() const 01186 { 01187 return CREATE_BOOLEAN( GetTypeManager(), iCount == 1 ); 01188 } 01189 }; 01190 01191 // -- 01192 // 01193 ITERATOR( TCollection_SortedBy) 01194 { 01195 private : 01196 typedef std::map<long, OclMeta::Object> TintMap; 01197 TintMap intMap; 01198 bool isInt; 01199 typedef std::map<double, OclMeta::Object> TrealMap; 01200 TrealMap realMap; 01201 bool isReal; 01202 typedef std::map<std::string, OclMeta::Object> TstringMap; 01203 TstringMap stringMap; 01204 bool isString; 01205 01206 01207 void Initialize() 01208 { 01209 OclIterator::Initialize(); 01210 intMap.clear(); 01211 isInt = false; 01212 realMap.clear(); 01213 isReal = false; 01214 stringMap.clear(); 01215 isString = false; 01216 } 01217 01218 void operator()() 01219 { 01220 OclMeta::Object keyObj = GetSubResult(); 01221 if (!keyObj.IsComparable()) 01222 { 01223 ThrowException( "Key must be: Integer or Real or String." ); 01224 return; 01225 } 01226 OclMeta::Object store = GetSubOriResult(); 01227 std::string keytype = keyObj.GetTypeName(); 01228 01229 if (keytype == "ocl::Integer") 01230 { 01231 isInt = true; 01232 DECL_INTEGER(key, keyObj); 01233 intMap.insert(TintMap::value_type(key, store)); 01234 } 01235 else if (keytype == "ocl::Real") 01236 { 01237 isReal = true; 01238 DECL_REAL(key, keyObj); 01239 realMap.insert(TrealMap::value_type(key, store)); 01240 } 01241 else if (keytype == "ocl::String") 01242 { 01243 isString = true; 01244 DECL_STRING(key, keyObj); 01245 stringMap.insert(TstringMap::value_type(key, store)); 01246 } 01247 01248 } 01249 01250 OclMeta::Object GetResult() const 01251 { 01252 OclMeta::ObjectVector vecSelecteds; 01253 vecSelecteds.clear(); 01254 if (isInt) 01255 { 01256 TintMap::const_iterator it = intMap.begin(); 01257 for (; it != intMap.end(); ++it) 01258 vecSelecteds.push_back( (*it).second); 01259 } 01260 else if (isReal) 01261 { 01262 TrealMap::const_iterator it = realMap.begin(); 01263 for (; it != realMap.end(); ++it) 01264 vecSelecteds.push_back( (*it).second); 01265 } 01266 else if (isString) 01267 { 01268 TstringMap::const_iterator it = stringMap.begin(); 01269 for (; it != stringMap.end(); ++it) 01270 vecSelecteds.push_back( (*it).second); 01271 } 01272 01273 return CREATE_ORDEREDSET( GetTypeManager(), vecSelecteds ); 01274 } 01275 01276 void Finalize() 01277 { 01278 intMap.clear(); 01279 isInt = false; 01280 realMap.clear(); 01281 isReal = false; 01282 stringMap.clear(); 01283 isString = false; 01284 OclIterator::Finalize(); 01285 } 01286 }; 01287 // -- 01288 01289 void TCollection_AttributeFactory::GetFeatures( const OclSignature::Attribute& signature, OclMeta::AttributeVector& vecFeatures ) 01290 { 01291 std::string strName = signature.GetName(); 01292 TS vecType; 01293 01294 if ( strName == "size" ) { 01295 vecType.push_back( "ocl::Integer" ); 01296 vecFeatures.push_back( new OclMeta::Attribute( strName, vecType, new TCollection_Size(), false ) ); 01297 return; 01298 } 01299 } 01300 01301 void TCollection_MethodFactory::GetFeatures( const OclSignature::Method& signature, OclMeta::MethodVector& vecFeatures ) 01302 { 01303 std::string strName = signature.GetName(); 01304 int iCount = signature.GetParameterCount(); 01305 FPV vecParams; 01306 TS vecType; 01307 01308 if ( ( strName == "isEmpty" ) && iCount == 0 ) { 01309 vecType.push_back( "ocl::Boolean" ); 01310 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TCollection_IsEmpty(), false ) ); 01311 return; 01312 } 01313 01314 if ( ( strName == "notEmpty" ) && iCount == 0 ) { 01315 vecType.push_back( "ocl::Boolean" ); 01316 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TCollection_NotEmpty(), false ) ); 01317 return; 01318 } 01319 01320 if ( ( strName == "includes" ) && iCount == 1 ) { 01321 vecParams.push_back( FP( "any", "ocl::Any", true ) ); 01322 vecType.push_back( "ocl::Boolean" ); 01323 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TCollection_Includes(), false ) ); 01324 return; 01325 } 01326 01327 if ( ( strName == "excludes" ) && iCount == 1 ) { 01328 vecParams.push_back( FP( "any", "ocl::Any", true ) ); 01329 vecType.push_back( "ocl::Boolean" ); 01330 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TCollection_Excludes(), false ) ); 01331 return; 01332 } 01333 01334 if ( ( strName == "includesAll" ) && iCount == 1 ) { 01335 vecParams.push_back( FP( "collection", "ocl::Collection", true ) ); 01336 vecType.push_back( "ocl::Boolean" ); 01337 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TCollection_IncludesAll(), false ) ); 01338 return; 01339 } 01340 01341 if ( ( strName == "excludesAll" ) && iCount == 1 ) { 01342 vecParams.push_back( FP( "collection", "ocl::Collection", true ) ); 01343 vecType.push_back( "ocl::Boolean" ); 01344 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TCollection_ExcludesAll(), false ) ); 01345 return; 01346 } 01347 01348 if ( ( strName == "count" ) && iCount == 1 ) { 01349 vecParams.push_back( FP( "any", "ocl::Any", true ) ); 01350 vecType.push_back( "ocl::Integer" ); 01351 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TCollection_Count(), false ) ); 01352 return; 01353 } 01354 01355 if ( ( strName == "asSet" ) && iCount == 0 ) { 01356 vecType.push_back( "ocl::Set" ); 01357 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 01358 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TCollection_AsSet(), false ) ); 01359 return; 01360 } 01361 01362 if ( ( strName == "asBag" ) && iCount == 0 ) { 01363 vecType.push_back( "ocl::Bag" ); 01364 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 01365 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TCollection_AsBag(), false ) ); 01366 return; 01367 } 01368 01369 // -- 01370 if ( ( strName == "asOrderedSet" ) && iCount == 0 ) { 01371 vecType.push_back( "ocl::OrderedSet" ); 01372 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 01373 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TCollection_AsOrderedSet(), false ) ); 01374 return; 01375 } 01376 // -- 01377 01378 if ( ( strName == "asSequence" ) && iCount == 0 ) { 01379 vecType.push_back( "ocl::Sequence" ); 01380 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 01381 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TCollection_AsSequence(), false ) ); 01382 return; 01383 } 01384 } 01385 01386 void TCollection_IteratorFactory::GetFeatures( const OclSignature::Iterator& signature, OclMeta::IteratorVector& vecFeatures ) 01387 { 01388 std::string strName = signature.GetName(); 01389 TS vecType; 01390 01391 if ( strName == "exists" ) { 01392 vecType.push_back( "ocl::Boolean" ); 01393 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Boolean", vecType, new TCollection_Exists(), false ) ); 01394 return; 01395 } 01396 01397 if ( strName == "forAll" ) { 01398 vecType.push_back( "ocl::Boolean" ); 01399 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Boolean", vecType, new TCollection_ForAll(), false ) ); 01400 return; 01401 } 01402 01403 if ( strName == "isUnique" ) { 01404 vecType.push_back( "ocl::Boolean" ); 01405 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Any", vecType, new TCollection_IsUnique(), false ) ); 01406 return; 01407 } 01408 01409 if ( strName == "any" ) { 01410 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 01411 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Boolean", vecType, new TCollection_Any(), false ) ); 01412 return; 01413 } 01414 01415 if ( strName == "one" ) { 01416 vecType.push_back( "ocl::Boolean" ); 01417 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Boolean", vecType, new TCollection_One(), false ) ); 01418 return; 01419 } 01420 // -- 01421 if ( strName == "sortedBy" ) { 01422 vecType.push_back( "ocl::OrderedSet" ); 01423 vecType.push_back( TYPE_AGGREGATED_OBJECT ); // ?? 01424 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Any", vecType, new TCollection_SortedBy(), false ) ); 01425 return; 01426 } 01427 // -- 01428 } 01429 01430 //############################################################################################################################################## 01431 // 01432 // T Y P E O F ocl::Set 01433 // 01434 //############################################################################################################################################## 01435 01436 OPERATOR( TSet_Plus ) // unio Set 01437 { 01438 void operator()() 01439 { 01440 DECL_COLLECTION( collThis, GetArgument( 0 ) ); 01441 DECL_ITERATOR( spIterator, GetArgument( 1 ) ); 01442 while ( spIterator->HasNext() ) { 01443 OclMeta::Object object = spIterator->GetNext(); 01444 if ( std::find( collThis.begin(), collThis.end(), object ) == collThis.end() ) 01445 collThis.push_back( object ); 01446 } 01447 SetResult( CREATE_SET( GetTypeManager(), collThis ) ); 01448 } 01449 }; 01450 01451 OPERATOR( TSet_PlusBag ) // unio Bag 01452 { 01453 void operator()() 01454 { 01455 DECL_COLLECTION( collThis, GetArgument( 0 ) ); 01456 DECL_ITERATOR( spIterator, GetArgument( 1 ) ); 01457 while ( spIterator->HasNext() ) 01458 collThis.push_back( spIterator->GetNext() ); 01459 SetResult( CREATE_BAG( GetTypeManager(), collThis ) ); 01460 } 01461 }; 01462 01463 OPERATOR( TSet_Times ) // intersection 01464 { 01465 void operator()() 01466 { 01467 DECL_COLLECTION( collThis, GetArgument( 0 ) ); 01468 DECL_ITERATOR( spIterator, GetArgument( 1 ) ); 01469 OclMeta::ObjectVector collOut; 01470 while ( spIterator->HasNext() ) { 01471 OclMeta::Object object = spIterator->GetNext(); 01472 if ( std::find( collThis.begin(), collThis.end(), object ) != collThis.end() ) 01473 if ( std::find( collOut.begin(), collOut.end(), object ) == collOut.end() ) // unnecessary 01474 collOut.push_back( object ); 01475 } 01476 SetResult( CREATE_SET( GetTypeManager(), collOut ) ); 01477 } 01478 }; 01479 01480 OPERATOR( TSet_Minus ) 01481 { 01482 void operator()() 01483 { 01484 DECL_COLLECTION( collThis, GetArgument( 0 ) ); 01485 DECL_ITERATOR( spIterator, GetArgument( 1 ) ); 01486 while ( spIterator->HasNext() ) { 01487 OclMeta::ObjectVector::iterator i = std::find( collThis.begin(), collThis.end(), spIterator->GetNext() ); 01488 if ( i != collThis.end() ) 01489 collThis.erase( i ); 01490 } 01491 SetResult( CREATE_SET( GetTypeManager(), collThis ) ); 01492 } 01493 }; 01494 01495 OPERATOR( TSet_Percent ) // symmetricdifference 01496 { 01497 void operator()() 01498 { 01499 DECL_COLLECTION( collThis, GetArgument( 0 ) ); 01500 DECL_ITERATOR( spIterator, GetArgument( 1 ) ); 01501 OclMeta::ObjectVector collOut; 01502 OclMeta::ObjectVector collTemp; 01503 while ( spIterator->HasNext() ) { 01504 OclMeta::Object object = spIterator->GetNext(); 01505 if ( std::find( collThis.begin(), collThis.end(), object ) == collThis.end() ) 01506 collOut.push_back( object ); 01507 else 01508 collTemp.push_back( object ); 01509 } 01510 for ( unsigned int i = 0 ; i < collThis.size() ; i++ ) 01511 if ( std::find( collTemp.begin(), collTemp.end(), collThis[ i ] ) == collTemp.end() ) 01512 collOut.push_back( collThis[ i ] ); 01513 SetResult( CREATE_SET( GetTypeManager(), collOut ) ); 01514 } 01515 }; 01516 01517 METHOD( TSet_Union ) 01518 { 01519 void operator()() 01520 { 01521 DECL_COLLECTION( collThis, GetThis() ); 01522 DECL_ITERATOR( spIterator, GetArgument( 0 ) ); 01523 while ( spIterator->HasNext() ) { 01524 OclMeta::Object object = spIterator->GetNext(); 01525 if ( std::find( collThis.begin(), collThis.end(), object ) == collThis.end() ) 01526 collThis.push_back( object ); 01527 } 01528 SetResult( CREATE_SET( GetTypeManager(), collThis ) ); 01529 } 01530 }; 01531 01532 METHOD( TSet_UnionBag ) 01533 { 01534 void operator()() 01535 { 01536 DECL_COLLECTION( collThis, GetThis() ); 01537 DECL_ITERATOR( spIterator, GetArgument( 0 ) ); 01538 while ( spIterator->HasNext() ) 01539 collThis.push_back( spIterator->GetNext() ); 01540 SetResult( CREATE_BAG( GetTypeManager(), collThis ) ); 01541 } 01542 }; 01543 01544 METHOD( TSet_Intersection ) 01545 { 01546 void operator()() 01547 { 01548 DECL_COLLECTION( collThis, GetThis() ); 01549 DECL_ITERATOR( spIterator, GetArgument( 0 ) ); 01550 OclMeta::ObjectVector collOut; 01551 while ( spIterator->HasNext() ) { 01552 OclMeta::Object object = spIterator->GetNext(); 01553 if ( ! ( std::find( collThis.begin(), collThis.end(), object ) == collThis.end() ) ) 01554 if ( std::find( collOut.begin(), collOut.end(), object ) == collOut.end() ) 01555 collOut.push_back( object ); 01556 } 01557 SetResult( CREATE_SET( GetTypeManager(), collOut ) ); 01558 } 01559 }; 01560 01561 METHOD( TSet_Subtract ) 01562 { 01563 void operator()() 01564 { 01565 DECL_COLLECTION( collThis, GetThis() ); 01566 DECL_ITERATOR( spIterator, GetArgument( 0 ) ); 01567 while ( spIterator->HasNext() ) { 01568 OclMeta::ObjectVector::iterator i = std::find( collThis.begin(), collThis.end(), spIterator->GetNext() ); 01569 if ( i != collThis.end() ) 01570 collThis.erase( i ); 01571 } 01572 SetResult( CREATE_SET( GetTypeManager(), collThis ) ); 01573 } 01574 }; 01575 01576 METHOD( TSet_SymmDiff ) 01577 { 01578 void operator()() 01579 { 01580 DECL_COLLECTION( collThis, GetThis() ); 01581 DECL_ITERATOR( spIterator, GetArgument( 0 ) ); 01582 OclMeta::ObjectVector collOut; 01583 OclMeta::ObjectVector collTemp; 01584 while ( spIterator->HasNext() ) { 01585 OclMeta::Object object = spIterator->GetNext(); 01586 if ( std::find( collThis.begin(), collThis.end(), object ) == collThis.end() ) 01587 collOut.push_back( object ); 01588 else 01589 collTemp.push_back( object ); 01590 } 01591 for ( unsigned int i = 0 ; i < collThis.size() ; i++ ) 01592 if ( std::find( collTemp.begin(), collTemp.end(), collThis[ i ] ) == collTemp.end() ) 01593 collOut.push_back( collThis[ i ] ); 01594 SetResult( CREATE_SET( GetTypeManager(), collOut ) ); 01595 } 01596 }; 01597 01598 METHOD( TSet_Including ) 01599 { 01600 void operator()() 01601 { 01602 DECL_COLLECTION( collThis, GetThis() ); 01603 if ( std::find( collThis.begin(), collThis.end(), GetArgument( 0 ) ) == collThis.end() ) 01604 collThis.push_back( GetArgument( 0 ) ); 01605 SetResult( CREATE_SET( GetTypeManager(), collThis ) ); 01606 } 01607 }; 01608 01609 METHOD( TSet_Excluding ) 01610 { 01611 void operator()() 01612 { 01613 DECL_COLLECTION( collThis, GetThis() ); 01614 OclMeta::ObjectVector::iterator i = std::find( collThis.begin(), collThis.end(), GetArgument( 0 ) ); 01615 if ( i != collThis.end() ) 01616 collThis.erase( i ); 01617 SetResult( CREATE_SET( GetTypeManager(), collThis ) ); 01618 } 01619 }; 01620 01621 ITERATOR( TSet_Select ) 01622 { 01623 private : 01624 OclMeta::ObjectVector m_vecSelecteds; 01625 01626 void Initialize() 01627 { 01628 OclIterator::Initialize(); 01629 m_vecSelecteds.clear(); 01630 } 01631 01632 void operator()() 01633 { 01634 if ( ! GetSubResult().IsUndefined() ) { 01635 DECL_BOOLEAN( bArg, GetSubResult() ); 01636 if ( bArg && std::find( m_vecSelecteds.begin(), m_vecSelecteds.end(), GetArgument( 0 ) ) == m_vecSelecteds.end() ) 01637 m_vecSelecteds.push_back( GetArgument( 0 ) ); 01638 } 01639 } 01640 01641 OclMeta::Object GetResult() const 01642 { 01643 return CREATE_SET( GetTypeManager(), m_vecSelecteds ); 01644 } 01645 01646 void Finalize() 01647 { 01648 m_vecSelecteds.clear(); 01649 OclIterator::Finalize(); 01650 } 01651 }; 01652 01653 ITERATOR( TSet_Reject ) 01654 { 01655 private : 01656 OclMeta::ObjectVector m_vecSelecteds; 01657 01658 void Initialize() 01659 { 01660 OclIterator::Initialize(); 01661 m_vecSelecteds.clear(); 01662 } 01663 01664 void operator()() 01665 { 01666 if ( ! GetSubResult().IsUndefined() ) { 01667 DECL_BOOLEAN( bArg, GetSubResult() ); 01668 if ( ! bArg && std::find( m_vecSelecteds.begin(), m_vecSelecteds.end(), GetArgument( 0 ) ) == m_vecSelecteds.end() ) 01669 m_vecSelecteds.push_back( GetArgument( 0 ) ); 01670 } 01671 } 01672 01673 OclMeta::Object GetResult() const 01674 { 01675 return CREATE_SET( GetTypeManager(), m_vecSelecteds ); 01676 } 01677 01678 void Finalize() 01679 { 01680 m_vecSelecteds.clear(); 01681 OclIterator::Finalize(); 01682 } 01683 }; 01684 01685 ITERATOR( TSet_Collect ) 01686 { 01687 private : 01688 OclMeta::ObjectVector m_vecSelecteds; 01689 01690 void Initialize() 01691 { 01692 OclIterator::Initialize(); 01693 m_vecSelecteds.clear(); 01694 } 01695 01696 void operator()() 01697 { 01698 m_vecSelecteds.push_back( GetSubResult() ); 01699 } 01700 01701 OclMeta::Object GetResult() const 01702 { 01703 return CREATE_BAG( GetTypeManager(), m_vecSelecteds ); 01704 } 01705 01706 void Finalize() 01707 { 01708 m_vecSelecteds.clear(); 01709 OclIterator::Finalize(); 01710 } 01711 }; 01712 01713 void TSet_MethodFactory::GetFeatures( const OclSignature::Method& signature, OclMeta::MethodVector& vecFeatures ) 01714 { 01715 std::string strName = signature.GetName(); 01716 int iCount = signature.GetParameterCount(); 01717 FPV vecParams; 01718 TS vecType; 01719 01720 if ( ( strName == "union" ) && iCount == 1 ) { 01721 vecParams.push_back( FP( "set", "ocl::Set", true ) ); 01722 vecType.push_back( "ocl::Set" ); 01723 vecType.push_back( TYPE_COMPOUNDARGUMENT_SELF_BASE ); 01724 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSet_Union(), false ) ); 01725 01726 vecParams.clear(); 01727 vecType.clear(); 01728 vecParams.push_back( FP( "bag", "ocl::Bag", true ) ); 01729 vecType.push_back( "ocl::Bag" ); 01730 vecType.push_back( TYPE_COMPOUNDARGUMENT_SELF_BASE ); 01731 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSet_UnionBag(), false ) ); 01732 return; 01733 } 01734 01735 if ( ( strName == "subtract" ) && iCount == 1 ) { 01736 vecParams.push_back( FP( "set", "ocl::Set", true ) ); 01737 vecType.push_back( "ocl::Set" ); 01738 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 01739 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSet_Subtract(), false ) ); 01740 return; 01741 } 01742 01743 if ( ( strName == "intersection" ) && iCount == 1 ) { 01744 vecParams.push_back( FP( "set", "ocl::Set", true ) ); 01745 vecType.push_back( "ocl::Set" ); 01746 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 01747 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSet_Intersection(), false ) ); 01748 01749 vecParams.clear(); 01750 vecType.clear(); 01751 vecParams.push_back( FP( "bag", "ocl::Bag", true ) ); 01752 vecType.push_back( "ocl::Set" ); 01753 vecType.push_back( TYPE_COMPOUNDARGUMENT_SELF_BASE ); 01754 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSet_Intersection(), false ) ); 01755 return; 01756 } 01757 01758 if ( ( strName == "symmetricDifference" ) && iCount == 1 ) { 01759 vecParams.push_back( FP( "set", "ocl::Set", true ) ); 01760 vecType.push_back( "ocl::Set" ); 01761 vecType.push_back( TYPE_COMPOUNDARGUMENT_SELF_BASE ); 01762 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSet_SymmDiff(), false ) ); 01763 return; 01764 } 01765 01766 if ( ( strName == "including" ) && iCount == 1 ) { 01767 vecParams.push_back( FP( "any", "ocl::Any", true ) ); 01768 vecType.push_back( "ocl::Set" ); 01769 vecType.push_back( TYPE_ARGUMENT_SELF_BASE ); 01770 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSet_Including(), false ) ); 01771 return; 01772 } 01773 01774 if ( ( strName == "excluding" ) && iCount == 1 ) { 01775 vecParams.push_back( FP( "any", "ocl::Any", true ) ); 01776 vecType.push_back( "ocl::Set" ); 01777 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 01778 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSet_Excluding(), false ) ); 01779 return; 01780 } 01781 } 01782 01783 void TSet_IteratorFactory::GetFeatures( const OclSignature::Iterator& signature, OclMeta::IteratorVector& vecFeatures ) 01784 { 01785 std::string strName = signature.GetName(); 01786 TS vecType; 01787 01788 if ( strName == "select" ) { 01789 vecType.push_back( "ocl::Set" ); 01790 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 01791 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Boolean", vecType, new TSet_Select(), false ) ); 01792 return; 01793 } 01794 01795 if ( strName == "reject" ) { 01796 vecType.push_back( "ocl::Set" ); 01797 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 01798 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Boolean", vecType, new TSet_Reject(), false ) ); 01799 return; 01800 } 01801 01802 if ( strName == "collect" ) { 01803 vecType.push_back( "ocl::Bag" ); 01804 vecType.push_back( TYPE_EXPRESSION_RETURN ); 01805 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Any", vecType, new TSet_Collect(), false ) ); 01806 return; 01807 } 01808 } 01809 01810 //############################################################################################################################################## 01811 // 01812 // T Y P E O F ocl::Sequence 01813 // 01814 //############################################################################################################################################## 01815 01816 OPERATOR( TSequence_Plus ) 01817 { 01818 void operator()() 01819 { 01820 DECL_COLLECTION( collThis, GetArgument( 0 ) ); 01821 DECL_COLLECTION( collArg, GetArgument( 1 ) ); 01822 for ( unsigned int i = 0 ; i < collArg.size() ; i++ ) 01823 collThis.push_back( collArg[ i ] ); 01824 SetResult( CREATE_SEQUENCE( GetTypeManager(), collThis) ); 01825 } 01826 }; 01827 01828 METHOD( TSequence_Union ) 01829 { 01830 void operator()() 01831 { 01832 DECL_COLLECTION( collThis, GetThis() ); 01833 DECL_COLLECTION( collArg, GetArgument( 0 ) ); 01834 for ( unsigned int i = 0 ; i < collArg.size() ; i++ ) 01835 collThis.push_back( collArg[ i ] ); 01836 SetResult( CREATE_SEQUENCE( GetTypeManager(), collThis) ); 01837 } 01838 }; 01839 01840 METHOD( TSequence_Prepend ) 01841 { 01842 void operator()() 01843 { 01844 DECL_COLLECTION( collThis, GetThis() ); 01845 collThis.insert( collThis.begin(), GetArgument( 0 ) ); 01846 SetResult( CREATE_SEQUENCE( GetTypeManager(), collThis ) ); 01847 } 01848 }; 01849 01850 METHOD( TSequence_Append ) 01851 { 01852 void operator()() 01853 { 01854 DECL_COLLECTION( collThis, GetThis() ); 01855 collThis.push_back( GetArgument( 0 ) ); 01856 SetResult( CREATE_SEQUENCE( GetTypeManager(), collThis ) ); 01857 } 01858 }; 01859 01860 METHOD( TSequence_SubSequence ) 01861 { 01862 void operator()() 01863 { 01864 DECL_COLLECTION( collThis, GetThis() ); 01865 DECL_INTEGER( lFrom, GetArgument( 0 ) ); 01866 if ( lFrom < 0 ) { 01867 ThrowException( "Argument 'from' is less than 0." ); 01868 return; 01869 } 01870 if ( lFrom >= (int) collThis.size() ) { 01871 ThrowException( "Argument 'from' equals to or is greater than size of Sequence." ); 01872 return; 01873 } 01874 if ( GetArgumentCount() == 1 ) { 01875 OclMeta::ObjectVector collOut; 01876 for ( unsigned long i = lFrom ; i < collThis.size() ; i++ ) 01877 collOut.push_back( collThis[ i ] ); 01878 SetResult( CREATE_SEQUENCE( GetTypeManager(), collOut ) ); 01879 return; 01880 } 01881 DECL_INTEGER( lTo, GetArgument( 1 ) ); 01882 if ( lTo < lFrom ) { 01883 ThrowException( "Argument 'to' greater than Argument 'from'." ); 01884 return; 01885 } 01886 if ( lTo >= (int) collThis.size() ) { 01887 ThrowException( "Argument 'to' equals to or is greater than size of Sequence." ); 01888 return; 01889 } 01890 OclMeta::ObjectVector collOut; 01891 for ( long i = lFrom ; i <= lTo ; i++ ) 01892 collOut.push_back( collThis[ i ] ); 01893 SetResult( CREATE_SEQUENCE( GetTypeManager(), collOut ) ); 01894 } 01895 }; 01896 01897 METHOD( TSequence_At ) 01898 { 01899 void operator()() 01900 { 01901 DECL_COLLECTION( collThis, GetThis() ); 01902 DECL_INTEGER( lAt, GetArgument( 0 ) ); 01903 if ( lAt < 0 ) { 01904 ThrowException( "Argument 'from' is less than 0." ); 01905 return; 01906 } 01907 if ( lAt >= (int) collThis.size() ) { 01908 ThrowException( "Argument 'from' equals to or is greater than size of Sequence." ); 01909 return; 01910 } 01911 SetResult( collThis[ lAt ] ); 01912 } 01913 }; 01914 01915 METHOD( TSequence_InsertAt ) 01916 { 01917 void operator()() 01918 { 01919 DECL_COLLECTION( collThis, GetThis() ); 01920 DECL_INTEGER( lAt, GetArgument( 0 ) ); 01921 if ( lAt < 0 ) 01922 lAt = 0; 01923 if ( lAt >= (int) collThis.size() ) { 01924 collThis.push_back( GetArgument( 1 ) ); 01925 SetResult( CREATE_SEQUENCE( GetTypeManager(), collThis ) ); 01926 return; 01927 } 01928 OclMeta::ObjectVector vecOut; 01929 for ( int i = 0 ; i < (int) collThis.size() ; i++ ) { 01930 if ( i == lAt ) 01931 vecOut.push_back( GetArgument( 1 ) ); 01932 vecOut.push_back( collThis[ i ] ); 01933 } 01934 SetResult( CREATE_SEQUENCE( GetTypeManager(), vecOut ) ); 01935 } 01936 }; 01937 01938 METHOD( TSequence_IndexOf ) 01939 { 01940 void operator()() 01941 { 01942 DECL_COLLECTION( collThis, GetThis() ); 01943 for ( int i = 0 ; i < (int) collThis.size() ; i ++ ) 01944 if ( collThis[ i ] == GetArgument( 0 ) ) { 01945 SetResult( CREATE_INTEGER( GetTypeManager(), i ) ); 01946 return; 01947 } 01948 SetResult( CREATE_INTEGER( GetTypeManager(), -1 ) ); 01949 } 01950 }; 01951 01952 METHOD( TSequence_First ) 01953 { 01954 void operator()() 01955 { 01956 DECL_COLLECTION( collThis, GetThis() ); 01957 if ( collThis.empty() ) { 01958 ThrowException( "Sequence is empty." ); 01959 return; 01960 } 01961 SetResult( collThis[ 0 ] ); 01962 } 01963 }; 01964 01965 METHOD( TSequence_Last ) 01966 { 01967 void operator()() 01968 { 01969 DECL_COLLECTION( collThis, GetThis() ); 01970 if ( collThis.empty() ) { 01971 ThrowException( "Sequence is empty." ); 01972 return; 01973 } 01974 SetResult( collThis[ collThis.size() - 1 ] ); 01975 } 01976 }; 01977 01978 METHOD( TSequence_Including ) 01979 { 01980 void operator()() 01981 { 01982 DECL_COLLECTION( collThis, GetThis() ); 01983 collThis.push_back( GetArgument( 0 ) ); 01984 SetResult( CREATE_SEQUENCE( GetTypeManager(), collThis ) ); 01985 } 01986 }; 01987 01988 METHOD( TSequence_Excluding ) 01989 { 01990 void operator()() 01991 { 01992 DECL_COLLECTION( collThis, GetThis() ); 01993 bool bFound = false; 01994 do { 01995 bFound = false; 01996 OclMeta::ObjectVector::iterator i = std::find( collThis.begin(), collThis.end(), GetArgument( 0 ) ); 01997 if ( i != collThis.end() ) { 01998 collThis.erase( i ); 01999 bFound = true; 02000 } 02001 } while ( bFound ); 02002 SetResult( CREATE_SEQUENCE( GetTypeManager(), collThis ) ); 02003 } 02004 }; 02005 02006 ITERATOR( TSequence_Select ) 02007 { 02008 private : 02009 OclMeta::ObjectVector m_vecSelecteds; 02010 02011 void Initialize() 02012 { 02013 OclIterator::Initialize(); 02014 m_vecSelecteds.clear(); 02015 } 02016 02017 void operator()() 02018 { 02019 if ( ! GetSubResult().IsUndefined() ) { 02020 DECL_BOOLEAN( bArg, GetSubResult() ); 02021 if ( bArg ) 02022 m_vecSelecteds.push_back( GetArgument( 0 ) ); 02023 } 02024 } 02025 02026 OclMeta::Object GetResult() const 02027 { 02028 return CREATE_SEQUENCE( GetTypeManager(), m_vecSelecteds ); 02029 } 02030 02031 void Finalize() 02032 { 02033 m_vecSelecteds.clear(); 02034 OclIterator::Finalize(); 02035 } 02036 }; 02037 02038 ITERATOR( TSequence_Reject ) 02039 { 02040 private : 02041 OclMeta::ObjectVector m_vecSelecteds; 02042 02043 void Initialize() 02044 { 02045 OclIterator::Initialize(); 02046 m_vecSelecteds.clear(); 02047 } 02048 02049 void operator()() 02050 { 02051 if ( ! GetSubResult().IsUndefined() ) { 02052 DECL_BOOLEAN( bArg, GetSubResult() ); 02053 if ( ! bArg ) 02054 m_vecSelecteds.push_back( GetArgument( 0 ) ); 02055 } 02056 } 02057 02058 OclMeta::Object GetResult() const 02059 { 02060 return CREATE_SEQUENCE( GetTypeManager(), m_vecSelecteds ); 02061 } 02062 02063 void Finalize() 02064 { 02065 m_vecSelecteds.clear(); 02066 OclIterator::Finalize(); 02067 } 02068 }; 02069 02070 ITERATOR( TSequence_Collect ) 02071 { 02072 private : 02073 OclMeta::ObjectVector m_vecSelecteds; 02074 02075 void Initialize() 02076 { 02077 OclIterator::Initialize(); 02078 m_vecSelecteds.clear(); 02079 } 02080 02081 void operator()() 02082 { 02083 m_vecSelecteds.push_back( GetSubResult() ); 02084 } 02085 02086 OclMeta::Object GetResult() const 02087 { 02088 return CREATE_SEQUENCE( GetTypeManager(), m_vecSelecteds ); 02089 } 02090 02091 void Finalize() 02092 { 02093 m_vecSelecteds.clear(); 02094 OclIterator::Finalize(); 02095 } 02096 }; 02097 02098 void TSequence_MethodFactory::GetFeatures( const OclSignature::Method& signature, OclMeta::MethodVector& vecFeatures ) 02099 { 02100 std::string strName = signature.GetName(); 02101 int iCount = signature.GetParameterCount(); 02102 FPV vecParams; 02103 TS vecType; 02104 02105 if ( ( strName == "union" ) && iCount == 1 ) { 02106 vecParams.push_back( FP( "sequence", "ocl::Sequence", true ) ); 02107 vecType.push_back( "ocl::Sequence" ); 02108 vecType.push_back( TYPE_COMPOUNDARGUMENT_SELF_BASE ); 02109 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSequence_Union(), false ) ); 02110 return; 02111 } 02112 02113 if ( ( strName == "prepend" ) && iCount == 1 ) { 02114 vecParams.push_back( FP( "any", "ocl::Any", true ) ); 02115 vecType.push_back( "ocl::Sequence" ); 02116 vecType.push_back( TYPE_ARGUMENT_SELF_BASE ); 02117 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSequence_Prepend(), false ) ); 02118 return; 02119 } 02120 02121 if ( ( strName == "append" ) && iCount == 1 ) { 02122 vecParams.push_back( FP( "any", "ocl::Any", true ) ); 02123 vecType.push_back( "ocl::Sequence" ); 02124 vecType.push_back( TYPE_ARGUMENT_SELF_BASE ); 02125 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSequence_Append(), false ) ); 02126 return; 02127 } 02128 02129 if ( ( strName == "subSequence" ) && iCount == 2 ) { 02130 vecParams.push_back( FP( "pos", "ocl::Integer", true ) ); 02131 vecParams.push_back( FP( "pos", "ocl::Integer", true ) ); 02132 vecType.push_back( "ocl::Sequence" ); 02133 vecType.push_back( TYPE_ARGUMENT_SELF_BASE ); 02134 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSequence_SubSequence(), false ) ); 02135 return; 02136 } 02137 02138 if ( ( strName == "first" ) && iCount == 0 ) { 02139 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 02140 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSequence_First(), false ) ); 02141 return; 02142 } 02143 02144 if ( ( strName == "last" ) && iCount == 0 ) { 02145 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 02146 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSequence_Last(), false ) ); 02147 return; 02148 } 02149 02150 if ( ( strName == "at" ) && iCount == 1 ) { 02151 vecParams.push_back( FP( "pos", "ocl::Integer", true ) ); 02152 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 02153 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSequence_At(), false ) ); 02154 return; 02155 } 02156 02157 if ( ( strName == "indexOf" ) && iCount == 1 ) { 02158 vecParams.push_back( FP( "any", "ocl::Any", true ) ); 02159 vecType.push_back( "ocl::Integer" ); 02160 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSequence_IndexOf(), false ) ); 02161 return; 02162 } 02163 02164 if ( ( strName == "insertAt" ) && iCount == 2 ) { 02165 vecParams.push_back( FP( "pos", "ocl::Integer", true ) ); 02166 vecParams.push_back( FP( "any", "ocl::Any", true ) ); 02167 vecType.push_back( "ocl::Sequence" ); 02168 vecType.push_back( TYPE_ARGUMENT_SELF_BASE ); 02169 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSequence_InsertAt(), false ) ); 02170 return; 02171 } 02172 02173 if ( ( strName == "including" ) && iCount == 1 ) { 02174 vecParams.push_back( FP( "any", "ocl::Any", true ) ); 02175 vecType.push_back( "ocl::Sequence" ); 02176 vecType.push_back( TYPE_ARGUMENT_SELF_BASE ); 02177 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSequence_Including(), false ) ); 02178 return; 02179 } 02180 02181 if ( ( strName == "excluding" ) && iCount == 1 ) { 02182 vecParams.push_back( FP( "any", "ocl::Any", true ) ); 02183 vecType.push_back( "ocl::Sequence" ); 02184 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 02185 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TSequence_Excluding(), false ) ); 02186 return; 02187 } 02188 } 02189 02190 void TSequence_IteratorFactory::GetFeatures( const OclSignature::Iterator& signature, OclMeta::IteratorVector& vecFeatures ) 02191 { 02192 std::string strName = signature.GetName(); 02193 TS vecType; 02194 02195 if ( strName == "select" ) { 02196 vecType.push_back( "ocl::Sequence" ); 02197 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 02198 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Boolean", vecType, new TSequence_Select(), false ) ); 02199 return; 02200 } 02201 02202 if ( strName == "reject" ) { 02203 vecType.push_back( "ocl::Sequence" ); 02204 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 02205 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Boolean", vecType, new TSequence_Reject(), false ) ); 02206 return; 02207 } 02208 02209 if ( strName == "collect" ) { 02210 vecType.push_back( "ocl::Sequence" ); 02211 vecType.push_back( TYPE_EXPRESSION_RETURN ); 02212 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Any", vecType, new TSequence_Collect(), false ) ); 02213 return; 02214 } 02215 } 02216 02217 //############################################################################################################################################## 02218 // 02219 // T Y P E O F ocl::Bag 02220 // 02221 //############################################################################################################################################## 02222 02223 OPERATOR( TBag_Plus ) // unio 02224 { 02225 void operator()() 02226 { 02227 DECL_COLLECTION( collThis, GetArgument( 0 ) ); 02228 DECL_ITERATOR( spIterator, GetArgument( 1 ) ); 02229 while ( spIterator->HasNext() ) 02230 collThis.push_back( spIterator->GetNext() ); 02231 SetResult( CREATE_BAG( GetTypeManager(), collThis ) ); 02232 } 02233 }; 02234 02235 OPERATOR( TBag_Times ) // intersection Bag 02236 { 02237 void operator()() 02238 { 02239 DECL_COLLECTION( collThis, GetArgument( 0 ) ); 02240 DECL_ITERATOR( spIterator, GetArgument( 1 ) ); 02241 OclMeta::ObjectVector collOut; 02242 while ( spIterator->HasNext() ) { 02243 OclMeta::Object object = spIterator->GetNext(); 02244 OclMeta::ObjectVector::iterator i = std::find( collThis.begin(), collThis.end(), object ); 02245 if ( i != collThis.end() ) { 02246 collOut.push_back( object ); 02247 collThis.erase( i ); 02248 } 02249 } 02250 SetResult( CREATE_BAG( GetTypeManager(), collOut ) ); 02251 } 02252 }; 02253 02254 OPERATOR( TBag_TimesSet ) // intersection Set 02255 { 02256 void operator()() 02257 { 02258 DECL_COLLECTION( collThis, GetArgument( 0 ) ); 02259 DECL_ITERATOR( spIterator, GetArgument( 1 ) ); 02260 OclMeta::ObjectVector collOut; 02261 while ( spIterator->HasNext() ) { 02262 OclMeta::Object object = spIterator->GetNext(); 02263 OclMeta::ObjectVector::iterator i = std::find( collThis.begin(), collThis.end(), object ); 02264 if ( i != collThis.end() ) { 02265 collOut.push_back( object ); 02266 collThis.erase( i ); 02267 } 02268 } 02269 SetResult( CREATE_SET( GetTypeManager(), collOut ) ); 02270 } 02271 }; 02272 02273 02274 METHOD( TBag_Union ) 02275 { 02276 void operator()() 02277 { 02278 DECL_COLLECTION( collThis, GetThis() ); 02279 DECL_ITERATOR( spIterator, GetArgument( 0 ) ); 02280 while ( spIterator->HasNext() ) 02281 collThis.push_back( spIterator->GetNext() ); 02282 SetResult( CREATE_BAG( GetTypeManager(), collThis ) ); 02283 } 02284 }; 02285 02286 METHOD( TBag_Intersection ) 02287 { 02288 void operator()() 02289 { 02290 DECL_COLLECTION( collThis, GetThis() ); 02291 DECL_ITERATOR( spIterator, GetArgument( 0 ) ); 02292 OclMeta::ObjectVector collOut; 02293 while ( spIterator->HasNext() ) { 02294 OclMeta::Object object = spIterator->GetNext(); 02295 OclMeta::ObjectVector::iterator i = std::find( collThis.begin(), collThis.end(), object ); 02296 if ( i != collThis.end() ) { 02297 collOut.push_back( object ); 02298 collThis.erase( i ); 02299 } 02300 } 02301 SetResult( CREATE_BAG( GetTypeManager(), collOut ) ); 02302 } 02303 }; 02304 02305 METHOD( TBag_IntersectionSet ) 02306 { 02307 void operator()() 02308 { 02309 DECL_COLLECTION( collThis, GetThis() ); 02310 DECL_ITERATOR( spIterator, GetArgument( 0 ) ); 02311 OclMeta::ObjectVector collOut; 02312 while ( spIterator->HasNext() ) { 02313 OclMeta::Object object = spIterator->GetNext(); 02314 OclMeta::ObjectVector::iterator i = std::find( collThis.begin(), collThis.end(), object ); 02315 if ( i != collThis.end() ) { 02316 collOut.push_back( object ); 02317 collThis.erase( i ); 02318 } 02319 } 02320 SetResult( CREATE_SET( GetTypeManager(), collOut ) ); 02321 } 02322 }; 02323 02324 METHOD( TBag_Including ) 02325 { 02326 void operator()() 02327 { 02328 DECL_COLLECTION( collThis, GetThis() ); 02329 collThis.push_back( GetArgument( 0 ) ); 02330 SetResult( CREATE_BAG( GetTypeManager(), collThis ) ); 02331 } 02332 }; 02333 02334 METHOD( TBag_Excluding ) 02335 { 02336 void operator()() 02337 { 02338 DECL_COLLECTION( collThis, GetThis() ); 02339 bool bFound = false; 02340 do { 02341 bFound = false; 02342 OclMeta::ObjectVector::iterator i = std::find( collThis.begin(), collThis.end(), GetArgument( 0 ) ); 02343 if ( i != collThis.end() ) { 02344 collThis.erase( i ); 02345 bFound = true; 02346 } 02347 } while ( bFound ); 02348 SetResult( CREATE_BAG( GetTypeManager(), collThis ) ); 02349 } 02350 }; 02351 02352 ITERATOR( TBag_Select ) 02353 { 02354 private : 02355 OclMeta::ObjectVector m_vecSelecteds; 02356 02357 void Initialize() 02358 { 02359 OclIterator::Initialize(); 02360 m_vecSelecteds.clear(); 02361 } 02362 02363 void operator()() 02364 { 02365 if ( ! GetSubResult().IsUndefined() ) { 02366 DECL_BOOLEAN( bArg, GetSubResult() ); 02367 if ( bArg ) 02368 m_vecSelecteds.push_back( GetArgument( 0 ) ); 02369 } 02370 } 02371 02372 OclMeta::Object GetResult() const 02373 { 02374 return CREATE_BAG( GetTypeManager(), m_vecSelecteds ); 02375 } 02376 02377 void Finalize() 02378 { 02379 m_vecSelecteds.clear(); 02380 OclIterator::Finalize(); 02381 } 02382 }; 02383 02384 ITERATOR( TBag_Reject ) 02385 { 02386 private : 02387 OclMeta::ObjectVector m_vecSelecteds; 02388 02389 void Initialize() 02390 { 02391 OclIterator::Initialize(); 02392 m_vecSelecteds.clear(); 02393 } 02394 02395 void operator()() 02396 { 02397 if ( ! GetSubResult().IsUndefined() ) { 02398 DECL_BOOLEAN( bArg, GetSubResult() ); 02399 if ( ! bArg ) 02400 m_vecSelecteds.push_back( GetArgument( 0 ) ); 02401 } 02402 } 02403 02404 OclMeta::Object GetResult() const 02405 { 02406 return CREATE_BAG( GetTypeManager(), m_vecSelecteds ); 02407 } 02408 02409 void Finalize() 02410 { 02411 m_vecSelecteds.clear(); 02412 OclIterator::Finalize(); 02413 } 02414 }; 02415 02416 ITERATOR( TBag_Collect ) 02417 { 02418 private : 02419 OclMeta::ObjectVector m_vecSelecteds; 02420 02421 void Initialize() 02422 { 02423 OclIterator::Initialize(); 02424 m_vecSelecteds.clear(); 02425 } 02426 02427 void operator()() 02428 { 02429 m_vecSelecteds.push_back( GetSubResult() ); 02430 } 02431 02432 OclMeta::Object GetResult() const 02433 { 02434 return CREATE_BAG( GetTypeManager(), m_vecSelecteds ); 02435 } 02436 02437 void Finalize() 02438 { 02439 m_vecSelecteds.clear(); 02440 OclIterator::Finalize(); 02441 } 02442 }; 02443 02444 void TBag_MethodFactory::GetFeatures( const OclSignature::Method& signature, OclMeta::MethodVector& vecFeatures ) 02445 { 02446 std::string strName = signature.GetName(); 02447 int iCount = signature.GetParameterCount(); 02448 FPV vecParams; 02449 TS vecType; 02450 02451 if ( ( strName == "union" ) && iCount == 1 ) { 02452 vecParams.push_back( FP( "bag", "ocl::Bag", true ) ); 02453 vecType.push_back( "ocl::Bag" ); 02454 vecType.push_back( TYPE_COMPOUNDARGUMENT_SELF_BASE ); 02455 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TBag_Union(), false ) ); 02456 02457 vecParams.clear(); 02458 vecType.clear(); 02459 vecParams.push_back( FP( "set", "ocl::Set", true ) ); 02460 vecType.push_back( "ocl::Bag" ); 02461 vecType.push_back( TYPE_COMPOUNDARGUMENT_SELF_BASE ); 02462 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TBag_Union(), false ) ); 02463 return; 02464 } 02465 02466 if ( ( strName == "intersection" ) && iCount == 1 ) { 02467 vecParams.push_back( FP( "bag", "ocl::Bag", true ) ); 02468 vecType.push_back( "ocl::Bag" ); 02469 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 02470 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TBag_Intersection(), false ) ); 02471 02472 vecParams.clear(); 02473 vecType.clear(); 02474 vecParams.push_back( FP( "set", "ocl::Set", true ) ); 02475 vecType.push_back( "ocl::Set" ); 02476 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 02477 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TBag_IntersectionSet(), false ) ); 02478 return; 02479 } 02480 02481 if ( ( strName == "including" ) && iCount == 1 ) { 02482 vecParams.push_back( FP( "any", "ocl::Any", true ) ); 02483 vecType.push_back( "ocl::Bag" ); 02484 vecType.push_back( TYPE_ARGUMENT_SELF_BASE ); 02485 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TBag_Including(), false ) ); 02486 return; 02487 } 02488 02489 if ( ( strName == "excluding" ) && iCount == 1 ) { 02490 vecParams.push_back( FP( "any", "ocl::Any", true ) ); 02491 vecType.push_back( "ocl::Bag" ); 02492 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 02493 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TBag_Excluding(), false ) ); 02494 return; 02495 } 02496 } 02497 02498 void TBag_IteratorFactory::GetFeatures( const OclSignature::Iterator& signature, OclMeta::IteratorVector& vecFeatures ) 02499 { 02500 std::string strName = signature.GetName(); 02501 TS vecType; 02502 02503 if ( strName == "select" ) { 02504 vecType.push_back( "ocl::Bag" ); 02505 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 02506 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Boolean", vecType, new TBag_Select(), false ) ); 02507 return; 02508 } 02509 02510 if ( strName == "reject" ) { 02511 vecType.push_back( "ocl::Bag" ); 02512 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 02513 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Boolean", vecType, new TBag_Reject(), false ) ); 02514 return; 02515 } 02516 02517 if ( strName == "collect" ) { 02518 vecType.push_back( "ocl::Bag" ); 02519 vecType.push_back( TYPE_EXPRESSION_RETURN ); 02520 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Any", vecType, new TBag_Collect(), false ) ); 02521 return; 02522 } 02523 } 02524 02525 02526 // -- OrderedSet inserted here 02527 //############################################################################################################################################## 02528 // 02529 // T Y P E O F ocl::OrderedSet 02530 // 02531 //############################################################################################################################################## 02532 02533 METHOD( TOrderedSet_Prepend ) 02534 { 02535 void operator()() 02536 { 02537 DECL_COLLECTION( collThis, GetThis() ); 02538 collThis.insert( collThis.begin(), GetArgument( 0 ) ); 02539 SetResult( CREATE_ORDEREDSET( GetTypeManager(), collThis ) ); 02540 } 02541 }; 02542 02543 METHOD( TOrderedSet_Append ) 02544 { 02545 void operator()() 02546 { 02547 DECL_COLLECTION( collThis, GetThis() ); 02548 collThis.push_back( GetArgument( 0 ) ); 02549 SetResult( CREATE_ORDEREDSET( GetTypeManager(), collThis ) ); 02550 } 02551 }; 02552 02553 METHOD( TOrderedSet_SubOrderedSet) 02554 { 02555 void operator()() 02556 { 02557 DECL_COLLECTION( collThis, GetThis() ); 02558 DECL_INTEGER( lFrom, GetArgument( 0 ) ); 02559 if ( lFrom < 0 ) { 02560 ThrowException( "Argument 'from' is less than 0." ); 02561 return; 02562 } 02563 if ( lFrom >= (int) collThis.size() ) { 02564 ThrowException( "Argument 'from' equals to or is greater than size of OrderedSet." ); 02565 return; 02566 } 02567 if ( GetArgumentCount() == 1 ) { 02568 OclMeta::ObjectVector collOut; 02569 for ( unsigned long i = lFrom ; i < collThis.size() ; i++ ) 02570 collOut.push_back( collThis[ i ] ); 02571 SetResult( CREATE_ORDEREDSET( GetTypeManager(), collOut ) ); 02572 return; 02573 } 02574 DECL_INTEGER( lTo, GetArgument( 1 ) ); 02575 if ( lTo < lFrom ) { 02576 ThrowException( "Argument 'to' greater than Argument 'from'." ); 02577 return; 02578 } 02579 if ( lTo >= (int) collThis.size() ) { 02580 ThrowException( "Argument 'to' equals to or is greater than size of OrderedSet." ); 02581 return; 02582 } 02583 OclMeta::ObjectVector collOut; 02584 for ( long i = lFrom ; i <= lTo ; i++ ) 02585 collOut.push_back( collThis[ i ] ); 02586 SetResult( CREATE_ORDEREDSET( GetTypeManager(), collOut ) ); 02587 } 02588 }; 02589 02590 METHOD( TOrderedSet_At ) 02591 { 02592 void operator()() 02593 { 02594 DECL_COLLECTION( collThis, GetThis() ); 02595 DECL_INTEGER( lAt, GetArgument( 0 ) ); 02596 if ( lAt < 0 ) { 02597 ThrowException( "Argument 'from' is less than 0." ); 02598 return; 02599 } 02600 if ( lAt >= (int) collThis.size() ) { 02601 ThrowException( "Argument 'from' equals to or is greater than size of OrederedSet." ); 02602 return; 02603 } 02604 SetResult( collThis[ lAt ] ); 02605 } 02606 }; 02607 02608 METHOD( TOrderedSet_InsertAt ) 02609 { 02610 void operator()() 02611 { 02612 DECL_COLLECTION( collThis, GetThis() ); 02613 DECL_INTEGER( lAt, GetArgument( 0 ) ); 02614 if ( lAt < 0 ) 02615 lAt = 0; 02616 if ( lAt >= (int) collThis.size() ) { 02617 collThis.push_back( GetArgument( 1 ) ); 02618 SetResult( CREATE_ORDEREDSET( GetTypeManager(), collThis ) ); 02619 return; 02620 } 02621 OclMeta::ObjectVector vecOut; 02622 for ( int i = 0 ; i < (int) collThis.size() ; i++ ) { 02623 if ( i == lAt ) 02624 vecOut.push_back( GetArgument( 1 ) ); 02625 vecOut.push_back( collThis[ i ] ); 02626 } 02627 SetResult( CREATE_ORDEREDSET( GetTypeManager(), vecOut ) ); 02628 } 02629 }; 02630 02631 METHOD( TOrderedSet_IndexOf ) 02632 { 02633 void operator()() 02634 { 02635 DECL_COLLECTION( collThis, GetThis() ); 02636 for ( int i = 0 ; i < (int) collThis.size() ; i ++ ) 02637 if ( collThis[ i ] == GetArgument( 0 ) ) { 02638 SetResult( CREATE_INTEGER( GetTypeManager(), i ) ); 02639 return; 02640 } 02641 SetResult( CREATE_INTEGER( GetTypeManager(), -1 ) ); 02642 } 02643 }; 02644 02645 METHOD( TOrderedSet_First ) 02646 { 02647 void operator()() 02648 { 02649 DECL_COLLECTION( collThis, GetThis() ); 02650 if ( collThis.empty() ) { 02651 ThrowException( "Sequence is empty." ); 02652 return; 02653 } 02654 SetResult( collThis[ 0 ] ); 02655 } 02656 }; 02657 02658 METHOD( TOrderedSet_Last ) 02659 { 02660 void operator()() 02661 { 02662 DECL_COLLECTION( collThis, GetThis() ); 02663 if ( collThis.empty() ) { 02664 ThrowException( "Sequence is empty." ); 02665 return; 02666 } 02667 SetResult( collThis[ collThis.size() - 1 ] ); 02668 } 02669 }; 02670 02671 02672 ITERATOR( TOrderedSet_Select ) 02673 { 02674 private : 02675 OclMeta::ObjectVector m_vecSelecteds; 02676 02677 void Initialize() 02678 { 02679 OclIterator::Initialize(); 02680 m_vecSelecteds.clear(); 02681 } 02682 02683 void operator()() 02684 { 02685 if ( ! GetSubResult().IsUndefined() ) { 02686 DECL_BOOLEAN( bArg, GetSubResult() ); 02687 if ( bArg ) 02688 m_vecSelecteds.push_back( GetArgument( 0 ) ); 02689 } 02690 } 02691 02692 OclMeta::Object GetResult() const 02693 { 02694 return CREATE_ORDEREDSET( GetTypeManager(), m_vecSelecteds ); 02695 } 02696 02697 void Finalize() 02698 { 02699 m_vecSelecteds.clear(); 02700 OclIterator::Finalize(); 02701 } 02702 }; 02703 02704 ITERATOR( TOrderedSet_Reject ) 02705 { 02706 private : 02707 OclMeta::ObjectVector m_vecSelecteds; 02708 02709 void Initialize() 02710 { 02711 OclIterator::Initialize(); 02712 m_vecSelecteds.clear(); 02713 } 02714 02715 void operator()() 02716 { 02717 if ( ! GetSubResult().IsUndefined() ) { 02718 DECL_BOOLEAN( bArg, GetSubResult() ); 02719 if ( ! bArg ) 02720 m_vecSelecteds.push_back( GetArgument( 0 ) ); 02721 } 02722 } 02723 02724 OclMeta::Object GetResult() const 02725 { 02726 return CREATE_ORDEREDSET( GetTypeManager(), m_vecSelecteds ); 02727 } 02728 02729 void Finalize() 02730 { 02731 m_vecSelecteds.clear(); 02732 OclIterator::Finalize(); 02733 } 02734 }; 02735 02736 ITERATOR( TOrderedSet_Collect ) 02737 { 02738 private : 02739 OclMeta::ObjectVector m_vecSelecteds; 02740 02741 void Initialize() 02742 { 02743 OclIterator::Initialize(); 02744 m_vecSelecteds.clear(); 02745 } 02746 02747 void operator()() 02748 { 02749 m_vecSelecteds.push_back( GetSubResult() ); 02750 } 02751 02752 OclMeta::Object GetResult() const 02753 { 02754 return CREATE_BAG( GetTypeManager(), m_vecSelecteds ); 02755 } 02756 02757 void Finalize() 02758 { 02759 m_vecSelecteds.clear(); 02760 OclIterator::Finalize(); 02761 } 02762 }; 02763 02764 void TOrderedSet_MethodFactory::GetFeatures( const OclSignature::Method& signature, OclMeta::MethodVector& vecFeatures ) 02765 { 02766 std::string strName = signature.GetName(); 02767 int iCount = signature.GetParameterCount(); 02768 FPV vecParams; 02769 TS vecType; 02770 02771 if ( ( strName == "prepend" ) && iCount == 1 ) { 02772 vecParams.push_back( FP( "any", "ocl::Any", true ) ); 02773 vecType.push_back( "ocl::OrderedSet" ); 02774 vecType.push_back( TYPE_ARGUMENT_SELF_BASE ); 02775 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TOrderedSet_Prepend(), false ) ); 02776 return; 02777 } 02778 02779 if ( ( strName == "append" ) && iCount == 1 ) { 02780 vecParams.push_back( FP( "any", "ocl::Any", true ) ); 02781 vecType.push_back( "ocl::OrderedSet" ); 02782 vecType.push_back( TYPE_ARGUMENT_SELF_BASE ); 02783 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TOrderedSet_Append(), false ) ); 02784 return; 02785 } 02786 02787 if ( ( strName == "subOrderedSet" ) && iCount == 2 ) { 02788 vecParams.push_back( FP( "pos", "ocl::Integer", true ) ); 02789 vecParams.push_back( FP( "pos", "ocl::Integer", true ) ); 02790 vecType.push_back( "ocl::OrderedSet" ); 02791 vecType.push_back( TYPE_ARGUMENT_SELF_BASE ); 02792 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TOrderedSet_SubOrderedSet(), false ) ); 02793 return; 02794 } 02795 02796 if ( ( strName == "first" ) && iCount == 0 ) { 02797 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 02798 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TOrderedSet_First(), false ) ); 02799 return; 02800 } 02801 02802 if ( ( strName == "last" ) && iCount == 0 ) { 02803 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 02804 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TOrderedSet_Last(), false ) ); 02805 return; 02806 } 02807 02808 if ( ( strName == "at" ) && iCount == 1 ) { 02809 vecParams.push_back( FP( "pos", "ocl::Integer", true ) ); 02810 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 02811 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TOrderedSet_At(), false ) ); 02812 return; 02813 } 02814 02815 if ( ( strName == "indexOf" ) && iCount == 1 ) { 02816 vecParams.push_back( FP( "any", "ocl::Any", true ) ); 02817 vecType.push_back( "ocl::Integer" ); 02818 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TOrderedSet_IndexOf(), false ) ); 02819 return; 02820 } 02821 02822 if ( ( strName == "insertAt" ) && iCount == 2 ) { 02823 vecParams.push_back( FP( "pos", "ocl::Integer", true ) ); 02824 vecParams.push_back( FP( "any", "ocl::Any", true ) ); 02825 vecType.push_back( "ocl::OrderedSet" ); 02826 vecType.push_back( TYPE_ARGUMENT_SELF_BASE ); 02827 vecFeatures.push_back( new OclMeta::Method( strName, vecParams, vecType, new TOrderedSet_InsertAt(), false ) ); 02828 return; 02829 } 02830 02831 } 02832 02833 void TOrderedSet_IteratorFactory::GetFeatures( const OclSignature::Iterator& signature, OclMeta::IteratorVector& vecFeatures ) 02834 { 02835 std::string strName = signature.GetName(); 02836 TS vecType; 02837 02838 if ( strName == "select" ) { 02839 vecType.push_back( "ocl::OrderedSet" ); 02840 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 02841 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Boolean", vecType, new TOrderedSet_Select(), false ) ); 02842 return; 02843 } 02844 02845 if ( strName == "reject" ) { 02846 vecType.push_back( "ocl::OrderedSet" ); 02847 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 02848 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Boolean", vecType, new TOrderedSet_Reject(), false ) ); 02849 return; 02850 } 02851 02852 if ( strName == "collect" ) { 02853 vecType.push_back( "ocl::OrderedSet" ); 02854 vecType.push_back( TYPE_EXPRESSION_RETURN ); 02855 vecFeatures.push_back( new OclMeta::Iterator( strName, "ocl::Any", vecType, new TOrderedSet_Collect(), false ) ); 02856 return; 02857 } 02858 } 02859 02860 02861 02862 //############################################################################################################################################## 02863 // 02864 // G L O B A L F A C T O R I E S 02865 // 02866 //############################################################################################################################################## 02867 02868 void OperatorFactory::GetFeatures( const OclSignature::Operator& signature, OclMeta::OperatorVector& vecFeatures ) 02869 { 02870 std::string strName = signature.GetName(); 02871 int iCount = signature.GetParameterCount(); 02872 02873 // ocl::Any 02874 02875 if ( ( strName == "=" ) && iCount == 2 ) { 02876 TS vecType; 02877 vecType.push_back( "ocl::Boolean" ); 02878 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Any", "ocl::Any", vecType, new TAny_Equals(), false ) ); 02879 } 02880 02881 if ( ( strName == "<>" ) && iCount == 2 ) { 02882 TS vecType; 02883 vecType.push_back( "ocl::Boolean" ); 02884 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Any", "ocl::Any", vecType, new TAny_NotEquals(), false ) ); 02885 } 02886 02887 if ( ( strName == "==" ) && iCount == 2 ) { 02888 TS vecType; 02889 vecType.push_back( "ocl::Boolean" ); 02890 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Any", "ocl::Any", vecType, new TAny_IdentityEquals(), false ) ); 02891 } 02892 02893 if ( ( strName == "!=" ) && iCount == 2 ) { 02894 TS vecType; 02895 vecType.push_back( "ocl::Boolean" ); 02896 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Any", "ocl::Any", vecType, new TAny_IdentityNotEquals(), false ) ); 02897 } 02898 02899 // ocl::Boolean 02900 02901 if ( ( strName == "not" ) && iCount == 1 ) { 02902 TS vecType; 02903 vecType.push_back( "ocl::Boolean" ); 02904 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Boolean", vecType, new TBoolean_Not(), false ) ); 02905 } 02906 if ( ( strName == "and" || strName == "&&" ) && iCount == 2 ) { 02907 TS vecType; 02908 vecType.push_back( "ocl::Boolean" ); 02909 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Boolean", "ocl::Boolean", vecType, new TBoolean_And(), false ) ); 02910 } 02911 02912 if ( ( strName == "or" || strName == "||" ) && iCount == 2 ) { 02913 TS vecType; 02914 vecType.push_back( "ocl::Boolean" ); 02915 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Boolean", "ocl::Boolean", vecType, new TBoolean_Or(), false ) ); 02916 } 02917 02918 if ( ( strName == "xor" ) && iCount == 2 ) { 02919 TS vecType; 02920 vecType.push_back( "ocl::Boolean" ); 02921 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Boolean", "ocl::Boolean", vecType, new TBoolean_Xor(), false ) ); 02922 } 02923 02924 if ( ( strName == "implies" || strName == "=>" ) && iCount == 2 ) { 02925 TS vecType; 02926 vecType.push_back( "ocl::Boolean" ); 02927 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Boolean", "ocl::Boolean", vecType, new TBoolean_Implies(), false ) ); 02928 } 02929 02930 // ocl::String 02931 02932 if ( ( strName == "<" ) && iCount == 2 ) { 02933 TS vecType; 02934 vecType.push_back( "ocl::Boolean" ); 02935 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::String", "ocl::String", vecType, new TString_Less(), false ) ); 02936 } 02937 02938 if ( ( strName == "<=" ) && iCount == 2 ) { 02939 TS vecType; 02940 vecType.push_back( "ocl::Boolean" ); 02941 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::String", "ocl::String", vecType, new TString_LessEquals(), false ) ); 02942 } 02943 02944 if ( ( strName == ">" ) && iCount == 2 ) { 02945 TS vecType; 02946 vecType.push_back( "ocl::Boolean" ); 02947 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::String", "ocl::String", vecType, new TString_Greater(), false ) ); 02948 } 02949 02950 if ( ( strName == ">=" ) && iCount == 2 ) { 02951 TS vecType; 02952 vecType.push_back( "ocl::Boolean" ); 02953 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::String", "ocl::String", vecType, new TString_GreaterEquals(), false ) ); 02954 } 02955 02956 if ( ( strName == "+" ) && iCount == 2 ) { 02957 TS vecType; 02958 vecType.push_back( "ocl::String" ); 02959 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::String", "ocl::String", vecType, new TString_Plus(), false ) ); 02960 } 02961 02962 // ocl::Enumeration 02963 02964 // ocl::Real 02965 02966 if ( ( strName == "-" ) && iCount == 1 ) { 02967 TS vecType; 02968 vecType.push_back( "ocl::Real" ); 02969 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Real", vecType, new TReal_Minus1(), false ) ); 02970 } 02971 02972 if ( ( strName == "-" ) && iCount == 2 ) { 02973 TS vecType; 02974 vecType.push_back( "ocl::Real" ); 02975 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Real", "ocl::Real", vecType, new TReal_Minus2(), false ) ); 02976 } 02977 02978 if ( ( strName == "+" ) && iCount == 2 ) { 02979 TS vecType; 02980 vecType.push_back( "ocl::Real" ); 02981 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Real", "ocl::Real", vecType, new TReal_Plus(), false ) ); 02982 } 02983 02984 if ( ( strName == "*" ) && iCount == 2 ) { 02985 TS vecType; 02986 vecType.push_back( "ocl::Real" ); 02987 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Real", "ocl::Real", vecType, new TReal_Times(), false ) ); 02988 } 02989 02990 if ( ( strName == "/" ) && iCount == 2 ) { 02991 TS vecType; 02992 vecType.push_back( "ocl::Real" ); 02993 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Real", "ocl::Real", vecType, new TReal_Slash(), false ) ); 02994 } 02995 02996 if ( ( strName == "<" ) && iCount == 2 ) { 02997 TS vecType; 02998 vecType.push_back( "ocl::Boolean" ); 02999 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Real", "ocl::Real", vecType, new TReal_Less(), false ) ); 03000 } 03001 03002 if ( ( strName == "<=" ) && iCount == 2 ) { 03003 TS vecType; 03004 vecType.push_back( "ocl::Boolean" ); 03005 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Real", "ocl::Real", vecType, new TReal_LessEquals(), false ) ); 03006 } 03007 03008 if ( ( strName == ">" ) && iCount == 2 ) { 03009 TS vecType; 03010 vecType.push_back( "ocl::Boolean" ); 03011 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Real", "ocl::Real", vecType, new TReal_Greater(), false ) ); 03012 } 03013 03014 if ( ( strName == ">=" ) && iCount == 2 ) { 03015 TS vecType; 03016 vecType.push_back( "ocl::Boolean" ); 03017 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Real", "ocl::Real", vecType, new TReal_GreaterEquals(), false ) ); 03018 } 03019 03020 // ocl::Integer 03021 03022 if ( ( strName == "-" ) && iCount == 1 ) { 03023 TS vecType; 03024 vecType.push_back( "ocl::Integer" ); 03025 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Integer", vecType, new TInteger_Minus1(), false ) ); 03026 } 03027 03028 if ( ( strName == "-" ) && iCount == 2 ) { 03029 TS vecType; 03030 vecType.push_back( "ocl::Integer" ); 03031 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Integer", "ocl::Integer", vecType, new TInteger_Minus2(), false ) ); 03032 } 03033 03034 if ( ( strName == "+" ) && iCount == 2 ) { 03035 TS vecType; 03036 vecType.push_back( "ocl::Integer" ); 03037 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Integer", "ocl::Integer", vecType, new TInteger_Plus(), false ) ); 03038 } 03039 03040 if ( ( strName == "*" ) && iCount == 2 ) { 03041 TS vecType; 03042 vecType.push_back( "ocl::Integer" ); 03043 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Integer", "ocl::Integer", vecType, new TInteger_Times(), false ) ); 03044 } 03045 03046 if ( ( strName == "div" ) && iCount == 2 ) { 03047 TS vecType; 03048 vecType.push_back( "ocl::Integer" ); 03049 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Integer", "ocl::Integer", vecType, new TInteger_Div(), false ) ); 03050 } 03051 03052 if ( ( strName == "mod" ) && iCount == 2 ) { 03053 TS vecType; 03054 vecType.push_back( "ocl::Integer" ); 03055 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Integer", "ocl::Integer", vecType, new TInteger_Mod(), false ) ); 03056 } 03057 03058 if ( ( strName == "<" ) && iCount == 2 ) { 03059 TS vecType; 03060 vecType.push_back( "ocl::Boolean" ); 03061 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Integer", "ocl::Integer", vecType, new TInteger_Less(), false ) ); 03062 } 03063 03064 if ( ( strName == "<=" ) && iCount == 2 ) { 03065 TS vecType; 03066 vecType.push_back( "ocl::Boolean" ); 03067 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Integer", "ocl::Integer", vecType, new TInteger_LessEquals(), false ) ); 03068 } 03069 03070 if ( ( strName == ">" ) && iCount == 2 ) { 03071 TS vecType; 03072 vecType.push_back( "ocl::Boolean" ); 03073 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Integer", "ocl::Integer", vecType, new TInteger_Greater(), false ) ); 03074 } 03075 03076 if ( ( strName == ">=" ) && iCount == 2 ) { 03077 TS vecType; 03078 vecType.push_back( "ocl::Boolean" ); 03079 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Integer", "ocl::Integer", vecType, new TInteger_GreaterEquals(), false ) ); 03080 } 03081 03082 // ocl::Type 03083 03084 // ocl::Set 03085 03086 if ( ( strName == "+" ) && iCount == 2 ) { 03087 TS vecType; 03088 vecType.push_back( "ocl::Set" ); 03089 vecType.push_back( TYPE_COMPOUNDARGUMENT_SELF_BASE ); 03090 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Set", "ocl::Set", vecType, new TSet_Plus(), false ) ); 03091 } 03092 03093 if ( ( strName == "+" ) && iCount == 2 ) { 03094 TS vecType; 03095 vecType.push_back( "ocl::Bag" ); 03096 vecType.push_back( TYPE_COMPOUNDARGUMENT_SELF_BASE ); 03097 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Set", "ocl::Bag", vecType, new TSet_PlusBag(), false ) ); 03098 } 03099 03100 if ( ( strName == "-" ) && iCount == 2 ) { 03101 TS vecType; 03102 vecType.push_back( "ocl::Set" ); 03103 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 03104 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Set", "ocl::Set", vecType, new TSet_Minus(), false ) ); 03105 } 03106 03107 if ( ( strName == "*" ) && iCount == 2 ) { 03108 TS vecType; 03109 vecType.push_back( "ocl::Set" ); 03110 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 03111 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Set", "ocl::Set", vecType, new TSet_Times(), false ) ); 03112 } 03113 03114 if ( ( strName == "*" ) && iCount == 2 ) { 03115 TS vecType; 03116 vecType.push_back( "ocl::Set" ); 03117 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 03118 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Set", "ocl::Bag", vecType, new TSet_Times(), false ) ); 03119 } 03120 03121 if ( ( strName == "%" ) && iCount == 2 ) { 03122 TS vecType; 03123 vecType.push_back( "ocl::Set" ); 03124 vecType.push_back( TYPE_COMPOUNDARGUMENT_SELF_BASE ); 03125 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Set", "ocl::Set", vecType, new TSet_Percent(), false ) ); 03126 } 03127 03128 // ocl::Sequence 03129 03130 if ( ( strName == "+" ) && iCount == 2 ) { 03131 TS vecType; 03132 vecType.push_back( "ocl::Sequence" ); 03133 vecType.push_back( TYPE_COMPOUNDARGUMENT_SELF_BASE ); 03134 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Sequence", "ocl::Sequence", vecType, new TSequence_Plus(), false ) ); 03135 } 03136 03137 // ocl::Bag 03138 03139 if ( ( strName == "+" ) && iCount == 2 ) { 03140 TS vecType; 03141 vecType.push_back( "ocl::Bag" ); 03142 vecType.push_back( TYPE_COMPOUNDARGUMENT_SELF_BASE ); 03143 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Bag", "ocl::Bag", vecType, new TBag_Plus(), false ) ); 03144 } 03145 03146 if ( ( strName == "+" ) && iCount == 2 ) { 03147 TS vecType; 03148 vecType.push_back( "ocl::Bag" ); 03149 vecType.push_back( TYPE_COMPOUNDARGUMENT_SELF_BASE ); 03150 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Bag", "ocl::Set", vecType, new TBag_Plus(), false ) ); 03151 } 03152 03153 if ( ( strName == "*" ) && iCount == 2 ) { 03154 TS vecType; 03155 vecType.push_back( "ocl::Bag" ); 03156 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 03157 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Bag", "ocl::Bag", vecType, new TBag_Times(), false ) ); 03158 } 03159 03160 if ( ( strName == "*" ) && iCount == 2 ) { 03161 TS vecType; 03162 vecType.push_back( "ocl::Set" ); 03163 vecType.push_back( TYPE_AGGREGATED_OBJECT ); 03164 vecFeatures.push_back( new OclMeta::Operator( strName, "ocl::Bag", "ocl::Set", vecType, new TBag_TimesSet(), false ) ); 03165 } 03166 } 03167 03168 void FunctionFactory::GetFeatures( const OclSignature::Function& signature, OclMeta::FunctionVector& vecFeatures ) 03169 { 03170 std::string strName = signature.GetName(); 03171 int iCount = signature.GetParameterCount(); 03172 03173 // ocl::Any 03174 03175 // ocl::Boolean 03176 03177 // ocl::String 03178 03179 // ocl::Enumeration 03180 03181 // ocl::Real 03182 03183 if ( ( strName == "abs" ) && iCount == 1 ) { 03184 FPV vecParams; TS vecType; 03185 vecParams.push_back( FP( "real", "ocl::Real", true ) ); 03186 vecType.push_back( "ocl::Real" ); 03187 vecFeatures.push_back( new OclMeta::Function( strName, vecParams, vecType, new TReal_Abs(), false ) ); 03188 } 03189 03190 if ( ( strName == "floor" ) && iCount == 1 ) { 03191 FPV vecParams; TS vecType; 03192 vecParams.push_back( FP( "real", "ocl::Real", true ) ); 03193 vecType.push_back( "ocl::Integer" ); 03194 vecFeatures.push_back( new OclMeta::Function( strName, vecParams, vecType, new TReal_Floor(), false ) ); 03195 } 03196 03197 if ( ( strName == "round" ) && iCount == 1 ) { 03198 FPV vecParams; TS vecType; 03199 vecParams.push_back( FP( "real", "ocl::Real", true ) ); 03200 vecType.push_back( "ocl::Integer" ); 03201 vecFeatures.push_back( new OclMeta::Function( strName, vecParams, vecType, new TReal_Round(), false ) ); 03202 } 03203 03204 if ( ( strName == "min" ) && iCount == 2 ) { 03205 FPV vecParams; TS vecType; 03206 vecParams.push_back( FP( "real1", "ocl::Real", true ) ); 03207 vecParams.push_back( FP( "real2", "ocl::Real", true ) ); 03208 vecType.push_back( "ocl::Real" ); 03209 vecFeatures.push_back( new OclMeta::Function( strName, vecParams, vecType, new TReal_Min(), false ) ); 03210 } 03211 03212 if ( ( strName == "max" ) && iCount == 2 ) { 03213 FPV vecParams; TS vecType; 03214 vecParams.push_back( FP( "real1", "ocl::Real", true ) ); 03215 vecParams.push_back( FP( "real2", "ocl::Real", true ) ); 03216 vecType.push_back( "ocl::Real" ); 03217 vecFeatures.push_back( new OclMeta::Function( strName, vecParams, vecType, new TReal_Max(), false ) ); 03218 } 03219 03220 // ocl::Integer 03221 03222 if ( ( strName == "abs" ) && iCount == 1 ) { 03223 FPV vecParams; TS vecType; 03224 vecParams.push_back( FP( "integer", "ocl::Integer", true ) ); 03225 vecType.push_back( "ocl::Integer" ); 03226 vecFeatures.push_back( new OclMeta::Function( strName, vecParams, vecType, new TInteger_Abs(), false ) ); 03227 } 03228 03229 if ( ( strName == "min" ) && iCount == 2 ) { 03230 FPV vecParams; TS vecType; 03231 vecParams.push_back( FP( "integer1", "ocl::Integer", true ) ); 03232 vecParams.push_back( FP( "integer2", "ocl::Integer", true ) ); 03233 vecType.push_back( "ocl::Integer" ); 03234 vecFeatures.push_back( new OclMeta::Function( strName, vecParams, vecType, new TInteger_Min(), false ) ); 03235 } 03236 03237 if ( ( strName == "max" ) && iCount == 2 ) { 03238 FPV vecParams; TS vecType; 03239 vecParams.push_back( FP( "integer1", "ocl::Integer", true ) ); 03240 vecParams.push_back( FP( "integer2", "ocl::Integer", true ) ); 03241 vecType.push_back( "ocl::Integer" ); 03242 vecFeatures.push_back( new OclMeta::Function( strName, vecParams, vecType, new TInteger_Max(), false ) ); 03243 } 03244 03245 // ocl::Type 03246 03247 } 03248 03249 void TypeFactory::GetTypes( const std::string& strName, const std::string& , std::vector<std::unique_ptr<OclMeta::Type>>& vecTypes, std::string& strNameResult ) 03250 { 03251 strNameResult = strName; 03252 if ( strName == "ocl::Any" || strName == "Any" ) { 03253 StringVector vecSupers; 03254 vecTypes.push_back(std::unique_ptr<OclMeta::Type>( new OclMeta::Type( "ocl::Any", vecSupers, new OclImplementation::AttributeFactory(), new OclImplementation::AssociationFactory(), new TAny_MethodFactory(), false ) )); 03255 return; 03256 } 03257 03258 if ( strName == "ocl::Boolean" || strName == "bool" ) { 03259 StringVector vecSupers; 03260 vecSupers.push_back( "ocl::Any" ); 03261 vecTypes.push_back(std::unique_ptr<OclMeta::Type>( new OclMeta::Type( "ocl::Boolean", vecSupers, new OclImplementation::AttributeFactory(), new OclImplementation::AssociationFactory(), new OclImplementation::MethodFactory(), false ) )); 03262 return; 03263 } 03264 03265 if ( strName == "ocl::Enumeration" || strName == "enum" ) { 03266 StringVector vecSupers; 03267 vecSupers.push_back( "ocl::Any" ); 03268 vecTypes.push_back(std::unique_ptr<OclMeta::Type>( new OclMeta::Type( "ocl::Enumeration", vecSupers, new OclImplementation::AttributeFactory(), new OclImplementation::AssociationFactory(), new TEnumeration_MethodFactory(), false ) )); 03269 return; 03270 } 03271 03272 if ( strName == "ocl::String" || strName == "string" ) { 03273 StringVector vecSupers; 03274 vecSupers.push_back( "ocl::Any" ); 03275 vecTypes.push_back(std::unique_ptr<OclMeta::Type>( new OclMeta::Type( "ocl::String", vecSupers, new TString_AttributeFactory(), new OclImplementation::AssociationFactory(), new TString_MethodFactory(), false ) )); 03276 return; 03277 } 03278 03279 if ( strName == "ocl::Real" || strName == "real" || strName == "double" ) { 03280 StringVector vecSupers; 03281 vecSupers.push_back( "ocl::Any" ); 03282 vecTypes.push_back(std::unique_ptr<OclMeta::Type>( new OclMeta::Type( "ocl::Real", vecSupers, new OclImplementation::AttributeFactory(), new OclImplementation::AssociationFactory(), new TReal_MethodFactory(), false ) )); 03283 return; 03284 } 03285 03286 if ( strName == "ocl::Integer" || strName == "int" || strName == "long" ) { 03287 StringVector vecSupers; 03288 vecSupers.push_back( "ocl::Real" ); 03289 vecTypes.push_back(std::unique_ptr<OclMeta::Type>( new OclMeta::Type( "ocl::Integer", vecSupers, new OclImplementation::AttributeFactory(), new OclImplementation::AssociationFactory(), new TInteger_MethodFactory(), false ) )); 03290 return; 03291 } 03292 03293 if ( strName == "ocl::Type" || strName == "Type" ) { 03294 StringVector vecSupers; 03295 vecSupers.push_back( "ocl::Any" ); 03296 vecTypes.push_back(std::unique_ptr<OclMeta::Type>( new OclMeta::Type( "ocl::Type", vecSupers, new OclImplementation::AttributeFactory(), new OclImplementation::AssociationFactory(), new OclImplementation::MethodFactory(), false ) )); 03297 return; 03298 } 03299 03300 if ( strName == "ocl::Collection" || strName == "Collection" ) { 03301 StringVector vecSupers; 03302 vecSupers.push_back( "ocl::Any" ); 03303 vecTypes.push_back(std::unique_ptr<OclMeta::Type>( new OclMeta::CompoundType( "ocl::Collection", vecSupers, new TCollection_AttributeFactory(), new OclImplementation::AssociationFactory(), new TCollection_MethodFactory(),new TCollection_IteratorFactory(), false ) )); 03304 return; 03305 } 03306 03307 if ( strName == "ocl::Set" || strName == "Set" ) { 03308 StringVector vecSupers; 03309 vecSupers.push_back( "ocl::Collection" ); 03310 vecTypes.push_back(std::unique_ptr<OclMeta::Type>( new OclMeta::CompoundType( "ocl::Set", vecSupers, new OclImplementation::AttributeFactory(), new OclImplementation::AssociationFactory(), new TSet_MethodFactory(),new TSet_IteratorFactory(), false ) )); 03311 return; 03312 } 03313 03314 if ( strName == "ocl::Sequence" || strName == "Sequence" ) { 03315 StringVector vecSupers; 03316 vecSupers.push_back( "ocl::Collection" ); 03317 vecTypes.push_back(std::unique_ptr<OclMeta::Type>( new OclMeta::CompoundType( "ocl::Sequence", vecSupers, new OclImplementation::AttributeFactory(), new OclImplementation::AssociationFactory(), new TSequence_MethodFactory(),new TSequence_IteratorFactory(), false ) )); 03318 return; 03319 } 03320 03321 if ( strName == "ocl::Bag" || strName == "Bag" ) { 03322 StringVector vecSupers; 03323 vecSupers.push_back( "ocl::Collection" ); 03324 vecTypes.push_back(std::unique_ptr<OclMeta::Type>( new OclMeta::CompoundType( "ocl::Bag", vecSupers, new OclImplementation::AttributeFactory(), new OclImplementation::AssociationFactory(), new TBag_MethodFactory(),new TBag_IteratorFactory(), false ) )); 03325 return; 03326 } 03327 } 03328 03329 }; // namespace OclBasic