FCF_TYPE_REGISTRATION
(TYPE a_type, const char* a_typeName, unsigned int a_typeIndex)
Package: fcfBasis
File: macro.hpp
Available from version: 1.0.1
Registers a custom type in the fcf type system, providing it with a unique index and metadata.
This macro is essential for making custom user-defined types visible to the fcf framework. Once a type is registered, it can be used within fcf::Variant, participate in dynamic function calls, and utilize the specifier system.
Initialization of type information is performed only if the FCF_BASIS_IMPLEMENTATION macro is declared. Without this macro, only the type information declaration is performed, and the information will be initialized the first time the fcf::Type object is accessed.
When you use this macro, the framework:
- Creates a fcf::TypeInfo object containing the type's name and metadata.
- Stores this information in global storage.
- If the provided typeIndex is 0, the framework automatically assigns a unique identifier.
- Performs this procedure separately for each subtype (a_type*, const a_type*, a_type&, const a_type&, ...)
Arguments
TYPE a_type
- The C++ type to be registered.
const char* a_typeName
- A human-readable string representing the name of the type.
unsigned int a_typeIndex
- The base index for the type. Use 0 to let the framework automatically assign a unique index.
Example: Registering a custom type with automatic indexing
#include <iostream>
#include <string>
// Define an implementation macro to include the implementation section in header files.
#define FCF_BASIS_IMPLEMENTATION
#include <fcfBasis/basis.hpp>
// 1. Define a custom structure for demonstration
struct MyCustomStruct {
int id;
std::string name;
};
// 2. Register the type in the fcf system.
// We pass 0 as the third argument so the framework automatically generates a unique index.
FCF_TYPE_REGISTRATION(MyCustomStruct, "MyCustomStruct", 0);
int main() {
// 3. Access the metadata for the registered type using fcf::Type
fcf::Type<MyCustomStruct> typeDescriptor;
// 4. Retrieve and print the type information
std::cout << "=== Registered Type Info ===" << std::endl;
std::cout << "Type Name: " << typeDescriptor.name() << std::endl;
std::cout << "Type Index: 0x" << std::hex << typeDescriptor.index() << std::dec << std::endl;
std::cout << "Type Size: " << typeDescriptor.size() << " bytes" << std::endl;
return 0;
}
Output:
=== Registered Type Info ===
Type Name: MyCustomStruct
Type Index: 0x1000015
Type Size: 40 bytes