FCF_SPECIFIER_REGISTRATION macro
Package: fcfBasis
File: macro.hpp
Available from version: 1.0.1
Binds a specifier implementation to a registered type, enabling runtime operations for that type.
This macro is used to link a specifier (such as
Registration is performed only if the
Without this registration, the framework will not know how to perform the requested operation on the given type, and attempting to use the specifier will result in a
When you use this macro, the framework:
- Retrieves the
fcf::TypeInfo for the specified type. - Finds the specialized implementation of the specifier (usually defined via a
fcf::Type template specialization). - Stores a pointer to the universal call function and specialized call function in the type's specifier map.
Arguments
- The C++ type to which the specifier will be bound.
- The specifier type (e.g., fcf::LessSpecifier ) that you are registering for this type.
Example: Binding a specifier to a custom type
#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 Person {
int age;
std::string name;
};
// 2. Register the type in the fcf system
FCF_TYPE_REGISTRATION (Person, "Person", 0);
// 3. Implement the specifier logic (LessSpecifier)
// We specialize the fcf::Type template for the specific Person/LessSpecifier combination.
namespace fcf {
template<> struct Type <Person, LessSpecifier > : public TypeImpl <Person, LessSpecifier > {
inline bool operator()(const Person* a_left, const Person* a_right) {
// Logic: compare people by age
return a_left->age < a_right->age;
}
};
}
// 4. Bind the specifier to the type using the macro
// This step is crucial: it tells the framework that Person supports LessSpecifier.
FCF_SPECIFIER_REGISTRATION (Person, fcf::LessSpecifier );
int main() {
// 5. Create instances of the type
Person p1{25, "Alice"};
Person p2{30, "Bob"};
// 6. Wrap the objects in fcf::Variant
// Variant uses the registered specifier for runtime operations.
fcf::Variant v1(p1);
fcf::Variant v2(p2);
// 7. Perform comparison using the standard '<' operator
// The framework will internally find and call our LessSpecifier implementation.
if (v1 < v2) {
std::cout << "Alice is younger than Bob" << std::endl;
} else {
std::cout << "Alice is not younger than Bob" << std::endl;
}
return 0;
}
Output:
Alice is younger than Bob
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.