NAP
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
nap::rtti Namespace Reference

Namespaces

 instanceproperty
 
 method
 

Classes

class  BinaryWriter
 
class  DefaultLinkResolver
 
struct  DeserializeResult
 
class  Factory
 
struct  FileLink
 
class  IObjectCreator
 
class  JSONWriter
 
class  LinkResolver
 
class  Object
 
class  ObjectCreator
 
struct  ObjectLink
 
class  ObjectPtr
 
class  ObjectPtrBase
 
class  ObjectPtrManager
 
class  Path
 
class  PathElement
 
struct  ReadState
 
class  ResolvedPath
 
class  ResolvedRTTIPathElement
 
struct  UnresolvedPointer
 
class  Writer
 

Typedefs

using OwnedObjectList = std::vector< std::unique_ptr< rtti::Object > >
 
using ObservedObjectList = std::vector< rtti::Object * >
 
using ObjectList = std::vector< Object * >
 
using ObjectSet = std::unordered_set< Object * >
 
using TypeInfo = rttr::type
 
using Enum = rttr::enumeration
 
using Property = rttr::property
 
using Variant = rttr::variant
 
using Instance = rttr::instance
 
using VariantArray = rttr::variant_array_view
 
using VariantMap = rttr::variant_associative_view
 
using UnresolvedPointerList = std::vector< UnresolvedPointer >
 

Enumerations

enum  EPropertyValidationMode : uint8_t { DisallowMissingProperties, AllowMissingProperties }
 
enum  EPointerPropertyMode : uint8_t { NoRawPointers, OnlyRawPointers, AllPointerTypes }
 
enum  EPropertyMetaData : uint8_t {
  Default = 0, Required = 1, FileLink = 2, Embedded = 4,
  ReadOnly = 8
}
 
enum  EPropertyFileType : uint8_t {
  Any = 0, Image = 1, FragShader = 2, VertShader = 3,
  ComputeShader = 4, Python = 5, Mesh = 6, Video = 7,
  ImageSequence = 8, Audio = 9, Font = 10
}
 
enum  ETypeCheck : uint8_t { EXACT_MATCH, IS_DERIVED_FROM }
 

Functions

bool NAPAPI checkBinaryVersion (const std::string &path)
 
bool NAPAPI deserializeBinary (utility::MemoryStream &stream, Factory &factory, DeserializeResult &result, utility::ErrorState &errorState)
 
bool NAPAPI readBinary (const std::string &path, Factory &factory, DeserializeResult &result, utility::ErrorState &errorState)
 
bool NAPAPI deserializeJSON (const std::string &json, EPropertyValidationMode propertyValidationMode, EPointerPropertyMode pointerPropertyMode, Factory &factory, DeserializeResult &result, utility::ErrorState &errorState)
 
bool NAPAPI deserializeJSONFile (const std::string &path, EPropertyValidationMode propertyValidationMode, EPointerPropertyMode pointerPropertyMode, Factory &factory, DeserializeResult &result, utility::ErrorState &errorState)
 
bool NAPAPI deserializeObjects (const rapidjson::Value &jsonArray, EPropertyValidationMode propertyValidationMode, EPointerPropertyMode pointerPropertyMode, Factory &factory, DeserializeResult &result, utility::ErrorState &errorState)
 
std::unique_ptr< nap::rtti::Object > NAPAPI getObjectFromJSONFile (const std::string &path, EPropertyValidationMode propertyValidationMode, Factory &factory, utility::ErrorState &errorState)
 
bool NAPAPI JSONDocumentFromString (const std::string &json, rapidjson::Document &document, nap::utility::ErrorState &errorState)
 
void NAPAPI copyObject (const rtti::Object &srcObject, rtti::Object &dstObject)
 
template<typename T >
std::unique_ptr< T > cloneObject (const T &object, rtti::Factory &factory)
 
bool NAPAPI areObjectsEqual (const rtti::Object &objectA, const rtti::Object &objectB, const rtti::UnresolvedPointerList &unresolvedPointers=UnresolvedPointerList())
 
void NAPAPI findFileLinks (const rtti::Object &object, std::vector< std::string > &fileLinks)
 
void NAPAPI findObjectLinks (const rtti::Object &object, std::vector< ObjectLink > &objectLinks)
 
int NAPAPI findUnresolvedPointer (const UnresolvedPointerList &unresolvedPointers, const Object *object, const rtti::Path &path)
 
