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

fcf::ResolveData class

Type:
class fcf::ResolveData

Package: fcfBasis

File: bits/PartSpecificator/ResolveSpecificatorDefinition.hpp

Available from version: 1.0.1

The structure describing the information returned by the fcf::ResolveSpecificator specificator. Structure containing resolved data, its type index, and invariance information.

Detailed description

fcf::ResolveData is a data carrier used by the framework during runtime resolution operations (such as fcf::ResolveSpecificator). It encapsulates the raw pointer to the resolved data, the unique type index of that data, and a flag indicating whether the data is invariant.

Properties
void* data
- A pointer to the data stored in the object.
unsigned int typeIndex
- Integer value ​​of a type index.
bool invariant
- The flag indicating whether an object can store different types of data

Example:

#include <iostream> // Define the implementation macro to expand templates and registration mechanisms #define FCF_BASIS_IMPLEMENTATION #include <fcfBasis/basis.hpp> // 1. Define a custom type that we want to resolve struct Person { int age; }; // Register the type in the fcf system FCF_TYPEID_REGISTRY(Person, "Person", 0); // 2. Implement a specifier that returns fcf::ResolveData. // The fcf::ResolveSpecificator is designed to return a fcf::ResolveData structure // which tells the framework where the underlying data is and what its type is. namespace fcf { template<> struct Type<Person, ResolveSpecificator> : public TypeImpl<Person, ResolveSpecificator> { // The call for fcf::ResolveSpecificator must return a fcf::ResolveData object fcf::ResolveData call(Person* a_object) const { // We return a fcf::ResolveData structure: // - data: pointer to the actual integer value // - typeIndex: the registered index for 'int' // - invariant: false (This means that this object can store only one data type - int) return fcf::ResolveData{ (void*)&a_object->age, fcf::Type<int>().index(), false }; } }; } // 3. Bind the specifier implementation to our type FCF_SPECIFICATOR_REGISTRY(Person, fcf::ResolveSpecificator); int main() { // Create an instance of our custom type Person data{42}; std::cout << "=== [1] Manual fcf::ResolveData Simulation ===" << std::endl; { // 4. Retrieve the call function for the fcf::ResolveSpecificator // This function is what the framework uses to perform the resolution fcf::ResolveSpecificator::CallType resolveFunc = fcf::Type<Person>().specificatorCall<fcf::ResolveSpecificator>(0); if (resolveFunc) { // The result of the call is the ResolveData object fcf::ResolveData rd = resolveFunc(&data); std::cout << "Resolution successful!" << std::endl; std::cout << "Resolved Type Index: 0x" << std::hex << rd.typeIndex << std::dec << std::endl; std::cout << "Is Invariant: " << (rd.invariant ? "Yes" : "No") << std::endl; // Use the pointer from data to access the value int resolvedValue = *static_cast<int*>(rd.data); std::cout << "Resolved Value: " << resolvedValue << std::endl; } else { std::cout << "Specificator not found!" << std::endl; } } return 0; }

Output:

=== [1] Manual ResolveData Simulation === Resolution successful! Resolved Type Index: 0x5 Is Invariant: No Resolved Value: 42