mal-packet-weaver
C++20 packet serialization/deserialization library.
Loading...
Searching...
No Matches
common-structures.hpp
Go to the documentation of this file.
1#pragma once
2#include "library-pch.hpp"
7namespace mal_toolkit
8{
11 {
12 public:
13 non_copyable() = default;
14 non_copyable(const non_copyable &) = delete;
16 };
19 {
20 public:
21 non_movable() = default;
24 };
27 {
28 public:
30 };
35 class namable
36 {
37 public:
38 namable() = default;
39 constexpr explicit namable(std::string const &name) : name_(name) {}
40 constexpr explicit namable(std::string &&name) : name_(std::move(name)) {}
41 ~namable() = default;
42
43 constexpr void set_name(std::string const &name) { name_ = name; }
44 constexpr void set_name(std::string &&name) { name_ = std::move(name); }
45 constexpr void clear_name() { name_.clear(); }
46 constexpr bool has_name() const { return !name_.empty(); }
47 [[nodiscard]] constexpr std::string_view name() const { return name_; }
48
49 private:
50 std::string name_;
51 };
58 {
59 public:
60 namable_protected() = default;
61 constexpr explicit namable_protected(std::string const &name) : namable(name) {}
62 constexpr explicit namable_protected(std::string &&name) : namable(std::move(name)) {}
63 ~namable_protected() = default;
64
65 protected:
68 };
74 class namable_once : private namable
75 {
76 public:
77 constexpr explicit namable_once(std::string const &name) : namable(name) {}
78 constexpr explicit namable_once(std::string &&name) : namable(std::move(name)) {}
79 ~namable_once() = default;
81 using namable::name;
82 };
88 {
89 public:
90 enableable() = default;
91 ~enableable() = default;
92
93 constexpr void enable() { enabled_ = true; }
94 constexpr void disable() { enabled_ = false; }
95 constexpr bool is_enabled() const { return enabled_; }
96 constexpr bool is_disabled() const { return !enabled_; }
97
98 constexpr bool enabled() const { return enabled_; }
99
100 private:
101 bool enabled_ = true;
102 };
103} // namespace mal_toolkit
A class that can be enabled or disabled.
constexpr bool enabled() const
constexpr bool is_disabled() const
constexpr bool is_enabled() const
A class that contains a name and can be named only once at construction.
constexpr std::string_view name() const
constexpr namable_once(std::string const &name)
constexpr namable_once(std::string &&name)
A class that contains a name and can be named and unnamed, but you cant set the name from outside.
constexpr namable_protected(std::string const &name)
constexpr namable_protected(std::string &&name)
A class that contains a name and can be named and unnamed.
constexpr namable(std::string &&name)
constexpr std::string_view name() const
constexpr namable(std::string const &name)
constexpr void clear_name()
constexpr bool has_name() const
constexpr void set_name(std::string const &name)
constexpr void set_name(std::string &&name)
A class that can't be copied neither moved.
A class that can't be copied.
non_copyable(const non_copyable &)=delete
non_copyable & operator=(const non_copyable &)=delete
A class that can't be moved.
non_movable & operator=(non_movable &&)=delete
non_movable(non_movable &&)=delete
Precompiled header (PCH) file for common headers used across the library.
Contains a collection of tools and utilities provided by the MAL Toolkit library.
Definition backoffs.hpp:7
STL namespace.