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, 0)>::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  /**
70  @brief category object constructor
71  @param svName - category name. For ex. CatRendering or CatWidgets
72  @param categoryColor - color to be used if supported
73  **/
74  constexpr explicit category(string_view svName, const color& categoryColor = kDefaultColor) noexcept;
75 
76  /**
77  @brief Create new category from this one with custom verbosity
78  @param eVerbosity - category verbosity.
79  User code will use this category with top priority and perform compile time checks if possible
80  @retval - new category
81  **/
82  constexpr category set_verbosity(verbosity eVerbosity) const noexcept;
83 
84  /**
85  @brief Get category name
86  @retval - category name
87  **/
88  constexpr string_view get_name() const noexcept;
89 
90  /**
91  @brief Get category color
92  @retval - category color
93  **/
94  constexpr const color& get_color() const noexcept;
95 
96  /**
97  @brief Get category verbosity
98  @retval - category verbosity
99  User code will use this category with top priority and perform compile time checks if possible
100  **/
101  constexpr verbosity get_verbosity() const noexcept;
102 
103 private:
104  color m_Color = kDefaultColor;
105  string_view m_svName;
106  verbosity m_Verbosity = QX_CONF_COMPILE_TIME_VERBOSITY;
107 };
108 
109 } // namespace qx
110 
111 #include <qx/category.inl>
112 
113 QX_DEFINE_CATEGORY(CatDefault, qx::color::white());
#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