Sen API
Sen Libraries
Loading...
Searching...
No Matches
method.h
Go to the documentation of this file.
1// === method.h ========================================================================================================
2// Sen Infrastructure
3// Released under the Apache License v2.0 (SPDX-License-Identifier Apache-2.0).
4// See the LICENSE.txt file for more information.
5// © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
6// =====================================================================================================================
7
8#ifndef SEN_CORE_META_METHOD_H
9#define SEN_CORE_META_METHOD_H
10
11// sen
15#include "sen/core/meta/type.h"
16
17// std
18#include <memory>
19#include <utility>
20#include <variant>
21
22namespace sen
23{
24
27
28// forward declarations
29class Property;
30
32enum class Constness
33{
36};
37
40{
41};
42
45{
47};
48
51{
53};
54
56using PropertyRelation = std::variant<NonPropertyRelated, PropertyGetter, PropertySetter>;
57
59struct MethodSpec final
60{
75
76 // Comparison operators
77 friend bool operator==(const MethodSpec& lhs, const MethodSpec& rhs) noexcept
78 {
79 return lhs.callableSpec == rhs.callableSpec && lhs.constness == rhs.constness && lhs.deferred == rhs.deferred &&
80 lhs.returnType == rhs.returnType;
81 }
82
83 friend bool operator!=(const MethodSpec& lhs, const MethodSpec& rhs) noexcept { return !(lhs == rhs); }
84
85public:
86 CallableSpec callableSpec; // NOLINT(misc-non-private-member-variables-in-classes)
87 Constness constness = Constness::nonConstant; // NOLINT(misc-non-private-member-variables-in-classes)
88 ConstTypeHandle<> returnType; // NOLINT(misc-non-private-member-variables-in-classes)
89 PropertyRelation propertyRelation = NonPropertyRelated {}; // NOLINT(misc-non-private-member-variables-in-classes)
90 bool deferred = false; // NOLINT(misc-non-private-member-variables-in-classes)
91 bool localOnly = false; // NOLINT(misc-non-private-member-variables-in-classes)
92};
93
95class Method final: public Callable
96{
97 SEN_NOCOPY_NOMOVE(Method)
99
100public:
103 Method(const MethodSpec& spec, Private notUsable);
104
105public:
108 [[nodiscard]] static std::shared_ptr<Method> make(MethodSpec spec);
109
110public: // special members
111 ~Method() override = default;
112
113public:
115 [[nodiscard]] Constness getConstness() const noexcept;
116
118 [[nodiscard]] bool getDeferred() const noexcept;
119
121 [[nodiscard]] ConstTypeHandle<> getReturnType() const noexcept;
122
124 [[nodiscard]] const PropertyRelation& getPropertyRelation() const noexcept;
125
127 [[nodiscard]] bool getLocalOnly() const noexcept;
128
130 [[nodiscard]] bool operator==(const Method& other) const noexcept;
131
133 [[nodiscard]] bool operator!=(const Method& other) const noexcept;
134
136 [[nodiscard]] MemberHash getHash() const noexcept;
137
139 [[nodiscard]] MemberHash getId() const noexcept;
140
141private:
142 Constness constness_;
143 bool deferred_;
144 bool localOnly_;
145 ConstTypeHandle<> returnType_;
146 PropertyRelation propertyRelation_;
147 MemberHash id_;
148 MemberHash hash_;
149};
150
152
154template <>
155struct impl::hash<MethodSpec>
156{
157 u32 operator()(const MethodSpec& spec) const noexcept
158 {
159 return hashCombine(hashSeed, spec.callableSpec, spec.constness, spec.returnType->getHash());
160 }
161};
162
163} // namespace sen
164
165#endif // SEN_CORE_META_METHOD_H
Here we define a set of template meta-programming helpers to let the compiler take some decisions bas...
Callable(CallableSpec spec)
Copies the spec into a member.
bool getDeferred() const noexcept
True if the method is marked as deferred.
ConstTypeHandle getReturnType() const noexcept
Gets the return type of the method (nullptr means void).
Method(const MethodSpec &spec, Private notUsable)
Copies the spec into a member. Private to prevent direct instances.
~Method() override=default
MemberHash getHash() const noexcept
Returns a unique hash to identify the method.
static std::shared_ptr< Method > make(MethodSpec spec)
Factory function that validates the spec and creates a method. Throws std::exception if the spec is n...
Constness getConstness() const noexcept
The constness of the method.
const PropertyRelation & getPropertyRelation() const noexcept
Information about the relation to a property.
MemberHash getId() const noexcept
Returns the hash of the method's unqualified name.
bool getLocalOnly() const noexcept
True if the method is the method is only locally available (within the same component).
Represents a property.
Definition property.h:79
constexpr u32 hashSeed
Initial seed for all hashes.
Definition hash32.h:33
u32 hashCombine(u32 seed, const Types &... args) noexcept
Combines the hash of different values into a single 32-bit hash.
Definition hash32.h:214
#define SEN_PRIVATE_TAG
Definition compiler_macros.h:490
const Property * property
Definition method.h:46
const Property * property
Definition method.h:52
std::variant< NonPropertyRelated, PropertyGetter, PropertySetter > PropertyRelation
Information about the relation between a method and a property.
Definition method.h:56
Constness
Method constness.
Definition method.h:33
TypeHandle< const T > ConstTypeHandle
Definition type.h:319
@ nonConstant
Definition method.h:35
@ constant
Definition method.h:34
Indicates that the method represents a getter of a property.
Definition method.h:45
Indicates that the method represents a setter of a property.
Definition method.h:51
uint32_t u32
Definition numbers.h:25
This file contains functions related to hashing and compression. This is mainly used by Sen internals...
Definition assert.h:17
STL namespace.
Data of a callable.
Definition callable.h:69
The hash of a member.
Definition type.h:39
Data of a method.
Definition method.h:60
CallableSpec callableSpec
Definition method.h:86
PropertyRelation propertyRelation
Definition method.h:89
ConstTypeHandle returnType
Definition method.h:88
friend bool operator==(const MethodSpec &lhs, const MethodSpec &rhs) noexcept
Definition method.h:77
bool deferred
Definition method.h:90
friend bool operator!=(const MethodSpec &lhs, const MethodSpec &rhs) noexcept
Definition method.h:83
MethodSpec(CallableSpec callableSpec, ConstTypeHandle<> returnType, Constness constness=Constness::nonConstant, PropertyRelation propertyRelation=NonPropertyRelated {}, bool deferred=false, bool localOnly=false)
Definition method.h:61
Constness constness
Definition method.h:87
bool localOnly
Definition method.h:91