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

specifierCall() method from fcf::Type class

template <typename TSpecifier>
TSpecifier::CallType specifierCall()
template <typename TSpecifier>
TSpecifier::CallType specifierCall(fcf::Exception* a_dstError)

Class: fcf::Type

Package: fcfBasis

File: bits/PartType/TypeDefinition.hpp

Available from version: 1.0.1

Retrieves a typed function pointer for a specifier, providing high-performance direct access.

The method returns a pointer of type TSpecifier::CallType. This is a specialized, typed function pointer that allows for direct execution of the specifier's logic without the overhead of the universal calling mechanism.

If no specifier handler function is defined for the specified specifier, calling the fcf::Type::specifierCall method without parameters will throw a fcf::SpecifierNotFoundException exception.

If the function instance is called with the a_dstError parameter accepting a pointer to an error object, then no exception will be thrown and the function will return 0 if there is no handler specifier.

Note that fcf::SpecifierInfo::call (fcf::Type::specifierCall) is only filled if the specified specifier has a declared type of TSpecifier::CallType.

Template arguments
TSpecifier - The type of the specifier (e.g., fcf::LessSpecifier, fcf::AddSpecifier).
Arguments

fcf::Exception* a_dstError
- The argument is a pointer to the object of fcf::Exception, whose fields will be filled in case of error. This argument may be zero.
Result
TSpecifier::CallType
- A specialized pointer to a specifier handler function. If called with the a_dstError argument, the function returns 0 on error.
Thrown exceptions
fcf::SpecifierNotFoundException - Thrown if the specified TSpecifier has not been registered for this type via FCF_SPECIFIER_REGISTRATION.

Example: High-performance direct call using typed pointer

#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 FCF_TYPE_REGISTRATION(MyCustomStruct, "MyCustomStruct", 0); // 3. Implement the comparison logic (LessSpecifier) namespace fcf { template<> struct Type<MyCustomStruct, LessSpecifier> : public TypeImpl<MyCustomStruct, LessSpecifier> { inline bool operator()(const MyCustomStruct* a_left, const MyCustomStruct* a_right) { return a_left->id < a_right->id; } }; } // 4. Bind the specifier to the type FCF_SPECIFIER_REGISTRATION(MyCustomStruct, fcf::LessSpecifier); int main() { // 5. Create instances of the type MyCustomStruct obj1{10, "Alice"}; MyCustomStruct obj2{20, "Bob"}; // 6. Get the typed function pointer for LessSpecifier // This is faster than UniversalCall because it uses the exact function signature fcf::LessSpecifier::CallType lessFunc = fcf::Type<MyCustomStruct>().specifierCall<fcf::LessSpecifier>(); if (lessFunc) { // 7. Execute the call directly with typed arguments // No Variant wrapping or universal dispatching is required here bool result = lessFunc(&obj1, &obj2); if (result) { std::cout << "Direct comparison result: obj1 < obj2 is TRUE" << std::endl; } else { std::cout << "Direct comparison result: obj1 < obj2 is FALSE" << std::endl; } } else { std::cout << "Specifier not found!" << std::endl; } return 0; }

Output:

Direct comparison result: obj1 < obj2 is TRUE