Class CompositeDataTypeImpl

    • Field Detail

      • aligned

        protected boolean aligned
      • packingValue

        protected int packingValue
      • externalAlignment

        protected int externalAlignment
    • Method Detail

      • getPreferredComponentLength

        protected int getPreferredComponentLength​(DataType dataType,
                                                  int length)
        Get the preferred length for a new component. For Unions and internally aligned structures the preferred component length for a fixed-length dataType will be the length of that dataType. Otherwise the length returned will be no larger than the specified length.
        Parameters:
        dataType - new component datatype
        length - constrained length or -1 to force use of dataType size. Dynamic types such as string must have a positive length specified.
        Returns:
        preferred component length
      • isPartOf

        public boolean isPartOf​(DataType dataTypeOfInterest)
        Description copied from interface: Composite
        Check if a data type is part of this data type. A data type could be part of another by:
        Being the same data type.
        containing the data type directly
        containing another data type that has the data type as a part of it.
        Specified by:
        isPartOf in interface Composite
        Parameters:
        dataTypeOfInterest - the data type to look for.
        Returns:
        true if the indicated data type is part of a sub-component of this data type.
      • checkAncestry

        protected void checkAncestry​(DataType dataType)
        This method throws an exception if the indicated data type is an ancestor of this data type. In other words, the specified data type has a component or sub-component containing this data type.
        Parameters:
        dataType - the data type
        Throws:
        java.lang.IllegalArgumentException - if the data type is an ancestor of this data type.
      • validateDataType

        protected void validateDataType​(DataType dataType)
        This method throws an exception if the indicated data type is not a valid data type for a component of this composite data type.
        Parameters:
        dataType - the data type to be checked.
        Throws:
        java.lang.IllegalArgumentException - if the data type is invalid.
      • updateBitFieldDataType

        protected boolean updateBitFieldDataType​(DataTypeComponentImpl bitfieldComponent,
                                                 DataType oldDt,
                                                 DataType newDt)
                                          throws InvalidDataTypeException
        Handle replacement of datatype which may impact bitfield datatype.
        Parameters:
        bitfieldComponent - bitfield component
        oldDt - affected datatype which has been removed or replaced
        newDt - replacement datatype
        true - if bitfield component was modified
        Throws:
        InvalidDataTypeException - if new datatype is not
      • setDescription

        public void setDescription​(java.lang.String desc)
        Description copied from class: DataTypeImpl
        Sets a String briefly describing this DataType.
        If a data type that extends this class wants to allow the description to be changed, then it must override this method.
        Specified by:
        setDescription in interface Composite
        Specified by:
        setDescription in interface DataType
        Overrides:
        setDescription in class DataTypeImpl
        Parameters:
        desc - a one-liner describing this DataType.
      • getDescription

        public java.lang.String getDescription()
        Description copied from interface: DataType
        Get a String briefly describing this DataType.
        Specified by:
        getDescription in interface DataType
        Returns:
        a one-liner describing this DataType.
      • getValue

        public java.lang.Object getValue​(MemBuffer buf,
                                         Settings settings,
                                         int length)
        Description copied from interface: DataType
        Get the data in the form of the appropriate Object for this DataType. For instance if the data type is an AddressDT, return an Address object. a Byte, return a Scalar* (maybe this should be a Byte) a Float, return a Float
        Specified by:
        getValue in interface DataType
        Parameters:
        buf - the data buffer.
        settings - the settings to use.
        length - the number of bytes to get the value from.
        Returns:
        the data Object.
      • setValue

        public void setValue​(MemBuffer buf,
                             Settings settings,
                             int length,
                             java.lang.Object value)
      • add

        public final DataTypeComponent add​(DataType dataType)
        Description copied from interface: Composite
        Adds a new datatype to the end of this composite. This is the preferred method to use for adding components to an aligned structure for fixed-length dataTypes.
        Specified by:
        add in interface Composite
        Parameters:
        dataType - the datatype to add.
        Returns:
        the DataTypeComponent created.
      • add

        public final DataTypeComponent add​(DataType dataType,
                                           int length)
        Description copied from interface: Composite
        Adds a new datatype to the end of this composite. This is the preferred method to use for adding components to an aligned structure for dynamic dataTypes such as strings whose length must be specified.
        Specified by:
        add in interface Composite
        Parameters:
        dataType - the datatype to add.
        length - the length to associate with the datatype. For fixed length types a length <= 0 will use the length of the resolved dataType.
        Returns:
        the componentDataType created.
      • add

        public final DataTypeComponent add​(DataType dataType,
                                           java.lang.String fieldName,
                                           java.lang.String comment)
        Description copied from interface: Composite
        Adds a new datatype to the end of this composite. This is the preferred method to use for adding components to an aligned structure for fixed-length dataTypes.
        Specified by:
        add in interface Composite
        Parameters:
        dataType - the datatype to add.
        fieldName - the field name to associate with this component.
        comment - the comment to associate with this component.
        Returns:
        the componentDataType created.
      • insert

        public final DataTypeComponent insert​(int ordinal,
                                              DataType dataType,
                                              int length)
        Description copied from interface: Composite
        Inserts a new datatype at the specified ordinal position in this composite.
        Note: For an aligned structure the ordinal position will get adjusted automatically to provide the proper alignment.
        Specified by:
        insert in interface Composite
        Parameters:
        ordinal - the ordinal where the new datatype is to be inserted.
        dataType - the datatype to insert.
        length - the length to associate with the datatype. For fixed length types a length <= 0 will use the length of the resolved dataType.
        Returns:
        the componentDataType created.
      • insert

        public final DataTypeComponent insert​(int ordinal,
                                              DataType dataType)
        Description copied from interface: Composite
        Inserts a new datatype at the specified ordinal position in this composite.
        Note: For an aligned structure the ordinal position will get adjusted automatically to provide the proper alignment.
        Specified by:
        insert in interface Composite
        Parameters:
        ordinal - the ordinal where the new datatype is to be inserted.
        dataType - the datatype to insert.
        Returns:
        the componentDataType created.
      • getPackingValue

        public int getPackingValue()
        Description copied from interface: Composite
        Gets the current packing value (typically a power of 2). If this isn't a packed data type then NOT_PACKING is returned. The packing value only pertains to internally aligned composite data types. Aligned structures allow packing.
        Specified by:
        getPackingValue in interface Composite
        Returns:
        the current packing value or NOT_PACKING.
      • setPackingValue

        public void setPackingValue​(int packingValue)
        Description copied from interface: Composite
        Sets the current packing value (usually a power of 2). A value of NOT_PACKING should be passed if this isn't a packed data type. Otherwise this value indicates a maximum alignment for any component within this data type. Calling this method will cause the data type to become an internally aligned data type.
        Note: If a component's data type has a specific external alignment, it will override this value if necessary.
        Specified by:
        setPackingValue in interface Composite
        Parameters:
        packingValue - the new packing value or 0 for NOT_PACKING. A negative value will be treated the same as 0.
      • getMinimumAlignment

        public int getMinimumAlignment()
        Description copied from interface: Composite
        Get the external alignment (a minimum alignment) for this DataType. This controls where this data type will get aligned within other data types. It also causes the end of this data type to get padded so its length is a multiple of the alignment.
        Specified by:
        getMinimumAlignment in interface Composite
        Returns:
        the external alignment for this DataType or DEFAULT_ALIGNMENT_VALUE.
      • setMinimumAlignment

        public void setMinimumAlignment​(int externalAlignment)
        Description copied from interface: Composite
        Sets the external alignment (a minimum alignment) for this DataType. This controls where this data type will get aligned within other data types. It also causes the end of this data type to get padded so its length is a multiple of the alignment. Calling this method will cause the data type to become an internally aligned data type.
        Specified by:
        setMinimumAlignment in interface Composite
        Parameters:
        externalAlignment - the external (minimum) alignment for this DataType. Any value less than 1 will revert to default alignment.
      • isInternallyAligned

        public boolean isInternallyAligned()
        Description copied from interface: Composite
        Determine if this data type has its internal components currently aligned.
        Specified by:
        isInternallyAligned in interface Composite
        Returns:
        true if this data type's components are aligned relative to each other using the current data organization. When internally aligned the end of this data type will be padded to a multiple of its actual alignment.
      • isDefaultAligned

        public boolean isDefaultAligned()
        Description copied from interface: Composite
        Whether or not this data type is using the default external (minimum) alignment.
        Specified by:
        isDefaultAligned in interface Composite
        Returns:
        true if this data type has the default external alignment.
      • isMachineAligned

        public boolean isMachineAligned()
        Description copied from interface: Composite
        Whether or not this data type is using the machine alignment value from the DataOrganization for its external (minimum) alignment.
        Specified by:
        isMachineAligned in interface Composite
        Returns:
        true if this data type is using the machine alignment as the minimum alignment.
      • setInternallyAligned

        public void setInternallyAligned​(boolean aligned)
        Description copied from interface: Composite
        Sets whether this data type's internal components are currently aligned or unaligned.
        Specified by:
        setInternallyAligned in interface Composite
        Parameters:
        aligned - true means align the internal components of this data type. false means don't align it. True also causes the end of this data type to be padded to a multiple of its actual alignment.
      • setToDefaultAlignment

        public void setToDefaultAlignment()
        Description copied from interface: Composite
        Sets this data type's external (minimum) alignment to the default alignment. This data type's external alignment will be based upon the components it contains. This should be used when a data type doesn't have an alignment attribute specified. Calling this method will cause the data type to become an internally aligned data type.
        Specified by:
        setToDefaultAlignment in interface Composite
      • setToMachineAlignment

        public void setToMachineAlignment()
        Description copied from interface: Composite
        Sets this data type's external (minimum) alignment to a multiple of the machine alignment that is specified in the DataOrganization. The machine alignment is defined as the maximum useful alignment for the target machine. This should be used when a data type has an alignment attribute specified without a size (indicating to use the machine alignment). Calling this method will cause the data type to become an internally aligned data type.
        Specified by:
        setToMachineAlignment in interface Composite
      • notifyAlignmentChanged

        protected void notifyAlignmentChanged()
        Notify any parent data types that this composite data type's alignment has changed.
      • adjustInternalAlignment

        protected abstract void adjustInternalAlignment()
        Adjusts the internal alignment of components within this composite based on the current settings of the internal alignment, packing, alignment type and minimum alignment value. This method should be called whenever any of the above settings are changed or whenever a components data type is changed or a component is added or removed.
      • getAlignment

        public int getAlignment()
        Description copied from interface: DataType
        Gets the alignment to be used when aligning this data type within another data type.
        Specified by:
        getAlignment in interface DataType
        Overrides:
        getAlignment in class DataTypeImpl
        Returns:
        this data type's alignment.
      • setAlignment

        protected void setAlignment​(Composite composite)
      • dumpComponents

        protected void dumpComponents​(java.lang.StringBuilder buffer,
                                      java.lang.String pad)
        Dump all components for use in toString() representation.
        Parameters:
        buffer - string buffer
        pad - padding to be used with each component output line