tango.core.RuntimeTraits

Provides runtime traits, which provide much of the functionality of tango.core.Traits and is-expressions, as well as some functionality that is only available at runtime, using runtime type information.

Authors:

Chris Wright (dhasenan) <dhasenan@gmail.com>

License:

Tango License, Apache 2.0
const(TypeInfo) realType(const(TypeInfo) type)
If the given type represents a typedef, return the actual type.
const(ClassInfo) asClass(const(TypeInfo) type)
If the given type represents a class, return its ClassInfo; else return null;
bool isDerived(const(ClassInfo) derived, const(ClassInfo) base)
Returns true iff one type is an ancestor of the other, or if the types are the same. If either is null, returns false.
bool implements(const(ClassInfo) implementor, const(ClassInfo) iface)
Returns true iff implementor implements the interface described by iface. This is an expensive operation (linear in the number of interfaces and base classes).
bool isImplicitly(const(ClassInfo) test, const(ClassInfo) target)
Returns true iff an instance of class test is implicitly castable to target. This is an expensive operation (isDerived + implements).
bool isImplicitly(const(TypeInfo) test, const(TypeInfo) target)
Returns true iff an instance of type test is implicitly castable to target. If the types describe classes or interfaces, this is an expensive operation.
const(ClassInfo)[] baseClasses(const(ClassInfo) type)
const(ClassInfo)[] baseInterfaces(const(ClassInfo) type)
Returns a list of all interfaces that this type implements, directly or indirectly. This includes base interfaces of types the class implements, and interfaces that base classes implement, and base interfaces of interfaces that base classes implement. This is an expensive operation.
const(ClassInfo)[] interfaceGraph(const(ClassInfo) type)
Returns all the interfaces that this type directly implements, including inherited interfaces. This is an expensive operation.

Examples:

1
2
3
4
5
6
interface I1 {}
interface I2 : I1 {}
class A : I2 {}

auto interfaces = interfaceGraph (A.classinfo);
// interfaces = [I1.classinfo, I2.classinfo]
1
2
3
4
5
6
7
interface I1 {}
interface I2 {}
class A : I1 {}
class B : A, I2 {}

auto interfaces = interfaceGraph (B.classinfo);
// interfaces = [I2.classinfo]
struct applyInterfaces
Iterate through all interfaces that type implements, directly or indirectly, including base interfaces.
this(const(ClassInfo) type)
int opApply(scope int delegate(ref ClassInfo) dg)
const(ClassInfo)[] baseTypes(const(ClassInfo) type)
ModuleInfo* moduleOf(const(ClassInfo) type)
const(ClassInfo)[] directInterfaces(const(ClassInfo) type)
Returns a list of interfaces that this class directly implements.
const(ClassInfo)[] derivedTypes(const(ClassInfo) type)
Returns a list of all types that are derived from the given type. This does not count interfaces; that is, if type is an interface, you will only get derived interfaces back. It is an expensive operations.
bool isDynamicArray(const(TypeInfo) type)
bool isStaticArray(const(TypeInfo) type)
bool isArray(const(TypeInfo) type)
Returns true iff the given type is a dynamic or static array (false for associative arrays and non-arrays).
bool isAssociativeArray(const(TypeInfo) type)
bool isCharacter(const(TypeInfo) type)
bool isString(const(TypeInfo) type)
bool isUnsignedInteger(const(TypeInfo) type)
bool isSignedInteger(const(TypeInfo) type)
bool isInteger(const(TypeInfo) type)
bool isBool(const(TypeInfo) type)
bool isFloat(const(TypeInfo) type)
bool isPrimitive(const(TypeInfo) type)
bool isInterface(const(TypeInfo) type)
Returns true iff the given type represents an interface.
bool isPointer(const(TypeInfo) type)
bool isClass(const(TypeInfo) type)
Returns true iff the type represents a class (false for interfaces).
bool isStruct(const(TypeInfo) type)
bool isFunction(const(TypeInfo) type)
bool isReferenceType(const(TypeInfo) type)
Returns true iff the given type is a reference type.
bool isUserDefined(const(TypeInfo) type)
Returns true iff the given type represents a user-defined type. This does not include functions, delegates, aliases, or typedefs.
bool isValueType(const(TypeInfo) type)
Returns true for all value types, false for all reference types. For functions and delegates, returns false (is this the way it should be?).
const(TypeInfo) keyType(const(TypeInfo) type)
The key type of the given type. For an array, size_t; for an associative array T[U], U.
const(TypeInfo) valueType(const(TypeInfo) type)
The value type of the given type -- given T[] or T[n], T; given T[U], T; given T*, T; anything else, null.
const(TypeInfo) returnType(const(TypeInfo) type)
If the given type represents a delegate or function, the return type of that function. Otherwise, null.