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

FCF_SPECIFIER_REGISTRATION macro

FCF_SPECIFIER_REGISTRATION (TYPE a_type, TYPE a_specifier)

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 fcf::LessSpecifier, fcf::AddSpecifier, etc.) to a type that has already been registered via FCF_TYPE_REGISTRATION.

Registration is performed only if the FCF_BASIS_IMPLEMENTATION macro is declared.

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 fcf::SpecifierNotFoundException.

When you use this macro, the framework:

  1. Retrieves the fcf::TypeInfo for the specified type.
  2. Finds the specialized implementation of the specifier (usually defined via a fcf::Type template specialization).
  3. Stores a pointer to the universal call function and specialized call function in the type's specifier map.

Arguments

TYPE a_type
- The C++ type to which the specifier will be bound.

TYPE a_specifier
- 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