Sen API
Sen Libraries
Loading...
Searching...
No Matches
interest.h
Go to the documentation of this file.
1// === interest.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_OBJ_INTEREST_H
9#define SEN_CORE_OBJ_INTEREST_H
10
11// sen
14#include "sen/core/lang/vm.h"
16#include "sen/core/meta/type.h"
18
19// std
20#include <memory>
21#include <mutex>
22#include <optional>
23#include <string>
24#include <string_view>
25#include <unordered_map>
26#include <variant>
27
28namespace sen
29{
30
33
35SEN_STRONG_TYPE(InterestId, uint32_t)
36
37template <>
38struct ShouldBePassedByValue<InterestId>: std::true_type
39{
40};
41
43using TypeCondition = std::variant<std::monostate, ConstTypeHandle<ClassType>, std::string>;
44
46struct BusSpec
47{
48 std::string sessionName;
49 std::string busName;
50};
51
53[[nodiscard]] std::string asString(const BusSpec& spec);
54
56using BusCondition = std::optional<BusSpec>;
57
59[[nodiscard]] std::string_view extractQualifiedTypeName(const TypeCondition& condition);
60
62struct VarInfo
63{
64 const Property* property = nullptr;
65 std::vector<uint16_t> fieldIndexes;
66};
67
69using VarInfoList = std::vector<VarInfo>;
70
72class Interest: public std::enable_shared_from_this<Interest>
73{
74public:
75 SEN_NOCOPY_NOMOVE(Interest)
77
78public:
81 [[nodiscard]] static std::shared_ptr<Interest> make(std::string_view query, const CustomTypeRegistry& typeRegistry);
82
83 ~Interest() = default;
84
85public:
87 [[nodiscard]] const TypeCondition& getTypeCondition() const noexcept;
88
90 [[nodiscard]] InterestId getId() const noexcept;
91
93 [[nodiscard]] const lang::Chunk& getQueryCode() const noexcept;
94
96 [[nodiscard]] const std::string& getQueryString() const noexcept;
97
99 [[nodiscard]] const BusCondition& getBusCondition() const noexcept;
100
104 [[nodiscard]] const VarInfoList& getOrComputeVarInfoList(const ClassType* classType) const;
105
106public:
107 [[nodiscard]] bool operator==(const Interest& other) const noexcept;
108 [[nodiscard]] bool operator!=(const Interest& other) const noexcept;
109
110public:
111 Interest(std::string_view query, const CustomTypeRegistry& typeRegistry, Private notUsable);
112
113private:
114 std::string queryString_;
115 BusCondition busCondition_;
116 TypeCondition type_;
117 lang::Chunk code_;
118 InterestId id_;
119 mutable std::mutex varInfoListMutex_;
120
121 // An interest with no type condition sees every class on the bus, and a VarInfo holds field
122 // positions taken from one of them. An empty optional marks a class the query cannot resolve.
123 mutable std::unordered_map<MemberHash, std::optional<VarInfoList>> varInfoLists_;
124};
125
127
128} // namespace sen
129
130SEN_STRONG_TYPE_HASHABLE(sen::InterestId)
131
132#endif // SEN_CORE_OBJ_INTEREST_H
A registry of custom types.
Definition type_registry.h:36
const VarInfoList & getOrComputeVarInfoList(const ClassType *classType) const
Compute the information about the variables used in the query expression (if any)....
const lang::Chunk & getQueryCode() const noexcept
The code that can evaluate the condition.
Interest(std::string_view query, const CustomTypeRegistry &typeRegistry, Private notUsable)
const BusCondition & getBusCondition() const noexcept
The source of this interest (if any).
const TypeCondition & getTypeCondition() const noexcept
The condition related to the type.
InterestId getId() const noexcept
The unique ID of this interest.
~Interest()=default
static std::shared_ptr< Interest > make(std::string_view query, const CustomTypeRegistry &typeRegistry)
Make an interest from a query. Throws std::exception if not well formed.
const std::string & getQueryString() const noexcept
The user-defined string that encodes the criteria.
Represents a property.
Definition property.h:79
#define SEN_PRIVATE_TAG
Definition compiler_macros.h:490
std::string busName
Definition interest.h:49
std::vector< uint16_t > fieldIndexes
Definition interest.h:65
std::string sessionName
Definition interest.h:48
std::optional< BusSpec > BusCondition
Bus conditions may be present, but are not mandatory.
Definition interest.h:56
std::vector< VarInfo > VarInfoList
List of variables used in a query expression.
Definition interest.h:69
std::string_view extractQualifiedTypeName(const TypeCondition &condition)
Gets the qualified type name from a type condition.
std::variant< std::monostate, ConstTypeHandle< ClassType >, std::string > TypeCondition
A condition set on an object's type.
Definition interest.h:43
std::string asString(const BusSpec &spec)
Converts a BusSpec into a session.bus string representation.
The name/address of a bus.
Definition interest.h:47
Information about a variable used in the query.
Definition interest.h:63
Definition code_location.h:14
Definition assert.h:19
STL namespace.
#define SEN_STRONG_TYPE_HASHABLE(name)
Makes your strong type std::hashable. NOLINTNEXTLINE.
Definition strong_type.h:188
#define SEN_STRONG_TYPE(name, native_type)
Helper macro to define strong types. NOLINTNEXTLINE.
Definition strong_type.h:179
The hash of a member.
Definition type.h:39
Utility to indicate that your class wants to be passed by value in some of the library calls.
Definition class_helpers.h:34