FCF_TYPE_REGISTRATION_FORCE
(TYPE a_type, const char* a_typeName, unsigned int a_typeIndex)
Package: fcfBasis
File: macro.hpp
Available from version: 1.0.1
Forces registration of a type in the fcf type system, ensuring it is added to the global registry regardless of the implementation macro state.
This macro is used to explicitly register a type in the fcf type system. It is designed to guarantee that the type is added to the global registry, making it visible to the framework's runtime components.
Unlike the standard FCF_TYPE_REGISTRATION macro, FCF_TYPE_REGISTRATION_FORCE performs the registration unconditionally. It does not depend on whether the FCF_BASIS_IMPLEMENTATION macro is defined in the current translation unit.
This is particularly useful in complex build systems, plugin architectures, or when the type registration logic is located in a separate library or module where the implementation macro might not be present.
When you use this macro, the framework:
- Creates a fcf::TypeInfo object containing the type's name and metadata.
- Stores this information in the global registry.
- 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&, etc.).
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: Forced type registration without implementation macro
This example demonstrates how to register a type even when the implementation macro is not present in the current translation unit.
#include <iostream>
// Note: We are NOT defining FCF_IMPLEMENTATION here.
#include <fcfBasis/basis.hpp>
// 1. Define a custom structure for demonstration
struct MySpecialType {
int id;
};
// 2. We forcefully 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_FORCE(MySpecialType, "MySpecialType", 0);
int main() {
// 3. Access the metadata for the registered type using fcf::Type
fcf::Type<MySpecialType> 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;
}
impl.cpp file:
// Define an implementation macro to include the implementation section in header files.
#define FCF_BASIS_IMPLEMENTATION
#include <fcfBasis/basis.hpp>
CMakeLists.txt file:
add_executable(app main.cpp impl.cpp)
target_include_directories(app PRIVATE ../../..)
Output:
=== Registered Type Info ===
Type Name: MySpecialType
Type Index: 0x1000001
Type Size: 4 bytes