Description

Stores type-casting functions between different type pairs, allowing to pick them at runtime from std::type_index or classname Converting pointers between different classes is usually possible by standard type casting, given that the source and destination class types are known at compile time. This class allows to typecast between class types that are known only at runtime. The requirement is that the typecasting function has to be prepared in advance (i.e. at compile time), when the types are still known. For each potential conversion an instance of ChCastingMap has to be declared, together with its typecasting function. This procedure is simplified by the macros CH_UPCASTING(FROM, TO) and CH_UPCASTING_SANITIZED(FROM, TO, UNIQUETAG) When the conversion should take place the following can be called: ConversionMap::Convert(std::string("source_classname"), std::string("destination_classname"), <void* to object>)

#include <ChClassFactory.h>

Public Member Functions

 ChCastingMap (const std::string &from, const std::type_index &from_ti, const std::string &to, const std::type_index &to_ti, std::function< void *(void *)> conv_ptr_fun, std::function< std::shared_ptr< void >(std::shared_ptr< void >)> conv_shptr_fun)
 

Static Public Member Functions

static void AddCastingFunction (const std::string &from, const std::type_index &from_ti, const std::string &to, const std::type_index &to_ti, std::function< void *(void *)> conv_ptr_fun, std::function< std::shared_ptr< void >(std::shared_ptr< void >)> conv_shptr_fun)
 
static void PrintCastingFunctions ()
 
static void * Convert (const std::string &from, const std::string &to, void *vptr)
 
static void * Convert (const std::type_index &from_it, const std::type_index &to_it, void *vptr)
 
static void * Convert (const std::string &from, const std::type_index &to_it, void *vptr)
 
static void * Convert (const std::type_index &from_it, const std::string &to, void *vptr)
 
static std::shared_ptr< void > Convert (const std::string &from, const std::string &to, std::shared_ptr< void > vptr)
 
static std::shared_ptr< void > Convert (const std::type_index &from_it, const std::type_index &to_it, std::shared_ptr< void > vptr)
 
static std::shared_ptr< void > Convert (const std::string &from, const std::type_index &to_it, std::shared_ptr< void > vptr)
 
static std::shared_ptr< void > Convert (const std::type_index &from_it, const std::string &to, std::shared_ptr< void > vptr)
 
static std::string GetClassnameFromPtrTypeindex (std::type_index typeindex)
 

The documentation for this class was generated from the following files:
  • /builds/uwsbel/chrono/src/chrono/core/ChClassFactory.h
  • /builds/uwsbel/chrono/src/chrono/core/ChClassFactory.cpp