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 <string>
23#include <string_view>
24#include <variant>
25
26namespace sen
27{
28
31
33SEN_STRONG_TYPE(InterestId, uint32_t)
34
35template <>
36struct ShouldBePassedByValue<InterestId>: std::true_type
37{
38};
39
41using TypeCondition = std::variant<std::monostate, ConstTypeHandle<ClassType>, std::string>;
42
44struct BusSpec
45{
46 std::string sessionName;
47 std::string busName;
48};
49
51[[nodiscard]] std::string asString(const BusSpec& spec);
52
54using BusCondition = std::optional<BusSpec>;
55
57[[nodiscard]] std::string_view extractQualifiedTypeName(const TypeCondition& condition);
58
60struct VarInfo
61{
62 const Property* property = nullptr;
63 std::vector<uint16_t> fieldIndexes;
64};
65
67using VarInfoList = std::vector<VarInfo>;
68
70class Interest: public std::enable_shared_from_this<Interest>
71{
72public:
73 SEN_NOCOPY_NOMOVE(Interest)
74
75public:
78 [[nodiscard]] static std::shared_ptr<Interest> make(std::string_view query, const CustomTypeRegistry& typeRegistry);
79
80 ~Interest() = default;
81
82public:
84 [[nodiscard]] const TypeCondition& getTypeCondition() const noexcept;
85
87 [[nodiscard]] InterestId getId() const noexcept;
88
90 [[nodiscard]] const lang::Chunk& getQueryCode() const noexcept;
91
93 [[nodiscard]] const std::string& getQueryString() const noexcept;
94
96 [[nodiscard]] const BusCondition& getBusCondition() const noexcept;
97
101 [[nodiscard]] const VarInfoList& getOrComputeVarInfoList(const ClassType* classType) const;
102
103public:
104 [[nodiscard]] bool operator==(const Interest& other) const noexcept;
105 [[nodiscard]] bool operator!=(const Interest& other) const noexcept;
106
107private:
108 Interest(std::string_view query, const CustomTypeRegistry& typeRegistry);
109 Interest(std::string_view query, TypeCondition typeCondition);
110
111private:
112 std::string queryString_;
113 BusCondition busCondition_;
114 TypeCondition type_;
115 lang::Chunk code_;
116 InterestId id_;
117 mutable std::mutex varInfoListMutex_;
118 mutable std::optional<VarInfoList> varInfoList_;
119};
120
122
123} // namespace sen
124
125SEN_STRONG_TYPE_HASHABLE(sen::InterestId)
126
127#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.
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
std::string busName
Definition interest.h:47
std::vector< uint16_t > fieldIndexes
Definition interest.h:63
std::string sessionName
Definition interest.h:46
std::optional< BusSpec > BusCondition
Bus conditions may be present, but are not mandatory.
Definition interest.h:54
std::vector< VarInfo > VarInfoList
List of variables used in a query expression.
Definition interest.h:67
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:41
std::string asString(const BusSpec &spec)
Converts a BusSpec into a session.bus string representation.
The name/address of a bus.
Definition interest.h:45
Information about a variable used in the query.
Definition interest.h:61
Definition code_location.h:14
Definition assert.h:17
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
Utility to indicate that your class wants to be passed by value in some of the library calls.
Definition class_helpers.h:34