void NAPAPI getPointeesRecursive (const rtti::Object &object, std::vector< rtti::Object * > &pointees)
 
uint64_t NAPAPI getRTTIVersion (const rtti::TypeInfo &type)
 
void NAPAPI getDerivedTypesRecursive (const rtti::TypeInfo &baseType, std::vector< rtti::TypeInfo > &types)
 
bool NAPAPI hasDescription (const rtti::Property &property)
 
const NAPAPI char * getDescription (const rtti::Property &property)
 
bool NAPAPI hasDescription (const rtti::TypeInfo &type)
 
const NAPAPI char * getDescription (const rtti::TypeInfo &type)
 
EPropertyMetaData operator& (EPropertyMetaData a, EPropertyMetaData b)
 
EPropertyMetaData operator| (EPropertyMetaData a, EPropertyMetaData b)
 
bool isPrimitive (const rtti::TypeInfo &type)
 
bool hasFlag (const rtti::Property &property, EPropertyMetaData flags)
 
bool isFileType (const rtti::Property &property, EPropertyFileType filetype)
 
bool isTypeMatch (const rtti::TypeInfo &typeA, const rtti::TypeInfo &typeB, ETypeCheck typeCheck)
 
rttr::method findMethodRecursive (const rtti::TypeInfo &type, const std::string &methodName)
 
bool NAPAPI serializeObjects (const ObjectList &rootObjects, Writer &writer, utility::ErrorState &errorState)
 
bool NAPAPI serializeObject (rtti::Object &object, Writer &writer, utility::ErrorState &errorState)
 

Variables

constexpr const char * sIDPropertyName = "mID"
 
constexpr char gRTTIBinaryVersion [] = "RTTIBinary-1.1"
 

Typedef Documentation

◆ Enum

using Enum = rttr::enumeration

◆ Instance

using Instance = rttr::instance

◆ ObjectList

using ObjectList = std::vector<Object*>

◆ ObjectSet

using ObjectSet = std::unordered_set<Object*>

◆ ObservedObjectList

using ObservedObjectList = std::vector<rtti::Object*>

◆ OwnedObjectList

using OwnedObjectList = std::vector<std::unique_ptr<rtti::Object> >

◆ Property

using Property = rttr::property

◆ TypeInfo

using TypeInfo = rttr::type

◆ UnresolvedPointerList

◆ Variant

using Variant = rttr::variant

◆ VariantArray

using VariantArray = rttr::variant_array_view

◆ VariantMap

using VariantMap = rttr::variant_associative_view

Enumeration Type Documentation

◆ EPointerPropertyMode

enum EPointerPropertyMode : uint8_t
strong

The deserializer can operate in two modes: using only raw pointers or without any raw pointers at all. The main distinction between the two modes lie in hotloading: in the normal flow of operation, all objects are managed by ResourceManager and internally by ObjectPtrManager. These classes enable the hotloading of objects and they do so by patching internal pointers in non-raw pointers like ObjectPtr, ResourcePtr, ComponentPtr. In such situations, raw pointers are not allowed. However, ObjectPtr and alike are not thread-safe and they should only be used from the main thread. In cases where objects are deserialized directly without the use of ResourceManager, you can use raw pointers instead of ObjectPtr and alike. By enabling OnlyRawPointers or NoRawPointers, the deserializer verifies the correct use of all pointers throughout deserialization.

Enumerator
NoRawPointers 

Raw pointers cannot be used to point to other object, only ObjectPtr, ResourcePtr or ComponentPtr, otherwise an error will be returned.

OnlyRawPointers 

Only raw pointers can be used to point to other objects, an error will be returned in case of other pointer types.

AllPointerTypes 

All types of pointers are supported; no checking is done on raw or non-raw.

◆ EPropertyFileType

enum EPropertyFileType : uint8_t
strong

If EPropertyMetaData::FileLink is set, you can provide a file type. Used for tooling.

Enumerator
Any 

Can point to any file, default.

Image 

Points to an image file, must be used with EPropertyMetaData::FileLink.

FragShader 

Points to a .vert file, must be used with EPropertyMetaData::FileLink.

VertShader 

Points to a .frag file, must be used with EPropertyMetaData::FileLink.

ComputeShader 

Points to a .comp file, must be used with EPropertyMetaData::FileLink.

Python 

Points to a .py file, must be used with EPropertyMetaData::FileLink.

