Class CompositeDataTypeImpl

    • Field Detail

      • minimumAlignment

        protected int minimumAlignment
      • packing

        protected int packing
    • Method Detail

      • getStoredPackingValue

        public int getStoredPackingValue()
        Description copied from interface: CompositeInternal
        Gets the current packing value (typically a power of 2). Other special values which may be returned include 0 and -1.
        Specified by:
        getStoredPackingValue in interface CompositeInternal
        Returns:
        the current positive packing value, 0 or -1.
      • dataTypeNameChanged

        public void dataTypeNameChanged​(DataType dt,
                                        java.lang.String oldName)
        Description copied from interface: DataType
        Informs this datatype that its name has changed from the indicated old name.

        TODO: This method is reserved for internal DB use.

        Specified by:
        dataTypeNameChanged in interface DataType
        Overrides:
        dataTypeNameChanged in class AbstractDataType
        Parameters:
        dt - the datatype whose name changed
        oldName - the datatype's old name
      • 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
      • isNotYetDefined

        public final boolean isNotYetDefined()
        Determine if this composite should be treated as undefined.

        A composite is considered undefined with a zero-length when it has no components and packing is disabled. A DataTypeComponent defined by an an datatype which is not-yet-defined (i.e., DataType.isNotYetDefined() is true) will always have a size of 1. If an empty composite should be treated as fully specified, packing on the composite should be enabled to ensure that a zero-length component is used should the occassion arise (e.g., empty structure placed within union as a component).

        Specified by:
        isNotYetDefined in interface DataType
        Overrides:
        isNotYetDefined in class AbstractDataType
        Returns:
        true if this type is not yet defined.
      • 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)
                              throws java.lang.IllegalArgumentException
        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 DataType 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. If the DEFAULT datatype is specified when unsupported an Undefined1 will be returned in its place (e.g., packing enabled, Union).
        Parameters:
        dataType - the data type to be checked.
        Returns:
        datatype to be used for insert/add
        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
        Returns:
        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 datatype 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.
      • getMnemonic

        public java.lang.String getMnemonic​(Settings settings)
        Description copied from interface: DataType
        Get the mnemonic for this DataType.
        Specified by:
        getMnemonic in interface DataType
        Overrides:
        getMnemonic in class AbstractDataType
        Parameters:
        settings - settings which may influence the result or null
        Returns:
        the mnemonic for this DataType.
      • repack

        public final void repack()
        Description copied from interface: Composite
        Updates packed composite to any changes in the data organization. If the composite does not have packing enabled this method does nothing.
        NOTE: Changes to data organization is discouraged. Attempts to use this method in such cases should be performed on all composites in dependency order (ignoring pointer components).
        Specified by:
        repack in interface Composite
      • repack

        public abstract boolean repack​(boolean notify)
        Repack components within this composite based on the current packing, alignment and DataOrganization settings. Non-packed Structures: change detection is limited to component count and length is assumed to already be correct.

        NOTE: If modifications to stored length are made prior to invoking this method, detection of a size change may not be possible.

        NOTE: Currently a change in calculated alignment can not be provided since this value is not stored.

        Parameters:
        notify - if true notification will be sent to parents if a size change or component placement change is detected.
        Returns:
        true if a layout change was detected.
      • setPackingEnabled

        public void setPackingEnabled​(boolean enabled)
        Description copied from interface: Composite
        Sets whether this data type's internal components are currently packed. The affect of disabled packing differs between Structure and Union. When packing disabled:
        • Structures utilize explicit component offsets and produce undefined filler components where defined components do not consume space.
        • Unions always place components at offset 0 and do not pad for alignment.
        In addition, when packing is disabled the default alignment is always 1 unless a different minimum alignment has been set. When packing is enabled the overall composite length influenced by the composite's minimum alignment setting. If a change in enablement occurs, the default alignment and packing behavior will be used.
        Specified by:
        setPackingEnabled in interface Composite
        Parameters:
        enabled - true enables packing of components respecting component alignment and pack setting, whereas false disables packing.
      • setToDefaultPacking

        public void setToDefaultPacking()
        Description copied from interface: Composite
        Enables default packing behavior. If packing was previously disabled, packing will be enabled. Composite will automatically pack based upon the alignment requirements of its components with overall composite length possibly influenced by the composite's minimum alignment setting.
        Specified by:
        setToDefaultPacking in interface Composite
      • getExplicitPackingValue

        public int getExplicitPackingValue()
        Description copied from interface: Composite
        Gets the current packing value (typically a power of 2). If this isn't a packed composite with an explicit packing value (see Composite.hasExplicitPackingValue()) then the return value is undefined.
        Specified by:
        getExplicitPackingValue in interface Composite
        Returns:
        the current packing value or an undefined non-positive value
      • setExplicitPackingValue

        public void setExplicitPackingValue​(int packingValue)
        Description copied from interface: Composite
        Sets the pack value for this composite (positive value, usually a power of 2). If packing was previously disabled, packing will be enabled. This value will establish the maximum effective alignment for this composite and each of the components during the alignment computation (e.g., a value of 1 will eliminate any padding). The overall composite length may be influenced by the composite's minimum alignment setting.
        Specified by:
        setExplicitPackingValue in interface Composite
        Parameters:
        packingValue - the new positive packing value.
      • setToDefaultAligned

        public void setToDefaultAligned()
        Description copied from interface: Composite
        Sets this data type's alignment to its default alignment. For packed composites, this data type's alignment will be based upon the components it contains and its current pack settings. This is the default state and only needs to be used when changing from a non-default alignment type.
        Specified by:
        setToDefaultAligned in interface Composite
      • setToMachineAligned

        public void setToMachineAligned()
        Description copied from interface: Composite
        Sets this data type's minimum alignment to the machine alignment which is specified by DataOrganization.getMachineAlignment(). The machine alignment is defined as the maximum useful alignment for the target machine.
        Specified by:
        setToMachineAligned in interface Composite
      • getExplicitMinimumAlignment

        public int getExplicitMinimumAlignment()
        Description copied from interface: Composite
        Get the explicit minimum alignment setting for this Composite which contributes to the actual computed alignment value (see Composite.getAlignment().
        Specified by:
        getExplicitMinimumAlignment in interface Composite
        Returns:
        the minimum alignment setting for this Composite or an undefined non-positive value if an explicit minimum alignment has not been set.
      • setExplicitMinimumAlignment

        public void setExplicitMinimumAlignment​(int minimumAlignment)
        Description copied from interface: Composite
        Sets this data type's explicit minimum alignment (positive value). Together with the pack setting and component alignments will affect the actual computed alignment of this composite. When packing is enabled, the alignment setting may also affect padding at the end of the composite and its length. When packing is disabled, this setting will not affect the length of this composite.
        Specified by:
        setExplicitMinimumAlignment in interface Composite
        Parameters:
        minimumAlignment - the minimum alignment for this Composite.
      • getNonPackedAlignment

        protected final int getNonPackedAlignment()
      • getAlignment

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