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.

Detailed description

Template arguments
Ty
- The type for which metadata is being retrieved.

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 specificators or converters.

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_TYPEID_REGISTRY(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