Mesh 

Points to a .mesh file, must be used with EPropertyMetaData::FileLink.

Video 

Points to a video file, must be used with EPropertyMetaData::FileLink.

ImageSequence 

Points to a an image sequence, must be used with EPropertyMetaData::FileLink.

Audio 

Points to an audio file, must be used with EPropertyMetaData::FileLink.

Font 

Points to a true type font, must be used with EPropertyMetaData::FileLink.

◆ EPropertyMetaData

enum EPropertyMetaData : uint8_t
strong

Controls how an RTTI property is interpreted

Enumerator
Default 

Uses the (class) default if the property isn't set.

Required 

Load will fail if the property isn't set.

FileLink 

Defines a relationship with an external file.

Embedded 

An embedded pointer.

ReadOnly 

A read only property in Python.

◆ EPropertyValidationMode

enum EPropertyValidationMode : uint8_t
strong
Enumerator
DisallowMissingProperties 

When a required property is missing from the file, an error will be returned.

AllowMissingProperties 

When a required property is missing from the file, no errors will be returned.

◆ ETypeCheck

enum ETypeCheck : uint8_t
strong

Selects whether the type check should be an exact type match or whether the type should be derived from the given type.

Enumerator
EXACT_MATCH 

The type needs to be of the exact same kind.

IS_DERIVED_FROM 

The type is derived from the specified type.

Function Documentation

◆ areObjectsEqual()

bool NAPAPI nap::rtti::areObjectsEqual ( const rtti::Object objectA,
const rtti::Object objectB,
const rtti::UnresolvedPointerList unresolvedPointers = UnresolvedPointerList() 
)

Tests whether the attributes of two objects have the same values.

Parameters
objectAfirst object to compare attributes from.
objectBsecond object to compare attributes from.
unresolvedPointerslist of unresolved pointers that should be used for pointer comparisons in case of unresolved pointers.

◆ checkBinaryVersion()

bool NAPAPI nap::rtti::checkBinaryVersion ( const std::string &  path)

Check whether the binary file at the specified path matches the current binary version (i.e. is up-to-date)

Parameters
pathpath to the binary file.
Returns
true if the binary versions of the types in the file are up-to-date, false if not.

◆ cloneObject()

std::unique_ptr<T> nap::rtti::cloneObject ( const T &  object,
rtti::Factory factory 
)

Creates a new object with the same attributes as it's source.

Parameters
objectthe object to copy rtti attributes from.
factoryRTTI object factory.
Returns
the cloned object

◆ copyObject()

void NAPAPI nap::rtti::copyObject ( const rtti::Object srcObject,
rtti::Object dstObject 
)

Copies rtti attributes from one object to another.

Parameters
srcObjectthe object to copy attributes from
dstObjectthe target object

◆ deserializeBinary()

bool NAPAPI nap::rtti::deserializeBinary ( utility::MemoryStream stream,
Factory factory,
DeserializeResult result,
utility::ErrorState errorState 
)

Deserialize a set of objects and their data from the specified stream

Parameters
streamthe stream to deserialize from
factorythe RTTI object factory.
resultThe result of the deserialization process
errorStatecontains the error if deserialization fails.
Returns
true if deserialization succeeded, false if not. In case of failure, errorState contains detailed error info.

◆ deserializeJSON()

bool NAPAPI nap::rtti::deserializeJSON ( const std::string &  json,
EPropertyValidationMode  propertyValidationMode,
EPointerPropertyMode  pointerPropertyMode,
Factory factory,
DeserializeResult result,
utility::ErrorState errorState 
)

Deserialize a set of objects and their data from the specified JSON string

Parameters
jsonThe JSON string to deserialize
propertyValidationModewhether missing required properties should be treated as errors
pointerPropertyModecontrols ownership of the created objects. Use 'NoRawPointers' in process and 'OnlyRawPointers' out of process.
factoryRTTI object factory.
resultthe result of the deserialization operation
errorStatecontains the error when de-serialization fails.
Returns
true if deserialization succeeded, false if not. In case of failure the errorState contains detailed error info.

◆ deserializeJSONFile()

bool NAPAPI nap::rtti::deserializeJSONFile ( const std::string &  path,
EPropertyValidationMode  propertyValidationMode,
EPointerPropertyMode  pointerPropertyMode,
Factory factory,
DeserializeResult result,
utility::ErrorState errorState 
)

