Menu
Lumberyard
C++ API Reference (Version 1.10)

RTTI.h File Reference

Header file for AZ RTTI, which is a lightweight, user-defined run-time type information (RTTI) system with which you can determine the type of an object during run time. More...

Namespaces

 AZStd
 
 AZ
 

Macros

#define azdynamic_cast
 Use azrtti_cast, which is the same, instead. More...
 
#define azrtti_cast
 Casts a pointer from one polymorphic type to another. More...
 
#define azrtti_istypeof
 Returns true if the input type is of the specified type or derived from the specified type. More...
 
#define azrtti_typeid
 Returns the ID of the specified type. More...
 
#define AZ_RTTI(...)
 Adds run-time type information to a class. More...
 

Detailed Description

Header file for AZ RTTI, which is a lightweight, user-defined run-time type information (RTTI) system with which you can determine the type of an object during run time.

This information enables you to cast a pointer from one polymorphic type to another. The functionality is similar to C++ RTTI. Like C++ RTTI, AZ_RTTI works for polymorphic types only. Unlike C++ RTTI, you assign AZ_RTTI to your classes manually to minimize the memory footprint.

Macro Definition Documentation

◆ AZ_RTTI

#define AZ_RTTI (   ...)

Adds run-time type information to a class.

AZ_RTTI uses a virtual function, so be sure to have a virtual destructor. AZ_RTTI includes the functionality of AZ_TYPE_INFO, so you don't need to declare TypeInfo if you use AZ_RTTI.

Usage: AZ_RTTI(ClassName,ClassUuid,(BaseClass1..N))

  • ClassName is the name of the class to add run-time type information to.
  • ClassUuid is a unique ID to assign to the class.
  • BaseClass1..N are 0 to N base classes with which to perform dynamic casts and queries about types.

A more complex use case is to use templates. In that case, you must group the parameters for the TypeInfo call. Example:

AZ_RTTI((ClassName,ClassUuid, Template1, ...),BaseClass1...)

◆ azdynamic_cast

#define azdynamic_cast

Use azrtti_cast, which is the same, instead.

◆ azrtti_cast

#define azrtti_cast

Casts a pointer from one polymorphic type to another.

Only works for polymorphic types. The functionality is similar to C++ RTTI's dynamic_cast. azdynamic_cast is generally faster than dynamic_cast and offers a few extensions that are used by Lumberyard systems, such as serialization and scripting.

Usage: T azdynamic_cast<T,U>(U ptr)

  • T is the destination type.
  • U is the input type.
  • ptr is a pointer to the data to cast. Cannot be a void pointer.

◆ azrtti_istypeof

#define azrtti_istypeof

Returns true if the input type is of the specified type or derived from the specified type.

This operation is safe to call for a type that does not support AZ RTTI. In that case, it returns true only if the input type fully matches the specified type.

Usage 1: bool azrtti_istypeof<T,U>(U data)

  • T is the type to check against.
  • U is the input type.
  • data is an instance of the input type.

Usage 2: azrtti_istypeof<U>(const Uuid& id, U data)

  • U is the input type.
  • data is an instance of the input type.
  • id is the ID of the type to check against. To set the ID of a type, use AZ_RTTI.

◆ azrtti_typeid

#define azrtti_typeid

Returns the ID of the specified type.

Usage 1: const Uuid& azrtti_typeid<U>()

  • U is the name of the type to get the ID for.
  • Uuid is the type ID. To set the ID of a type, use AZ_RTTI.

Usage 2: const Uuid& azrtti_typeid<U>(const U& data)

  • U is the name of the type to get the ID for.
  • Uuid is the type ID. To set the ID of a type, use AZ_RTTI.
  • data is an instance of the input type.