NAWA
0.9
Web Application Framework for C++
macros.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2019-2022 Tobias Flaig.
3
*
4
* This file is part of nawa.
5
*
6
* nawa is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License,
8
* version 3, as published by the Free Software Foundation.
9
*
10
* nawa is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Lesser General Public License for more details.
14
*
15
* You should have received a copy of the GNU Lesser General Public License
16
* along with nawa. If not, see <https://www.gnu.org/licenses/>.
17
*/
18
24
#ifndef NAWA_MACROS_H
25
#define NAWA_MACROS_H
26
27
#include <experimental/propagate_const>
28
#include <memory>
29
30
#define NAWA_PRIVATE_DATA() \
31
struct Data; \
32
std::experimental::propagate_const<std::unique_ptr<Data>> data;
33
34
#define NAWA_DEFAULT_DESTRUCTOR_DEF(Class) virtual ~Class()
35
#define NAWA_DEFAULT_DESTRUCTOR_OVERRIDE_DEF(Class) ~Class() override
36
#define NAWA_DEFAULT_DESTRUCTOR_IMPL(Class) Class::~Class() = default;
37
#define NAWA_DEFAULT_DESTRUCTOR_IMPL_WITH_NS(Namespace, Class) Namespace::Class::~Class() = default;
38
39
#define NAWA_DEFAULT_CONSTRUCTOR_DEF(Class) Class()
40
#define NAWA_DEFAULT_CONSTRUCTOR_IMPL(Class) \
41
Class::Class() { data = make_unique<Data>(); }
42
#define NAWA_DEFAULT_CONSTRUCTOR_IMPL_WITH_NS(Namespace, Class) \
43
Namespace::Class::Class() { data = make_unique<Data>(); }
44
45
#define NAWA_COPY_CONSTRUCTOR_DEF(Class) Class(Class const& other)
46
#define NAWA_COPY_CONSTRUCTOR_IMPL(Class) \
47
Class::Class(const Class& other) { data = make_unique<Data>(*other.data); }
48
#define NAWA_COPY_CONSTRUCTOR_IMPL_WITH_NS(Namespace, Class) \
49
Namespace::Class::Class(const Namespace::Class& other) { data = make_unique<Data>(*other.data); }
50
#define NAWA_COPY_CONSTRUCTOR_DERIVED_IMPL(Class, Parent) \
51
Class::Class(const Class& other) : Parent(other) { data = make_unique<Data>(*other.data); }
52
#define NAWA_COPY_CONSTRUCTOR_DERIVED_IMPL_WITH_NS(Namespace, Class, Parent) \
53
Namespace::Class::Class(const Namespace::Class& other) : Parent(other) { data = make_unique<Data>(*other.data); }
54
55
#define NAWA_COPY_ASSIGNMENT_OPERATOR_DEF(Class) Class& operator=(const Class& other)
56
#define NAWA_COPY_ASSIGNMENT_OPERATOR_IMPL(Class) \
57
Class& Class::operator=(const Class& other) { \
58
if (this != &other) { \
59
*data = *other.data; \
60
} \
61
return *this; \
62
}
63
#define NAWA_COPY_ASSIGNMENT_OPERATOR_IMPL_WITH_NS(Namespace, Class) \
64
Namespace::Class& Namespace::Class::operator=(const Namespace::Class& other) { \
65
if (this != &other) { \
66
*data = *other.data; \
67
} \
68
return *this; \
69
}
70
#define NAWA_COPY_ASSIGNMENT_OPERATOR_DERIVED_IMPL(Class, Parent) \
71
Class& Class::operator=(const Class& other) { \
72
if (this != &other) { \
73
Parent::operator=(other); \
74
*data = *other.data; \
75
} \
76
return *this; \
77
}
78
#define NAWA_COPY_ASSIGNMENT_OPERATOR_DERIVED_IMPL_WITH_NS(Namespace, Class, Parent) \
79
Namespace::Class& Namespace::Class::operator=(const Namespace::Class& other) { \
80
if (this != &other) { \
81
Parent::operator=(other); \
82
*data = *other.data; \
83
} \
84
return *this; \
85
}
86
87
#define NAWA_MOVE_CONSTRUCTOR_DEF(Class) Class(Class&& other) noexcept
88
#define NAWA_MOVE_CONSTRUCTOR_IMPL(Class) \
89
Class::Class(Class&& other) noexcept : data(std::move(other.data)) {}
90
#define NAWA_MOVE_CONSTRUCTOR_IMPL_WITH_NS(Namespace, Class) \
91
Namespace::Class::Class(Namespace::Class&& other) noexcept : data(std::move(other.data)) {}
92
#define NAWA_MOVE_CONSTRUCTOR_DERIVED_IMPL(Class, Parent) \
93
Class::Class(Class&& other) noexcept : Parent(std::move(other)), data(std::move(other.data)) {}
94
#define NAWA_MOVE_CONSTRUCTOR_DERIVED_IMPL_WITH_NS(Namespace, Class, Parent) \
95
Namespace::Class::Class(Namespace::Class&& other) noexcept : Parent(std::move(other)), data(std::move(other.data)) {}
96
97
#define NAWA_MOVE_ASSIGNMENT_OPERATOR_DEF(Class) Class& operator=(Class&& other) noexcept
98
#define NAWA_MOVE_ASSIGNMENT_OPERATOR_IMPL(Class) \
99
Class& Class::operator=(Class&& other) noexcept { \
100
if (this != &other) { \
101
data = std::move(other.data); \
102
} \
103
return *this; \
104
}
105
#define NAWA_MOVE_ASSIGNMENT_OPERATOR_IMPL_WITH_NS(Namespace, Class) \
106
Namespace::Class& Namespace::Class::operator=(Namespace::Class&& other) noexcept { \
107
if (this != &other) { \
108
data = std::move(other.data); \
109
} \
110
return *this; \
111
}
112
#define NAWA_MOVE_ASSIGNMENT_OPERATOR_DERIVED_IMPL(Class, Parent) \
113
Class& Class::operator=(Class&& other) noexcept { \
114
if (this != &other) { \
115
data = std::move(other.data); \
116
Parent::operator=(std::move(other)); \
117
} \
118
return *this; \
119
}
120
#define NAWA_MOVE_ASSIGNMENT_OPERATOR_DERIVED_IMPL_WITH_NS(Namespace, Class, Parent) \
121
Namespace::Class& Namespace::Class::operator=(Namespace::Class&& other) noexcept { \
122
if (this != &other) { \
123
data = std::move(other.data); \
124
Parent::operator=(std::move(other)); \
125
} \
126
return *this; \
127
}
128
129
#define NAWA_PRIMITIVE_DATA_ACCESSORS_DEF(Class, Member, Type) \
130
Type& Member() noexcept; \
131
[[nodiscard]] Type Member() const noexcept; \
132
Class& Member(Type value) noexcept
133
#define NAWA_COMPLEX_DATA_ACCESSORS_DEF(Class, Member, Type) \
134
Type& Member() noexcept; \
135
[[nodiscard]] Type const& Member() const noexcept; \
136
Class& Member(Type value) noexcept
137
#define NAWA_PRIMITIVE_DATA_ACCESSORS_IMPL(Class, Member, Type) \
138
Type& Class::Member() noexcept { return data->Member; } \
139
Type Class::Member() const noexcept { return data->Member; } \
140
Class& Class::Member(Type value) noexcept { \
141
data->Member = value; \
142
return *this; \
143
}
144
#define NAWA_COMPLEX_DATA_ACCESSORS_IMPL(Class, Member, Type) \
145
Type& Class::Member() noexcept { return data->Member; } \
146
Type const& Class::Member() const noexcept { return data->Member; } \
147
Class& Class::Member(Type value) noexcept { \
148
data->Member = std::move(value); \
149
return *this; \
150
}
151
152
#endif
//NAWA_MACROS_H
include
nawa
internal
macros.h
Generated by
1.9.2