qxLib
category.h
Go to the documentation of this file.
1 /**
2 
3  @file category.h
4  @author Khrapov
5  @date 5.12.2022
6  @copyright © Nick Khrapov, 2022. All right reserved.
7 
8 **/
9 #pragma once
10 
12 #include <qx/macros/common.h>
13 #include <qx/render/color.h>
14 #include <qx/verbosity.h>
15 
16 /**
17  @brief Define a category
18  @param name - category name
19  @param ... - optional category color
20 **/
21 #define QX_DEFINE_CATEGORY(name, ...) constexpr qx::category name(QXT(#name), ##__VA_ARGS__)
22 
23 /**
24  @brief Set the file category
25  You can access this value via QX_GET_FILE_CATEGORY()
26  This category will not be exported via #include
27  @param _category - category to use in this file
28 **/
29 #define QX_SET_FILE_CATEGORY(_category) \
30  template<> \
31  struct qx::details::file_category<qx::djb2a_hash(QX_SHORT_FILE, 0)> \
32  { \
33  static constexpr const qx::category& get() noexcept \
34  { \
35  return _category; \
36  } \
37  }
38 
39 /**
40  @brief Get category defined in QX_SET_FILE_CATEGORY
41  If there is none, CatDefault will be used
42 **/
43 #define QX_GET_FILE_CATEGORY() qx::details::file_category<qx::djb2a_hash(QX_SHORT_FILE)>::get()
44 
45 namespace qx
46 {
47 
48 /**
49 
50  @class category
51  @brief A category is a class that identifies a particular piece of code.
52  This code can be located in different files, but united by one functionality.
53  Objects of this class can be used in logging, asserts and profiling.
54  @author Khrapov
55  @date 5.12.2022
56 
57 **/
58 class category
59 {
60  static constexpr auto kDefaultColor = color::white();
61 
62 public:
63  constexpr category() = default;
64  constexpr category(const category&) = default;
65  constexpr category(category&&) = default;
66  constexpr category& operator=(const category&) = default;
67  constexpr category& operator=(category&&) = default;
68 
69  constexpr bool operator==(const category&) const = default;
70 
71  /**
72  @brief category object constructor
73  @param svName - category name. For ex. CatRendering or CatWidgets
74  @param categoryColor - color to be used if supported
75  **/
76  constexpr explicit category(string_view svName, const color& categoryColor = kDefaultColor) noexcept;
77 
78  /**
79  @brief Create new category from this one with custom verbosity
80  @param eVerbosity - category verbosity.
81  User code will use this category with top priority and perform compile time checks if possible
82  @retval - new category
83  **/
84  constexpr category set_verbosity(verbosity eVerbosity) const noexcept;
85 
86  /**
87  @brief Get category name
88  @retval - category name
89  **/
90  constexpr string_view get_name() const noexcept;
91 
92  /**
93  @brief Get category color
94  @retval - category color
95  **/
96  constexpr const color& get_color() const noexcept;
97 
98  /**
99  @brief Get category verbosity
100  @retval - category verbosity
101  User code will use this category with top priority and perform compile time checks if possible
102  **/
103  constexpr verbosity get_verbosity() const noexcept;
104 
105 private:
106  color m_Color = kDefaultColor;
107  string_view m_svName;
108  verbosity m_Verbosity = QX_CONF_COMPILE_TIME_VERBOSITY;
109 };
110 
111 } // namespace qx
112 
113 #include <qx/category.inl>
114 
115 QX_DEFINE_CATEGORY(CatDefault, qx::color::white());
116 
117 namespace qx::details
118 {
119 
120 template<size_t nHash>
122 {
123  static constexpr const qx::category& get() noexcept
124  {
125  return CatDefault;
126  }
127 };
128 
129 } // namespace qx::details
#define QX_DEFINE_CATEGORY(name,...)
Define a category.
Definition: category.h:21
A category is a class that identifies a particular piece of code. This code can be located in differe...
Definition: category.h:59
constexpr string_view get_name() const noexcept
Get category name.
Definition: category.inl:26
constexpr category set_verbosity(verbosity eVerbosity) const noexcept
Create new category from this one with custom verbosity.
Definition: category.inl:19
constexpr const color & get_color() const noexcept
Get category color.
Definition: category.inl:31
constexpr verbosity get_verbosity() const noexcept
Get category verbosity.
Definition: category.inl:36
RGBA color.
Definition: color.h:193