fcf::Type class
Type:
template <typename Ty>
classfcf::Type
class
Package: fcfBasis
File: bits/PartType/TypeDefinition.hpp
Available from version: 1.0.1
A template class that provides access to metadata and runtime information for a specific type.
Detailed description
Template arguments
- The type for which metadata is being retrieved.
Example:
#include <iostream>
#include <string>
// We declare the FCF_BASIS_IMPLEMENTATION macro, so the header
// files will include the implementation and type registration blocks.
// This macro should only be declared in one .cpp file.
// For this example, it is declared in the main file, but in final implementations
// it is better to move it to a separate .cpp file to avoid
// rebuilding the framework each time.
#define FCF_BASIS_IMPLEMENTATION
#include <fcfBasis/basis.hpp>
// Custom data type
struct MyCustomType {
int id;
};
// Registering the custom type in the fcf system
FCF_TYPEID_REGISTRY (MyCustomType, // Data type
"MyCustomType", // String representation of the data type name
0 // Data type index. Specify 0, then the framework will automatically set the type index value.
);
int main() {
// 1. Accessing metadata for a built-in pointer type
// We use fcf::Type<T> to get a description for std::string*
std::cout << "=== [1] Built-in Pointer Type ===" << std::endl;
std::cout << "Type index: 0x" << std::hex << fcf::Type <std::string*>().index () << std::dec << std::endl;
std::cout << "Type name: " << fcf::Type <std::string*>().name () << std::endl;
std::cout << "Type size: " << fcf::Type <std::string*>().size () << " bytes" << std::endl;
// 2. Accessing metadata for a custom registered type
std::cout << "\n=== [2] Custom Registered Type ===" << std::endl;
std::cout << "Type index: 0x" << std::hex << fcf::Type <MyCustomType>().index () << std::dec << std::endl;
std::cout << "Type name: " << fcf::Type <MyCustomType>().name () << std::endl;
std::cout << "Type size: " << fcf::Type <MyCustomType>().size () << " bytes" << std::endl;
return 0;
}
Output:
=== [1] Built-in Pointer Type ===
Type index: 0x1000001e
Type name: std::string*
Type size: 8 bytes
=== [2] Custom Registered Type ===
Type index: 0x1000015
Type name: MyCustomType
Type size: 4 bytes
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.