Changeset 348:2acc2fd9af4b in finroc_core-java


Ignore:
Timestamp:
13.05.2021 20:26:04 (6 weeks ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Phase:
public
Tags:
tip
Message:

Adds support for new 'to single element vector' type conversion operation. Also, type conversion operation deserialization can now cope with SupportedTypeFilter enum extensions.

Location:
remote
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • remote/RemoteRuntime.java

    r347 r348  
    313313        RemoteTypeConversion getTupleElementOperation = getTypeConversionOperation(RemoteTypeConversion.SupportedTypeFilter.GET_TUPLE_ELEMENT); 
    314314        RemoteTypeConversion adjustLengthOperation = getTypeConversionOperation(RemoteTypeConversion.SupportedTypeFilter.ADJUST_LENGTH); 
     315        RemoteTypeConversion toSingleElementVector = getTypeConversionOperation(RemoteTypeConversion.SupportedTypeFilter.TO_SINGLE_ELEMENT_VECTOR); 
    315316        RemoteTypeConversion captureMetadataOperation = getTypeConversionOperation("Capture Metadata"); 
    316317        RemoteTypeConversion appendMetadataOperation = getTypeConversionOperation("Append Metadata"); 
     
    366367            } 
    367368        } 
     369        if (toSingleElementVector != null) { 
     370            for (int i = 0, n = remoteTypes.size(); i < n; i++) { 
     371                RemoteType type = remoteTypes.get(i); 
     372                if (type.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST && type.getElementType() == sourceType.getHandle()) { 
     373                    fromSourceType.add(new GetCastOperationEntry(toSingleElementVector, type, false)); 
     374                    break; 
     375                } 
     376            } 
     377        } 
    368378 
    369379        // Collect all operations from destination type 
     
    404414                checkType = getUnderlyingTypeOperationsAreInheritedFrom(checkType); 
    405415            } 
     416        } 
     417        if (toSingleElementVector != null && destinationType.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST) { 
     418            fromDestinationType.add(new GetCastOperationEntry(toSingleElementVector, remoteTypes.get(destinationType.getElementType()), false)); 
    406419        } 
    407420 
     
    14351448        } 
    14361449 
     1450        // To single element vector operation 
     1451        for (int i = 0, n = remoteTypes.size(); i < n; i++) { 
     1452            RemoteType candidateType = remoteTypes.get(i); 
     1453            if (candidateType.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST && candidateType.getElementType() == type.getHandle()) { 
     1454                updateConversionRating(ratings.cachedConversionRatings, candidateType.getHandle(), Definitions.TypeConversionRating.EXPLICIT_CONVERSION); 
     1455                break; 
     1456            } 
     1457        } 
     1458 
     1459 
    14371460        RemoteTypeConversion captureMetadataOperation = getTypeConversionOperation("Capture Metadata"); 
    14381461        if (captureMetadataOperation != null) { 
  • remote/RemoteTypeConversion.java

    r345 r348  
    5656 
    5757        // For externally defined non-standard operations 
    58         EXTERNALLY_DEFINED 
     58        EXTERNALLY_DEFINED, 
     59 
     60        // Newer enum constants (appended after 2020) 
     61        TO_SINGLE_ELEMENT_VECTOR,  //!< Types supported by to single element vector operation 
    5962    } 
    6063 
     
    139142    public void deserializeRegisterEntry(BinaryInputStream stream) throws Exception { 
    140143        name = stream.readString(); 
    141         supportedSourceTypes = stream.readEnum(SupportedTypeFilter.class); 
     144        supportedSourceTypes = deserializeSupportedTypeFilter(stream, name); 
    142145        if (supportedSourceTypes == SupportedTypeFilter.SINGLE) { 
    143146            supportedSourceType = RemoteType.deserialize(stream); 
     
    145148            supportedSourceType = null; 
    146149        } 
    147         supportedDestinationTypes = stream.readEnum(SupportedTypeFilter.class); 
     150        supportedDestinationTypes = deserializeSupportedTypeFilter(stream, name); 
    148151        if (supportedDestinationTypes == SupportedTypeFilter.SINGLE) { 
    149152            supportedDestinationType = RemoteType.deserialize(stream); 
     
    219222    /** Handle of conversion operation that this one is not usually combined with (-1 if there is no such operation) */ 
    220223    private short notUsuallyCombinedWithHandle = -1; 
     224 
     225 
     226    /** Helper method to handle new SupportedTypeFilter enum constants (possibly unknown to older Java tools) */ 
     227    private SupportedTypeFilter deserializeSupportedTypeFilter(BinaryInputStream stream, String name) throws Exception { 
     228        int index = stream.readByte(); 
     229        if (index >= SupportedTypeFilter.values().length) { 
     230            Log.log(LogLevel.WARNING, "Conversion operation '" + name + "' has unknown conversion operation type filter (index " + index + "). Setting to EXTERNALLY_DEFINED. Your finstruct installation needs to be updated in order to create connectors with this new conversion operation."); 
     231            return SupportedTypeFilter.EXTERNALLY_DEFINED; 
     232        } 
     233        return SupportedTypeFilter.values()[index]; 
     234    } 
    221235} 
Note: See TracChangeset for help on using the changeset viewer.