Class Struct

java.lang.Object
net.codecrete.windowsapi.metadata.Type
net.codecrete.windowsapi.metadata.Struct

public final class Struct extends Type
Struct or union.

Structs can either be independent or nested. An independent type has a namespace and can be the enclosing type for nested types. Nested types have no namespace and must be contained in an enclosing parent type. They often have artificial names like _Anonymous_e__Struct. Nested types are typically used for unnamed structs or unions.

  • Constructor Details

    • Struct

      public Struct(String name, Namespace namespace, int typeDefIndex, boolean isUnion, int packageSize, int structSize, Struct enclosingType, String structSizeMember, UUID guid)
      Creates a new instance.
      Parameters:
      name - the struct name
      namespace - the namespace
      typeDefIndex - the TypeDef index
      isUnion - indicates if the new instance is a union (instead of a struct)
      packageSize - the package size (alignment) of this struct (in bytes)
      structSize - the size of this struct (in bytes)
      enclosingType - the enclosing type in case it is a nested type
      structSizeMember - the struct field holding the struct's size (usually a member called {code cbSize}).
      guid - the GUID associated with the struct
  • Method Details

    • isUnion

      public boolean isUnion()
      Indicates if this is a union.
      Returns:
      true if it is a union, false if it is a struct
    • packageSize

      public int packageSize()
      Returns the package size, i.e., the alignment required by this struct.
      Returns:
      the package size (in bytes)
    • setPackageSize

      public void setPackageSize(int packageSize)
      Sets the package size, i.e., the alignment required by this struct.
      Parameters:
      packageSize - the package size (in bytes)
    • structSize

      public int structSize()
      Gets the struct size (length).
      Returns:
      the struct size (in bytes).
    • setStructSize

      public void setStructSize(int structSize)
      Sets the struct size (length).
      Parameters:
      structSize - the struct size (in bytes).
    • isLayoutDone

      public boolean isLayoutDone()
      Indicates if the layout of this struct has been calculated.
      Returns:
      {code true} if it is done
    • setLayoutDone

      public void setLayoutDone()
      Marks that the layout of this struct has been calculated.
    • enclosingType

      public Struct enclosingType()
      Gets the parent type enclosing this type.
      Returns:
      the enclosing type, or null if this type is not nested
    • addNestedType

      public void addNestedType(Type nestedType)
      Adds the given type as a nested type of this type.
      Parameters:
      nestedType - the nested type
    • getNestedType

      public Type getNestedType(String name)
      Gets the nested type with the given name.
      Parameters:
      name - the type name
      Returns:
      the nested type
    • hasNestedTypes

      public boolean hasNestedTypes()
      Indicates if this type contains nested types.
      Returns:
      true if this type has nested types
    • nestedTypes

      public Collection<Type> nestedTypes()
      Gets the nested types.
      Returns:
      the types
    • members

      public List<Member> members()
      Gets this struct's members (fields).
      Returns:
      the members
    • setMembers

      public void setMembers(List<Member> members)
      Sets this struct's members (fields).
      Parameters:
      members - the members
    • isNested

      public boolean isNested()
      Indicates if this type is a nested type.
      Returns:
      true if this type is nested
    • hasFixedSize

      public boolean hasFixedSize()
      Indicates if this struct has a fixed size.

      A struct does not have a fixed size if it contains a flexible array, i.e., an array with a variable number of elements.

      Returns:
      true if this struct has a fixed size
    • flexibleArrayMember

      public Member flexibleArrayMember()
      Gets the field within this struct that is a flexible array
      Returns:
      the flexible array member, or null if there is no such member
    • setFlexibleArrayMember

      public void setFlexibleArrayMember(Member flexibleArrayMember)
      Sets the field within this struct that is a flexible array
      Parameters:
      flexibleArrayMember - the flexible array member, or null if there is no such member
    • structSizeMember

      public String structSizeMember()
      Gets the field within this struct that indicates the struct size.

      The Windows API can support multiple versions of the same struct if the struct has a field indicating the size of the struct. It must be set by the caller.

      If the struct contains such a field, it is usually called cbSize.

      Returns:
      the field containing the struct size, or null if there is no such field
    • isArchitectureSpecific

      public boolean isArchitectureSpecific()
      Indicates if this struct is only valid for certain processor architectures (X64, ARM64).

      If it is architecture-specific, there might be separate versions of each architecture, or it might not be supported on all architectures.

      Returns:
      true if it is architecture-specific
    • setArchitectureSpecific

      public void setArchitectureSpecific(boolean isArchitectureSpecific)
      Sets if this struct is only valid for certain processor architectures (X64, ARM64).

      If it is architecture-specific, there might be separate versions of each architecture, or it might not be supported on all architectures.

      Parameters:
      isArchitectureSpecific - true if it is architecture-specific, false if it is valid for all architecture
    • guid

      public UUID guid()
      Gets the GUID associated with this struct.
      Returns:
      the GUID
    • referencedTypes

      public Stream<Type> referencedTypes()
      Description copied from class: Type
      Returns the types directly references by this type.
      Overrides:
      referencedTypes in class Type
      Returns:
      Stream of types
    • duplicate

      public Struct duplicate(int newTypeDefIndex)
      Creates a copy of this type and assigns it a different TypeDef index.
      Parameters:
      newTypeDefIndex - the new TypeDef index
      Returns:
      the copied type
    • replaceTypes

      public void replaceTypes(UnaryOperator<Type> typeReplacement)
      Description copied from class: Type
      Replace the types directly referenced by this type with the provided replacements.

      The lambda for replacement lookup will return the same type if no replacement is needed.

      Overrides:
      replaceTypes in class Type
      Parameters:
      typeReplacement - lambda for looking up the replacement type.