utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
loggable.hpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
32#pragma once
33
34#include <memory>
35#include <string>
36#include <typeinfo>
37
38#include "utility/demangle.hpp"
39
41
42namespace utility::logging
43{
44
54 template<typename ClassType, InheritFromLogger LoggerType> class Loggable
55 {
56 private:
57 std::string _name;
58 std::unique_ptr<LoggerType> _logger;
59
60 protected:
64 explicit Loggable(void)
65 : _name(utility::demangle<ClassType>())
66 , _logger(std::make_unique<LoggerType>(_name))
67 {
68 }
69
74 Loggable(Loggable &&other) noexcept
75 : _name(std::move(other._name))
76 , _logger(std::move(other._logger))
77 {
78 }
79
85 Loggable &operator=(Loggable &&other) noexcept
86 {
87 if (this != &other) {
88 _name = std::move(other._name);
89 _logger = std::move(other._logger);
90 }
91 return *this;
92 }
93
98 LoggerType &getLogger(void)
99 {
100 return *_logger;
101 }
102
107 LoggerType &getLogger(void) const
108 {
109 return *_logger;
110 }
111
112 public:
116 virtual ~Loggable(void) = default;
117 };
118
119} // namespace utility::logging
Mixin base class providing logging capabilities to derived classes.
Definition loggable.hpp:55
Loggable & operator=(Loggable &&other) noexcept
Move assignment operator for Loggable.
Definition loggable.hpp:85
Loggable(Loggable &&other) noexcept
Move constructor for Loggable.
Definition loggable.hpp:74
Loggable(void)
Construct a Loggable with the specified LoggerType.
Definition loggable.hpp:64
LoggerType & getLogger(void) const
Get the internal logger.
Definition loggable.hpp:107
virtual ~Loggable(void)=default
Virtual destructor for proper cleanup.
LoggerType & getLogger(void)
Get the internal logger.
Definition loggable.hpp:98
Logging interface with levels, source-location metadata, and stream-style output.
The utility namespace contains classes and functions for the utility project.
Definition cache.hpp:34
std::string demangle(void)
Demangles a C++ type name for better readability.
Definition demangle.hpp:51