Class UnionDataType

    • Constructor Detail

      • UnionDataType

        public UnionDataType​(CategoryPath path,
                             java.lang.String name)
        Construct a new empty union with the given name within the specified categry path. An empty union will report its length as 1 and CompositeDataTypeImpl.isNotYetDefined() will return true.
        Parameters:
        path - the category path indicating where this data type is located.
        name - the name of the new union
      • UnionDataType

        public UnionDataType​(CategoryPath path,
                             java.lang.String name,
                             DataTypeManager dtm)
        Construct a new empty union with the given name and datatype manager within the specified categry path. An empty union will report its length as 1 and CompositeDataTypeImpl.isNotYetDefined() will return true.
        Parameters:
        path - the category path indicating where this data type is located.
        name - the name of the new union
        dtm - the data type manager associated with this data type. This can be null. Also, the data type manager may not yet contain this actual data type.
      • UnionDataType

        public UnionDataType​(CategoryPath path,
                             java.lang.String name,
                             UniversalID universalID,
                             SourceArchive sourceArchive,
                             long lastChangeTime,
                             long lastChangeTimeInSourceArchive,
                             DataTypeManager dtm)
        Construct a new empty union with the given name within the specified categry path. An empty union will report its length as 1 and CompositeDataTypeImpl.isNotYetDefined() will return true.
        Parameters:
        path - the category path indicating where this data type is located.
        name - the name of the new structure
        universalID - the id for the data type
        sourceArchive - the source archive for this data type
        lastChangeTime - the last time this data type was changed
        lastChangeTimeInSourceArchive - the last time this data type was changed in its source archive.
        dtm - the data type manager associated with this data type. This can be null. Also, the data type manager may not contain this actual data type.
      • UnionDataType

        public UnionDataType​(java.lang.String name)
        Construct a new UnionDataType
        Parameters:
        name - the name of this dataType
    • Method Detail

      • getRepresentation

        public java.lang.String getRepresentation​(MemBuffer buf,
                                                  Settings settings,
                                                  int length)
        Description copied from interface: DataType
        Get bytes from memory in a printable format for this type.
        Specified by:
        getRepresentation in interface DataType
        Parameters:
        buf - the data.
        settings - the settings to use for the representation.
        length - the number of bytes to represent.
        Returns:
        the representation of the data in this format, never null.
      • getComponent

        public DataTypeComponent getComponent​(int ordinal)
        Description copied from interface: Composite
        Returns the component of this data type with the indicated ordinal.
        Specified by:
        getComponent in interface Composite
        Parameters:
        ordinal - the component's ordinal (zero based).
        Returns:
        the data type component.
      • getComponents

        public DataTypeComponent[] getComponents()
        Description copied from interface: Composite
        Returns an array of Data Type Components that make up this composite including undefined filler components which may be present within a Structure whch has packing disabled. The number of components corresponds to Composite.getNumComponents().
        Specified by:
        getComponents in interface Composite
        Returns:
        array all components
      • getDefinedComponents

        public DataTypeComponent[] getDefinedComponents()
        Description copied from interface: Composite
        Returns an array of Data Type Components that make up this composite excluding undefined filler components which may be present within Structures where packing is disabled. The number of components corresponds to Composite.getNumDefinedComponents(). For Unions and packed Structures this is equivalent to Composite.getComponents() since they do not contain undefined filler components.
        Specified by:
        getDefinedComponents in interface Composite
        Returns:
        array all explicitly defined components
      • getNumComponents

        public int getNumComponents()
        Description copied from interface: Composite
        Gets the number of component data types in this composite. If this is Structure with packing disabled, the count will include all undefined filler components which may be present.
        Specified by:
        getNumComponents in interface Composite
        Returns:
        the number of components that make up this composite
      • getNumDefinedComponents

        public int getNumDefinedComponents()
        Description copied from interface: Composite
        Returns the number of explicitly defined components in this composite. For Unions and packed Structures this is equivalent to Composite.getNumComponents() since they do not contain undefined components. This count will always exclude all undefined filler components which may be present within a Structure whose packing is disabled (see Composite.isPackingEnabled()).
        Specified by:
        getNumDefinedComponents in interface Composite
        Returns:
        the number of explicitly defined components in this composite
      • getPreferredComponentLength

        protected int getPreferredComponentLength​(DataType dataType,
                                                  int length)
        Description copied from class: CompositeDataTypeImpl
        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.
        Overrides:
        getPreferredComponentLength in class CompositeDataTypeImpl
        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
      • add

        public DataTypeComponent add​(DataType dataType,
                                     int length,
                                     java.lang.String componentName,
                                     java.lang.String comment)
                              throws java.lang.IllegalArgumentException
        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.
        componentName - the field name to associate with this component.
        comment - the comment to associate with this component.
        Returns:
        the componentDataType created.
        Throws:
        java.lang.IllegalArgumentException - if the specified data type is not allowed to be added to this composite data type or an invalid length is specified. For example, suppose dt1 contains dt2. Therefore it is not valid to add dt1 to dt2 since this would cause a cyclic dependency.
      • insert

        public DataTypeComponent insert​(int ordinal,
                                        DataType dataType,
                                        int length,
                                        java.lang.String componentName,
                                        java.lang.String comment)
                                 throws java.lang.IllegalArgumentException
        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.
        componentName - the field name to associate with this component.
        comment - the comment to associate with this component.
        Returns:
        the componentDataType created.
        Throws:
        java.lang.IllegalArgumentException - if the specified data type is not allowed to be inserted into this composite data type or an invalid length is specified. For example, suppose dt1 contains dt2. Therefore it is not valid to insert dt1 to dt2 since this would cause a cyclic dependency.
      • addBitField

        public DataTypeComponent addBitField​(DataType baseDataType,
                                             int bitSize,
                                             java.lang.String componentName,
                                             java.lang.String comment)
                                      throws InvalidDataTypeException
        Description copied from interface: Composite
        Adds a new bitfield to the end of this composite. This method is intended to be used with packed structures/unions only where the bitfield will be appropriately packed. The minimum storage storage byte size will be applied. It will not provide useful results for composites with packing disabled.
        Specified by:
        addBitField in interface Composite
        Parameters:
        baseDataType - the bitfield base datatype (certain restrictions apply).
        bitSize - the bitfield size in bits
        componentName - the field name to associate with this component.
        comment - the comment to associate with this component.
        Returns:
        the componentDataType created whose associated data type will be BitFieldDataType.
        Throws:
        InvalidDataTypeException - if the specified data type is not a valid base type for bitfields.
      • insertBitField

        public DataTypeComponent insertBitField​(int ordinal,
                                                DataType baseDataType,
                                                int bitSize,
                                                java.lang.String componentName,
                                                java.lang.String comment)
                                         throws InvalidDataTypeException,
                                                java.lang.IndexOutOfBoundsException
        Description copied from interface: Union
        Inserts a new bitfield at the specified ordinal position in this union. For all Unions, bitfield starts with bit-0 (lsb) of the first byte for little-endian, and with bit-7 (msb) of the first byte for big-endian. This is the default behavior for most compilers. Insertion behavior may not work as expected if packing rules differ from this.
        Specified by:
        insertBitField in interface Union
        Parameters:
        ordinal - the ordinal where the new datatype is to be inserted.
        baseDataType - the bitfield base datatype (certain restrictions apply).
        bitSize - the declared bitfield size in bits. The effective bit size may be adjusted based upon the specified baseDataType.
        componentName - the field name to associate with this component.
        comment - the comment to associate with this component.
        Returns:
        the bitfield component created whose associated data type will be BitFieldDataType.
        Throws:
        InvalidDataTypeException - if the specified baseDataType is not a valid base type for bitfields.
        java.lang.IndexOutOfBoundsException - if ordinal is less than 0 or greater than the current number of components.
      • clone

        public Union clone​(DataTypeManager dtm)
        Description copied from interface: DataType
        Returns an instance of this DataType with its universalID and SourceArchive identity retained.

        The current instanceof will be returned if this datatype's DataTypeManager matches the specified dtm. The recursion depth of a clone will stop on any datatype whose DataTypeManager matches the specified dtm and simply use the existing datatype instance.

        Specified by:
        clone in interface DataType
        Specified by:
        clone in interface Union
        Parameters:
        dtm - the data-type manager instance whose data-organization should apply.
        Returns:
        cloned instance which may be the same as this instance
      • copy

        public DataType copy​(DataTypeManager dtm)
        Description copied from interface: DataType
        Returns a new instance (shallow copy) of this DataType with a new identity.

        Any reference to other datatypes will use DataType.clone(DataTypeManager).

        Specified by:
        copy in interface DataType
        Parameters:
        dtm - the data-type manager instance whose data-organization should apply.
        Returns:
        new instanceof of this datatype
      • delete

        public void delete​(int ordinal)
        Description copied from interface: Composite
        Deletes the component at the given ordinal position.
        Note: Removal of bitfields from a structure with packing disabled will not shift other components causing vacated bytes to revert to undefined filler.
        Specified by:
        delete in interface Composite
        Parameters:
        ordinal - the ordinal of the component to be deleted.
      • delete

        public void delete​(java.util.Set<java.lang.Integer> ordinals)
        Description copied from interface: Composite
        Deletes the specified set of components at the given ordinal positions.
        Note: Removal of bitfields from a structure with packing disabled will not shift other components causing vacated bytes to revert to undefined filler.
        Specified by:
        delete in interface Composite
        Parameters:
        ordinals - the ordinals of the component to be deleted.
      • repack

        public boolean repack​(boolean notify)
        Description copied from class: CompositeDataTypeImpl
        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.

        Specified by:
        repack in class CompositeDataTypeImpl
        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.
      • isEquivalent

        public boolean isEquivalent​(DataType dt)
        Description copied from interface: DataType
        Check if the given datatype is equivalent to this datatype.

        The precise meaning of "equivalent" is datatype dependent.
        NOTE: if invoked by a DB object or manager it should be invoked on the DataTypeDB object passing the other datatype as the argument.

        Specified by:
        isEquivalent in interface DataType
        Parameters:
        dt - the datatype being tested for equivalence.
        Returns:
        true if the if the given datatype is equivalent to this datatype.
      • dataTypeSizeChanged

        public void dataTypeSizeChanged​(DataType dt)
        Description copied from interface: DataType
        Notification that the given datatype's size has changed.

        DataTypes may need to make internal changes in response.
        TODO: This method is reserved for internal DB use.

        Specified by:
        dataTypeSizeChanged in interface DataType
        Overrides:
        dataTypeSizeChanged in class AbstractDataType
        Parameters:
        dt - the datatype that has changed.
      • dataTypeReplaced

        public void dataTypeReplaced​(DataType oldDt,
                                     DataType newDt)
                              throws java.lang.IllegalArgumentException
        Description copied from interface: DataType
        Informs this datatype that the given oldDT has been replaced with newDT

        TODO: This method is reserved for internal DB use.

        Specified by:
        dataTypeReplaced in interface DataType
        Overrides:
        dataTypeReplaced in class AbstractDataType
        Parameters:
        oldDt - old datatype
        newDt - new datatype
        Throws:
        java.lang.IllegalArgumentException
      • dataTypeDeleted

        public void dataTypeDeleted​(DataType dt)
        Description copied from interface: DataType
        Informs this datatype that the given datatype has been deleted.

        TODO: This method is reserved for internal DB use.

        Specified by:
        dataTypeDeleted in interface DataType
        Overrides:
        dataTypeDeleted in class AbstractDataType
        Parameters:
        dt - the datatype that has been deleted.
      • replaceWith

        public void replaceWith​(DataType dataType)
                         throws java.lang.IllegalArgumentException
        Description copied from interface: DataType
        For datatypes that support change, this method replaces the internals of this datatype with the internals of the given datatype.

        The datatypes must be of the same "type" (i.e. structure can only be replacedWith another structure.

        Specified by:
        replaceWith in interface DataType
        Overrides:
        replaceWith in class DataTypeImpl
        Throws:
        java.lang.IllegalArgumentException - if the given datatype is not the same type as this datatype.
      • dependsOn

        public boolean dependsOn​(DataType dt)
        Description copied from interface: DataType
        Check if this datatype depends on the existence of the given datatype.

        For example byte[] depends on byte. If byte were deleted, then byte[] would also be deleted.

        Specified by:
        dependsOn in interface DataType
        Overrides:
        dependsOn in class AbstractDataType
        Parameters:
        dt - the datatype to test that this datatype depends on.
        Returns:
        true if the existence of this datatype relies on the existence of the specified datatype dt.
      • getDefaultLabelPrefix

        public java.lang.String getDefaultLabelPrefix()
        Description copied from interface: DataType
        Returns the appropriate string to use as the default label prefix in the absence of any data.
        Specified by:
        getDefaultLabelPrefix in interface DataType
        Overrides:
        getDefaultLabelPrefix in class AbstractDataType
        Returns:
        the default label prefix or null if none specified.