qxLib
names.h
Go to the documentation of this file.
1 /**
2 
3  @file names.h
4  @author Khrapov
5  @date 24.07.2025
6  @copyright © Nick Khrapov, 2025. All right reserved.
7 
8 **/
9 #pragma once
10 
11 #include <qx/macros/common.h>
12 
13 /**
14  @def QX_STRINGIFY
15  @brief Macro can be used to turn any text in your code into a string,
16  but only the exact text between the parentheses
17  There are no variable dereferencing or macro substitutions or any other sort of thing done.
18  @param name - name to convert to the string
19 **/
20 #define QX_STRINGIFY(name) #name
21 
22 /**
23  @def QX_LINE_NAME
24  @brief Do magic! Creates a unique name using the line number
25  @param prefix - name prefix
26 **/
27 #define QX_LINE_NAME(prefix) _QX_JOIN(prefix, __LINE__)
28 
29 /**
30  @brief A helper to avoid duplication when converting c libs constants to string literals
31  @param name - c constant
32  @code
33  static const char* GlfwErrorCodeToString(int nErrorCode)
34  {
35  switch (nErrorCode)
36  {
37  QX_C_CONSTANT_CASE(GLFW_NO_ERROR);
38  QX_C_CONSTANT_CASE(GLFW_NOT_INITIALIZED);
39  QX_C_CONSTANT_CASE(GLFW_NO_CURRENT_CONTEXT);
40  QX_C_CONSTANT_CASE(GLFW_INVALID_ENUM);
41  QX_C_CONSTANT_CASE(GLFW_INVALID_VALUE);
42  QX_C_CONSTANT_CASE(GLFW_OUT_OF_MEMORY);
43  QX_C_CONSTANT_CASE(GLFW_API_UNAVAILABLE);
44  QX_C_CONSTANT_CASE(GLFW_VERSION_UNAVAILABLE);
45  QX_C_CONSTANT_CASE(GLFW_PLATFORM_ERROR);
46  QX_C_CONSTANT_CASE(GLFW_FORMAT_UNAVAILABLE);
47  QX_C_CONSTANT_CASE(GLFW_NO_WINDOW_CONTEXT);
48  }
49 
50  return "GLFW_UNKNOWN_ERROR";
51  }
52  @endcode
53 **/
54 #define QX_C_CONSTANT_CASE(name) \
55  case name: \
56  return #name
57 
58 /**
59  @brief Get a method name (without className::), while statically verifying that the method exists
60  @param className - class name
61  @param methodName - method name
62 **/
63 #define QX_METHOD_NAME(className, methodName) \
64  ((void)sizeof(&className::methodName), QX_STRINGIFY(methodName)))
65 
66 /**
67  @brief Get a full method name (className::methodName), while statically verifying that the method exists
68  @param className - class name
69  @param methodName - method name
70 **/
71 #define QX_FULL_METHOD_NAME(className, methodName) \
72  ((void)sizeof(&className::methodName), QX_STRINGIFY(className) "::" QX_STRINGIFY(methodName))