Skip to content

coded_index

Raymond Chen edited this page Apr 3, 2019 · 8 revisions

A xmr::coded_index<T> represents a row in a database table, where the table is not known until run time, but it is one of a fixed set of possibilities.

A coded_index is used when the value could be one of various things. For example, a coded_index<TypeDefOrRef> represents a row in the TypeDef table, a row in the TypeRef table, a row in the TypeSpec table, or nothing at all. (The type should be more accurately named TypeDefRefOrSpec, but it's too late to fix it now.)

In the ECMA-335 file format, a coded index is represented as a row number and a type code packed together. A selected number of low-order bits encode the type code, and the remaining bits encode the row. The row number is incremented before being combined with the type code, to ensure that a valid entry always has a nonzero value.

(The incrementing of the row number by 1 is not mentioned in the ECMA-335 file format specification, section II.24.2.6 "If e is a coded index...", but the incrementing appears to be done in practice.)

Internally, a coded_index<T> derives from typed_index<T>, which in turn derives from index_base<T>.

Members

operator bool

operator bool() const noexcept;

Returns true if the coded_index (really, the index_base) is not "nothing".

If the boolean conversion operator returns false, then the only other method you can call is get_database().

Performance: O(1). Very fast.

type

T type() const noexcept;

Returns the enumeration value that indicates which table the coded index refers to.

Performance: O(1). Fast.

type

T index() const noexcept;

Returns the (zero-based) row index in the destination table.

Performance: O(1). Fast.

get_row

template<typename Row>
Row get_row() const;

Returns a reference to the index()th row of the Row table. The type() of the coded_index must match Row.

Performance: O(1).

get_database

xmr::database const& get_database() const noexcept;

Returns a reference to the database that contains this row.

Performance: O(1). Very fast.

operators

bool operator==(index_base<T> const& other) const noexcept;
bool operator!=(index_base<T> const& other) const noexcept;

Determine whether the current index_base<T> object refers to the same row and table as the other index_base<T> object.

bool operator<(index_base<T> const& other) const noexcept;

Imposes a total order on the index_base<T> objects.

The order is numeric by the encoded values, because that matches the sort order used by various tables. This is generally not something you need to worry about.

The presence of an < operator has the pleasant side effect of allowing the index_base to be used as a key in a std::map, std::set, or other data structure that requires a total order.

Specializations

Specializations of coded_index<T> typically provide helper methods to follow the coded index into the appropriate table. The helper method has the same name as the table, and it returns a row from that table.

For example, if coded_index<TypeDefOrRef>.type() returns TypeDefOrRef::TypeDef, then you can call the coded_index<TypeDefOrRef>.TypeDef() method, and it produces the TypeDef row that the coded index represents.

T If type() is... Then call coded_index<T> method... ... returns a...
TypeDefOrRef TypeDef TypeDef() TypeDef
TypeDefOrRef TypeRef TypeRef() TypeRef
TypeDefOrRef TypeSpec TypeSpec() TypeSpec
HasConstant Field Field() Field
HasConstant Param Param() Param
HasConstant Property Property() Property
CustomAttributeType MethodDef MethodDef() MethodDef
CustomAttributeType MethodRef MethodRef() MethodRef
HasSemantics Event Event() Event
HasSemantics Property Property() Property
MethodDefOrRef MethodDef MethodDef() MethodDef
MethodDefOrRef MethodRef MethodRef() MethodRef
ResolutionScope Module Module() Module
ResolutionScope ModuleRef ModuleRef() ModuleRef
ResolutionScope AssemblyRef AssemblyRef() AssemblyRef
ResolutionScope TypeRef TypeRef() TypeRef
MemberRefParent TypeDef TypeDef() TypeDef
MemberRefParent TypeRef TypeRef() TypeRef
MemberRefParent ModuleRef ModuleRef() ModuleRef
MemberRefParent MethodDef MethodDef() MethodDef
MemberRefParent TypeSpec TypeSpec() TypeSpec

Non-member operators

There are a number of overloads for the < operator to facilitate searching through sorted tables. They are not intended for general use.

Comparing... With... Compares the...
coded_index<HasCustomAttribute> CustomAttribute CustomAttribute::Parent()
coded_index<TypeOrMethodDef> GenericParam GenericParam::Owner()
coded_index<HasConstant> Constant Constant::Parent()
coded_index<HasSemantics> MethodSemantics MethodSemantics::Association()
Clone this wiki locally