FCF 2.0 development in progress...
> > > >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

fcf::Type class


Type:
template <typename Ty>
class fcf::Type

Package: fcfBasis

File: bits/PartType/TypeDefinition.hpp

Available from version: 1.0.1

A template class that provides access to metadata and runtime information for a specific type.

fcf::Type is a template class that acts as a gateway to the framework's type system. It allows you to retrieve a fcf::TypeInfo object, which contains essential runtime information such as the type's name, unique index, size, and registered specifiers or converters.

Template arguments
Ty - The type for which metadata is being retrieved.
Methods
fcf::TypeIndex index()
- Retrieves the unique runtime index of the type.
const std::string& name()
- Returns the human-readable name of the registered type.
size_t size()
- Returns the size of the type in bytes.
const fcf::TypeInfo* typeInfo()
- Retrieves a pointer to the metadata descriptor of the type.
const fcf::TypeInfo::SpecifiersType& specifiers()
- Retrieves the map of registered specifiers for the given type.
template <typename TSpecifier>
TSpecifier::CallType specifierCall()
template <typename TSpecifier>
TSpecifier::CallType specifierCall(fcf::Exception* a_dstError)
- Retrieves a typed function pointer for a specifier, providing high-performance direct access.
template <typename TSpecifier>
fcf::UniversalCall specifierUniversalCall()
template <typename TSpecifier>
fcf::UniversalCall specifierUniversalCall(fcf::Exception* a_dstError)
- Retrieves a universal function pointer for a specifier, enabling dynamic runtime dispatch.
const fcf::TypeInfo::ConvertersType& converters()
- Retrieves the map of registered converters for the given type.
const fcf::TypeInfo::ConvertersType& backConverters()
- Retrieves the map of registered back-converters for the given type.

Example:

#include <iostream> #include <string> // We declare the FCF_BASIS_IMPLEMENTATION macro, so the header // files will include the implementation and type registration blocks. // This macro should only be declared in one .cpp file. // For this example, it is declared in the main file, but in final implementations // it is better to move it to a separate .cpp file to avoid // rebuilding the framework each time. #define FCF_BASIS_IMPLEMENTATION #include <fcfBasis/basis.hpp> // Custom data type struct MyCustomType { int id; }; // Registering the custom type in the fcf system FCF_TYPE_REGISTRATION(MyCustomType, // Data type "MyCustomType", // String representation of the data type name 0 // Data type index. Specify 0, then the framework will automatically set the type index value. ); int main() { // 1. Accessing metadata for a built-in pointer type // We use fcf::Type<T> to get a description for std::string* std::cout << "=== [1] Built-in Pointer Type ===" << std::endl; std::cout << "Type index: 0x" << std::hex << fcf::Type<std::string*>().index() << std::dec << std::endl; std::cout << "Type name: " << fcf::Type<std::string*>().name() << std::endl; std::cout << "Type size: " << fcf::Type<std::string*>().size() << " bytes" << std::endl; // 2. Accessing metadata for a custom registered type std::cout << "\n=== [2] Custom Registered Type ===" << std::endl; std::cout << "Type index: 0x" << std::hex << fcf::Type<MyCustomType>().index() << std::dec << std::endl; std::cout << "Type name: " << fcf::Type<MyCustomType>().name() << std::endl; std::cout << "Type size: " << fcf::Type<MyCustomType>().size() << " bytes" << std::endl; return 0; }

Output:

=== [1] Built-in Pointer Type === Type index: 0x1000001e Type name: std::string* Type size: 8 bytes === [2] Custom Registered Type === Type index: 0x1000015 Type name: MyCustomType Type size: 4 bytes