Read and deserialize a set of objects and their data from the specified JSON file

Parameters
pathThe JSON file to deserialize
propertyValidationModeWhether missing required properties should be treated as errors
pointerPropertyModecontrols ownership of the created objects. Use 'NoRawPointers' in process and 'OnlyRawPointers' out of process.
factoryRTTI object factory.
resultThe result of the deserialization operation
errorStatecontains the error when deserialization fails.
Returns
true if deserialization succeeded, false if not. In case of failure the errorState contains detailed error info.

◆ deserializeObjects()

bool NAPAPI nap::rtti::deserializeObjects ( const rapidjson::Value &  jsonArray,
EPropertyValidationMode  propertyValidationMode,
EPointerPropertyMode  pointerPropertyMode,
Factory factory,
DeserializeResult result,
utility::ErrorState errorState 
)

Deserialize a set of objects and their data from the specified JSON string

Parameters
jsonArrayThe JSON value to deserialize
propertyValidationModewhether missing required properties should be treated as errors
pointerPropertyModecontrols ownership of the created objects. Use 'NoRawPointers' in process and 'OnlyRawPointers' out of process.
factoryRTTI object factory.
resultthe result of the deserialization operation
errorStatecontains the error when de-serialization fails.
Returns
true if deserialization succeeded, false if not. In case of failure the errorState contains detailed error info.

◆ findFileLinks()

void NAPAPI nap::rtti::findFileLinks ( const rtti::Object object,
std::vector< std::string > &  fileLinks 
)

Searches through object's rtti attributes for attribute that have the 'file link' tag.

Parameters
objectobject to find file links from.
fileLinksoutput array containing the filenames.

◆ findMethodRecursive()

rttr::method nap::rtti::findMethodRecursive ( const rtti::TypeInfo type,
const std::string &  methodName 
)

Finds method recursively in class and its base classes. Note that if a function is defined twice the base class gets priority.

Note: this should normally work through the regular rttr::get_method function, but this does not seem to work properly. This function is used as a workaround until we solve the issue.

◆ findObjectLinks()

void NAPAPI nap::rtti::findObjectLinks ( const rtti::Object object,
std::vector< ObjectLink > &  objectLinks 
)

Searches through object's rtti attributes for pointer attributes.

Parameters
objectobject to find file links from.
objectLinksoutput array containing the object links

◆ findUnresolvedPointer()

int NAPAPI nap::rtti::findUnresolvedPointer ( const UnresolvedPointerList unresolvedPointers,
const Object object,
const rtti::Path path 
)

Helper to find the index of the unresolved pointer with the specified object and path combination

Parameters
unresolvedPointersThe list of UnresolvedPointers to search in
objectThe object that the UnresolvedPointer originates in
pathThe path to the attribute on the object that the UnresolvedPointer originates in
Returns
The index of the UnresolvedPointer in the specified list. -1 if not found.

◆ getDerivedTypesRecursive()

void NAPAPI nap::rtti::getDerivedTypesRecursive ( const rtti::TypeInfo baseType,
std::vector< rtti::TypeInfo > &  types 
)

Recursively get all types derived from the specified type (including the base type itself)

Parameters
baseTypeThe type to use as base
typesThe resulting array of types

◆ getDescription() [1/2]

const NAPAPI char* nap::rtti::getDescription ( const rtti::Property property)

Returns the description of a property.

Returns
property description, nullptr when not defined.

◆ getDescription() [2/2]

const NAPAPI char* nap::rtti::getDescription ( const rtti::TypeInfo type)

Returns the description of a type, including base types.

Returns
type description, nullptr when not defined.

◆ getObjectFromJSONFile()

std::unique_ptr<nap::rtti::Object> NAPAPI nap::rtti::getObjectFromJSONFile ( const std::string &  path,
EPropertyValidationMode  propertyValidationMode,
Factory factory,
utility::ErrorState errorState 
)

Read and deserialize the first rtti::object from a JSON file. Ownership is transferred.

Parameters
pathlocation of the JSON file on disk.
propertyValidationModeproperty validation mode
factoryRTTI object creation factory.
errorStatecontains the error if the operation fails.
Returns
de-serialized rtti::object

Read and deserialize the first rtti::object of type T from a JSON file. Ownership is transferred.

Parameters
pathlocation of the JSON file on disk.
propertyValidationModeproperty validation mode
factoryRTTI object creation factory.
errorStatecontains the error if the operation fails.
Returns
de-serialized rtti::object

