qxLib
common.h
Go to the documentation of this file.
1 /**
2 
3  @file common.h
4  @author Khrapov
5  @date 17.06.2019
6  @copyright © Nick Khrapov, 2021. All right reserved.
7 
8 **/
9 #pragma once
10 
12 #include <qx/meta/qualifiers.h>
13 
14 /**
15  @def QX_EMPTY_MACRO
16  @brief Placeholder for disabled macros
17  @details Has no effect and work correctly with "if else"
18 **/
19 #define QX_EMPTY_MACRO ((void*)0)
20 
21 /**
22  @def QX_STRINGIFY
23  @brief Macro can be used to turn any text in your code into a string,
24  but only the exact text between the parentheses
25  There are no variable dereferencing or macro substitutions or any other sort of thing done.
26  @param name - name to convert to the string
27 **/
28 #define QX_STRINGIFY(name) #name
29 
30 /**
31  @def QX_LINE_NAME
32  @brief Do magic! Creates a unique name using the line number
33  @param prefix - name prefix
34 **/
35 #define QX_LINE_NAME(prefix) _QX_JOIN(prefix, __LINE__)
36 #define _QX_JOIN(symbol1, symbol2) _QX_DO_JOIN(symbol1, symbol2)
37 #define _QX_DO_JOIN(symbol1, symbol2) symbol1##symbol2
38 
39 namespace qx::details
40 {
41 
42 constexpr const char_type* last_slash(const char_type* str)
43 {
44  const char_type* pszLastSlash = str;
45  while (str && *str != QX_TEXT('\0'))
46  {
47  if (*str == QX_TEXT('\\') || *str == QX_TEXT('/'))
48  pszLastSlash = str;
49 
50  ++str;
51  }
52  return pszLastSlash + 1;
53 }
54 
55 } // namespace qx::details
56 
57 /**
58  @def QX_SHORT_FILE
59  @brief Cuts full absolute path to the file name only
60  ex: "C:\folder1\foler2\file.h" => "file.h"
61 **/
62 #define QX_SHORT_FILE qx::details::last_slash(QX_TEXT(__FILE__))
63 
64 /**
65  @def QX_SINGLE_ARGUMENT
66  @brief Let macro param containing commas work fine
67  "#define FOO(type, name) type name"
68  FOO(QX_SINGLE_ARGUMENT(std::map<int, int>), map_var);
69  @param ... - param containing commas
70 **/
71 #define QX_SINGLE_ARGUMENT(...) __VA_ARGS__
72 
73 /**
74  @def QX_CONST_CAST_THIS
75  @brief This macro is made for situations where you have a const method and you need exactly the same method but non-const
76  @warning You can also use it in vice-versa situations, but be careful as it will break your const guarantees
77 
78  @code
79  int foo() const
80  {
81  // some complicated stuff
82  }
83  int foo()
84  {
85  QX_CONST_CAST_THIS()->foo();
86  }
87  @endcode
88 **/
89 #define QX_CONST_CAST_THIS() const_cast<qx::switch_const_t<std::remove_pointer_t<decltype(this)>>*>(this)