VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
name_detector.h File Reference

Compile-time type-name and enum-name detection utilities. More...

#include <string_view>
#include "../thirdparty/nameof.h"
Include dependency graph for name_detector.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

Functions

template<typename T>
constexpr bool vlink::NameDetector::is_support () noexcept
 Checks at compile time whether the nameof library can produce a type name for T.
template<typename T>
constexpr std::string_view vlink::NameDetector::get () noexcept
 Returns the unqualified compile-time name of type T as a std::string_view.
template<typename T>
std::string_view vlink::NameDetector::get_enum (T e) noexcept
 Returns the string representation of an enumeration value e.

Detailed Description

Compile-time type-name and enum-name detection utilities.

The vlink::NameDetector namespace wraps the third-party nameof library to provide a portable, constexpr API for obtaining the string representation of a type or an enumeration value at compile time.

These utilities are used by the VLink plugin system to automatically derive plugin identifiers from interface class names, avoiding error-prone manual string registration.

Platform notes:

  • On Windows (MSVC / MSYS2) the nameof library may prefix types with "struct " or "class ". NameDetector::get() strips these prefixes automatically to return only the unqualified type name.
  • On GCC/Clang the result of nameof::nameof_type<T>() is used directly.
Note
The get<T>() function returns a constexpr std::string_view that points into static storage generated by the compiler. The view is valid for the entire program lifetime.
Example
// Check support and get the type name:
constexpr std::string_view name = vlink::NameDetector::get<MyPlugin>();
// name == "MyPlugin"
}
// Get enum value name at runtime:
enum class Color { Red, Green, Blue };
std::string_view name = vlink::NameDetector::get_enum(Color::Green);
// name == "Green"