Class Field

Class Documentation

class Field

Public Functions

Field()

Default constructor; all members are initialized to their zero values.

Field(char const *name, char const *typeString, BasicType basicType, size_t offset, size_t size, Struct const *structRef, Enum const *enumRef, Union const *unionRef, Field const *lenField, BasicType referencedType, size_t elementCount, std::function<size_t(uint64_t)> lengthFunction = nullptr)

Full constructor; all members are initialized to the values passed as arguments to this constructor.

Parameters
  • name -- Name of the field as declared in the original API header file

  • typeString -- Type of the field as declared in the original API header file

  • basicType -- BasicType of the field; GetBasicType() can be used to determine this.

  • offset -- Offset, in bytes, of the field, from the beginning of the parent struct's storage

  • size -- Size, in bytes, of the field. Note that this does not consider any padding required by the compiler for the field to maintain struct packing.

  • structRef -- If this field refers to another struct in any way, this argument should be a pointer to an instance of the Struct metadata class that describes the referenced struct.

  • enumRef -- If this field refers to another enum in any way, this argument should be a pointer to an instance of the Enum metadata class that describes the referenced enum.

  • lenField -- If this field refers to an array of objects (of any type), this argument contains a pointer to the Field that provides access to the number of elements in that array.

  • referencedType -- If this field refers to another object that is not a struct, this argument contains the BasicType of the referenced object (or a single element in an array of objects).

  • elementCount -- If this field refers to a constant-sized array (an array whose size is known at compile time, as opposed to provided at runtime via lenField), then this argument should contain that compile-time element count

Field(char const *name, char const *typeString, BasicType basicType, size_t offset, size_t size, Struct const *structRef, Enum const *enumRef, Union const *unionRef, Field const *lenField, BasicType referencedType)

Abbrieviated constructor for non-array fields.

This constructor is typically called when the field refers (points) to another value, such as a struct or primitive type instance. For example, in the following example, constructing a Field describing pInt would require referencedType be given a value of BasicType::kUInt32:

struct Foo {
    uint32_t* pInt;
};

See also

Field (Full constructor)

Field(char const *name, char const *typeString, BasicType basicType, size_t offset, size_t size, Struct const *structRef, Enum const *enumRef, Union const *unionRef, Field const *lenField, BasicType referencedType, std::function<size_t(uint64_t)> lengthFunction)
Field(char const *name, char const *typeString, BasicType basicType, size_t offset, size_t size, Struct const *structRef, Enum const *enumRef, Union const *unionRef, Field const *lenField)

Abbreviated constructor.

See also

Field (Full constructor)

~Field()
char const *Name() const

Field name accessor.

Returns

Name of field as declared in original API header

char const *TypeString() const

Type string accessor.

Returns

Field type declaration as declared in original API header

BasicType Type() const

Field BasicType accessor.

See also

GetBasicType()

Returns

BasicType of the field.

BasicType ReferencedType() const

Referenced data type accessor.

Returns

If the field refers to other data (for example, the field type is BasicType::kPointer), and that other data is not a known struct type, then this accessor will return the type of that referenced data. Otherwise, this accessor returns BasicType::kUndefined.

size_t Offset() const

Obtain the number of bytes between the beginning of the parent struct's storage, and the start of this field's storage.

Note

This offset takes into consideration struct packing by the compiler that compiled the GPA Framework. Therefore, this offset will be accurate for the compiler and compile flags used to build the GPA Framework.

Returns

Number of bytes from start of parent struct's storage and this field's storage.

size_t Size() const

Obtain the size of the field's storage, in bytes.

Note

This does not take into account struct packing by any compiler; it is calculated by a call to GetSize().

Returns

The number of bytes required to store this field's data.

size_t ElementCount() const

Obtain the number of elements in a constant-sized array.

Note

For non-constant-sized arrays (for example, arrays whose element count are known at runtime by value of another field in the struct), the element count can be obtained through LengthField().

Returns

If the field was declared as a constant-sized array, this accessor will return the number of elements in that array. Otherwise, this accessor returns zero.

Struct const *StructRef() const

Obtain the metadata for a referenced struct.

Returns

If this field refers to one or more instances of another struct (via pointer or embedded type), then this accessor will return a pointer to the metadata (Struct) for that structure. Otherwise, this accessor will return nullptr.

Enum const *EnumRef() const

Obtain the metadata for a referenced enum value.

Returns

If this field refers to one or more instances of an enum value (for example, an array of enum values), then this accessor will return a pointer to the metadata (Enum) for that enumeration. Otherwise, this accessor will return nullptr;

Union const *UnionRef() const

Obtain the metadata for a referenced union value.

Returns

If this field refers to one or more instances of a union value, then this accessor will return a pointer to the metadata (Union) for that union. Otherwise, this accessor will return nullptr;

Field const *LengthField() const

Obtain a pointer to another field in the parent struct that provides the number of elements in a runtime-sized array.

Returns

If this field refers to an array (as determined at GPA Framework compile time) whose length is provided in another field in the parent struct, this accessor returns a pointer to that field's metadata. Otherwise, this accessor returns nullptr.

std::function<size_t(uint64_t)> LengthFunction() const