◆ getPointeesRecursive()

void NAPAPI nap::rtti::getPointeesRecursive ( const rtti::Object object,
std::vector< rtti::Object * > &  pointees 
)

Recursively traverses pointers of the given object and puts them in pointees. Basically traverses the object graph beneath object.

Parameters
objectThe root object to start traversing pointers from.
pointeesThe resulting array of objects.

◆ getRTTIVersion()

uint64_t NAPAPI nap::rtti::getRTTIVersion ( const rtti::TypeInfo type)

Calculate the version number of the specified type

Parameters
typeThe type to calculate the version number for
Returns
The version number

◆ hasDescription() [1/2]

bool NAPAPI nap::rtti::hasDescription ( const rtti::Property property)

Checks if a description is provided for the given property.

Returns
if a description is provided for the given property.

◆ hasDescription() [2/2]

bool NAPAPI nap::rtti::hasDescription ( const rtti::TypeInfo type)

Checks if a description is provided for the given type, including base types. Note that if a description is defined for multiple types, the top-most (derived) description is returned.

Returns
if a description is provided for the given type.

◆ hasFlag()

bool nap::rtti::hasFlag ( const rtti::Property property,
EPropertyMetaData  flags 
)

Helper function to check whether a property has the specified flag set

◆ isFileType()

bool nap::rtti::isFileType ( const rtti::Property property,
EPropertyFileType  filetype 
)

Helper function to check whether a property is associated with a specific type of file

Returns
if the property is a specific type of file

◆ isPrimitive()

bool nap::rtti::isPrimitive ( const rtti::TypeInfo type)

Helper function to determine whether the specified type is a primitive type (i.e. int, float, string, etc)

◆ isTypeMatch()

bool nap::rtti::isTypeMatch ( const rtti::TypeInfo typeA,
const rtti::TypeInfo typeB,
ETypeCheck  typeCheck 
)

Helper function to check whether two types match, based on a comparison mode

◆ JSONDocumentFromString()

bool NAPAPI nap::rtti::JSONDocumentFromString ( const std::string &  json,
rapidjson::Document &  document,
nap::utility::ErrorState errorState 
)

Parse JSON text from a read-only string.

Parameters
jsonstring to parse
documentoutput document
errorStatecontains the error if string can't be parsed

◆ operator&()

EPropertyMetaData nap::rtti::operator& ( EPropertyMetaData  a,
EPropertyMetaData  b 
)

◆ operator|()

EPropertyMetaData nap::rtti::operator| ( EPropertyMetaData  a,
EPropertyMetaData  b 
)

◆ readBinary()

bool NAPAPI nap::rtti::readBinary ( const std::string &  path,
Factory factory,
DeserializeResult result,
utility::ErrorState errorState 
)

Deserialize a set of objects and their data from the specified file

Parameters
pathpath to file.
factorythe RTTI object factory.
resultThe result of the deserialization process.
errorStatecontains the error if deserialization fails.
Returns
true if deserialization succeeded, false if not. In case of failure, errorState contains detailed error info.

◆ serializeObject()

bool NAPAPI nap::rtti::serializeObject ( rtti::Object object,
Writer writer,
utility::ErrorState errorState 
)

Serialize a single RTTI object. This function performs all the logic, including traversal. The actual writing is done by the 'type of writer passed in. Object is placed in the root of the document and is NOT part of an 'Objects' array. Use this function to write a single RTTI object, instead of multiple. The object cannot point to other root objects, embedded pointers are allowed.

Parameters
objectthe object to write.
writerthe rtti writer
errorStatecontains the error if writing fails

◆ serializeObjects()

bool NAPAPI nap::rtti::serializeObjects ( const ObjectList rootObjects,
Writer writer,
utility::ErrorState errorState 
)

Serialize a set of objects using the given writer. This function performs all the logic, including traversal. The actual writing is done by the 'type of writer passed in. All objects are placed inside the 'Objects' array.

Parameters
rootObjectsthe objects to write.
writerthe rtti writer
errorStatecontains the error if writing fails

Variable Documentation

◆ gRTTIBinaryVersion

constexpr char gRTTIBinaryVersion[] = "RTTIBinary-1.1"
constexpr

◆ sIDPropertyName

constexpr const char* sIDPropertyName = "mID"
constexpr