dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
PrivateState.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Vincent Leroy
2// SPDX-License-Identifier: MIT
3//
4// This file is part of dfx.
5//
6// Licensed under the MIT License. See the LICENSE file in the project root
7// for full license information.
8
9#pragma once
10
11// Standard includes
12#include <exception>
13#include <memory>
14#include <utility>
15
16// Project includes
17#include "Log.hpp"
18
38
52#define DFX_PRIVATE_STATE(Class, logger) \
53private: \
54 struct State; \
55 std::unique_ptr<State> _state; \
56 template<typename Self> \
57 decltype(auto) _st(this Self && self) noexcept \
58 { \
59 if (self._state == nullptr) \
60 { \
61 DFX_LLOG_CRITICAL(logger, #Class " used after move"); \
62 std::terminate(); \
63 } \
64 return *std::forward<Self>(self)._state; \
65 }
66
82#define DFX_PRIVATE_STATE_DECLARE_RULE_OF_5(Class) \
83public: \
84 Class(Class const &) = delete; \
85 Class(Class &&) noexcept; \
86 ~Class(); \
87 Class & operator=(Class const &) = delete; \
88 Class & operator=(Class &&) noexcept
89
99#define DFX_PRIVATE_STATE_DEFINE_RULE_OF_5(ns, Class) \
100 ns::Class::Class(Class &&) noexcept = default; \
101 ns::Class::~Class() = default; \
102 ns::Class & ns::Class::operator=(Class &&) noexcept = default