Changeset 353:d80caa0f753d in finroc_core-java
- Timestamp:
- 14.02.2022 07:07:32 (22 months ago)
- Branch:
- default
- Phase:
- public
- Tags:
- tip
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
remote/RemoteType.java
r341 r353 48 48 EXACT, // Option 1: Local type is the exact counterpart to remote type 49 49 ADAPTED, // Option 2: Local type is adapted via a type adapter 50 CAST, // Option 3: Local type is obtained via static cast from and to remote type 50 CAST, // Option 3: Local type is obtained via static cast from and to remote type (conversion to and from local type is lossless) 51 51 STRING, // Option 4: Type's string representation is used 52 52 XML, // Option 5: Type's XML representation is used 53 EVENT, // Option 6: Event type is used 53 LOSSY_CAST,// Option 6: Local type is obtained via static cast from and to remote type (conversion to and from local type is lossy) 54 EVENT, // Option 7: Event type is used 54 55 NONE // Local type has not yet been resolved 55 56 } … … 292 293 } 293 294 294 // Option 3 : Type has a static cast operation to and from known type (underlying type is preferred, next choices are types with best local type match - and smallest size difference)295 // Option 3/6: Type has a static cast operation to and from known type (underlying type is preferred, next choices are types with best local type match - and smallest size difference) 295 296 RemoteType castedTo = null; 297 boolean lossyCast = false; 296 298 if ((typeTraits & DataTypeBase.HAS_UNDERLYING_TYPE) != 0) { 297 299 castedTo = runtime.getTypes().get(underlyingType); … … 309 311 if (cast.getSourceType() == this && runtime.isStaticCastSupported(cast.getDestinationType(), this)) { 310 312 RemoteType candidate = cast.getDestinationType(); 313 boolean candidateCastLossy = candidate.size < this.size; 311 314 if (maxCasts == 2) { 312 315 candidate.resolveDefaultLocalType(runtime, 1); 313 316 } 314 if (candidate.getCastCountForDefaultLocalType() <= 1 && (castedTo == null || (candidate.localTypeMatch.ordinal() < castedTo.localTypeMatch.ordinal()) || (candidate.localTypeMatch == castedTo.localTypeMatch && Math.abs(candidate.size - this.size) < Math.abs(castedTo.size - this.size)))) { 317 if (candidate.getCastCountForDefaultLocalType() <= 1 && (castedTo == null || (candidate.localTypeMatch.ordinal() < castedTo.localTypeMatch.ordinal()) || 318 (candidate.localTypeMatch == castedTo.localTypeMatch && ((!candidateCastLossy) || lossyCast) && (((!candidateCastLossy) && lossyCast) || Math.abs(candidate.size - this.size) < Math.abs(castedTo.size - this.size))))) { 315 319 castedTo = candidate; 320 lossyCast = candidateCastLossy; 321 //System.out.println("Cast operation adapted type (this -> casted to): " + this.getName() + " " + this.getSize() + " -> " + castedTo.getName() + " " + castedTo.getSize()+ " " + lossyCast); 316 322 } 317 323 } … … 320 326 321 327 localTypeCastsChecked |= (maxCasts >= 2); 322 if (castedTo != null ) {328 if (castedTo != null && ((!lossyCast) || localTypeMatch.ordinal() > LocalTypeMatch.LOSSY_CAST.ordinal())) { 323 329 this.castedTo = castedTo; 324 330 localDataType = castedTo.localDataType; 325 localTypeMatch = LocalTypeMatch.CAST;331 localTypeMatch = lossyCast ? LocalTypeMatch.LOSSY_CAST : LocalTypeMatch.CAST; 326 332 return; 327 333 } … … 364 370 365 371 // Options 4 and 5: Type has a string or XML representation 366 // Option 6: Use empty (event) type372 // Option 7: Use empty (event) type 367 373 RemoteTypeAdapter.Default defaultAdapter = RemoteTypeAdapter.Default.getInstance(); 368 374 defaultAdapter.handleType(this, info); … … 403 409 break; 404 410 case CAST: 411 case LOSSY_CAST: 405 412 castedTo.deserializeData(stream, object); 406 413 break; … … 429 436 break; 430 437 case CAST: 438 case LOSSY_CAST: 431 439 castedTo.serializeData(stream, object); 432 440 break;
Note: See TracChangeset
for help on using the changeset viewer.