Sen API
Sen Libraries
Loading...
Searching...
No Matches
object_source.h
Go to the documentation of this file.
1// === object_source.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_OBJECT_SOURCE_H
9#define SEN_CORE_OBJ_OBJECT_SOURCE_H
10
11// sen
12#include "sen/core/base/span.h"
14#include "sen/core/obj/object.h"
17
18// std
19#include <mutex>
20#include <vector>
21
22namespace sen::kernel::impl
23{
24class Runner;
25} // namespace sen::kernel::impl
26
27namespace sen
28{
29
32
35{
36public:
37 SEN_NOCOPY_NOMOVE(ObjectSource)
38
39public:
40 using NativeObjectPtr = std::shared_ptr<NativeObject>;
41
42public:
43 explicit ObjectSource(const ObjectOwnerId& id): ObjectFilter(id) {}
44 ~ObjectSource() override = default;
45
46public:
51 virtual bool add(const Span<NativeObjectPtr>& instances) = 0;
52
57 bool add(NativeObjectPtr instance) { return add(makeSpan<NativeObjectPtr>(instance)); }
58
60 template <typename T>
61 bool add(const std::vector<std::shared_ptr<T>>& instances)
62 {
63 std::vector<NativeObjectPtr> vec(instances.begin(), instances.end());
64 return add(makeSpan(vec));
65 }
66
70 virtual void remove(const Span<NativeObjectPtr>& instances) = 0;
71
76
78 template <typename T>
79 void remove(const std::vector<std::shared_ptr<T>>& instances)
80 {
81 std::vector<NativeObjectPtr> vec(instances.begin(), instances.end());
82 remove(makeSpan(vec));
83 }
84
85protected:
87 virtual void flushOutputs() = 0;
88 virtual void drainInputs() = 0;
89};
90
92
93} // namespace sen
94
95#endif // SEN_CORE_OBJ_OBJECT_SOURCE_H
ObjectFilter(ObjectOwnerId ownerId)
friend class kernel::impl::Runner
Definition object_source.h:86
virtual void drainInputs()=0
bool add(const std::vector< std::shared_ptr< T > > &instances)
Convenience helper.
Definition object_source.h:61
virtual void flushOutputs()=0
ObjectSource(const ObjectOwnerId &id)
Definition object_source.h:43
bool add(NativeObjectPtr instance)
Registers an object (including its type). It does nothing if the objects are already present....
Definition object_source.h:57
void remove(NativeObjectPtr instance)
Unregisters an object. Does nothing if the object is not present. This method is thread-safe.
Definition object_source.h:75
~ObjectSource() override=default
virtual void remove(const Span< NativeObjectPtr > &instances)=0
Unregisters an object and notifies any registered listeners. Ignores objects that are not present....
std::shared_ptr< NativeObject > NativeObjectPtr
Definition object_source.h:40
virtual bool add(const Span< NativeObjectPtr > &instances)=0
Registers an object (including its type). It does nothing if the object is already registered....
void remove(const std::vector< std::shared_ptr< T > > &instances)
Convenience helper.
Definition object_source.h:79
Contiguous view of elements of type T. Inspired by http://www.open-std.org/jtc1/sc22/wg21/docs/papers...
Definition span.h:34
constexpr Span< T > makeSpan(T *ptr, std::size_t size) noexcept
Takes in a type that can be passed to a contiguous range and returns a Span.
Definition span.h:201
Definition assert.h:17