3 #include "utilities/event.h" 4 #include "utilities/for_each.h" 5 #include "utilities/map.h" 6 #include "utilities/mapping_iterator_adapter.h" 8 #include "cereal/types/tuple.hpp" 16 template <
typename Derived>
19 using derived_type = Derived;
31 using connection =
typename on_change::connection;
32 using scoped_connection =
typename on_change::scoped_connection;
33 using callback_type =
typename on_change::callback_type;
35 connection connect(callback_type t) {
36 return on_change_.connect(std::move(t));
39 void notify() { on_change_(*static_cast<Derived*>(
this)); }
40 size_t connections()
const {
return on_change_.size(); }
49 #define NOTIFYING_COPY_ASSIGN_DECLARATION(TYPE) \ 50 inline TYPE& operator=(const TYPE& other) { \ 52 base_type::operator=(copy); \ 60 template <
typename Item>
63 using scoped_connection =
typename Item::scoped_connection;
76 template <
typename Owner>
80 template <
typename Owner>
82 : item_{std::make_shared<item_t>(i)}
84 item_->connect([o = &owner](
auto&) { o->notify(); })} {}
98 const std::shared_ptr<item_t>&
item()
const {
return item_; }
100 auto get()
const {
return item_.get(); }
101 auto operator-> ()
const {
return item_.operator->(); }
102 auto& operator*()
const {
return item_.operator*(); }
104 void block() { connection_.connection.block(); }
105 void unblock() { connection_.connection.unblock(); }
108 std::shared_ptr<item_t> item_;
109 scoped_connection connection_;
113 template <
typename T>
119 template <
typename It>
120 static auto make_item_extractor_iterator(It it) {
121 return util::make_mapping_iterator_adapter(std::move(it),
item_extractor{});
126 template <
typename Derived,
typename... DataMembers>
129 using derived_type = Derived;
136 *
static_cast<Derived*
>(
this)}...} {}
142 *
static_cast<Derived*
>(
this), data_members}...} {}
149 std::make_index_sequence<
sizeof...(DataMembers)>{}} {}
155 assign(other, std::make_index_sequence<
sizeof...(DataMembers)>{});
159 template <
typename Archive>
171 return tie() == other.tie();
175 return !operator==(other);
182 const auto&
get()
const & {
183 return std::get<I>(data_members_);
188 return std::get<I>(data_members_);
191 template <
typename T>
192 const auto&
get()
const & {
193 return std::get<persistent_connection<T>>(data_members_);
196 template <
typename T>
198 return std::get<persistent_connection<T>>(data_members_);
202 using data_members = std::tuple<persistent_connection<DataMembers>...>;
205 using tuple_element_t = std::tuple_element_t<I, data_members>;
207 template <
size_t... Ix>
209 : data_members_{tuple_element_t<Ix>{
210 *
static_cast<Derived*
>(
this),
214 template <
size_t... Ix>
215 void assign(
const owning_member& other, std::index_sequence<Ix...>) {
216 (void)std::initializer_list<int>{
219 std::get<Ix>(other.data_members_))),
223 template <
size_t... Ix>
224 auto tie(std::index_sequence<Ix...>)
const {
225 return std::tie(
item_extractor{}(std::get<Ix>(data_members_))...);
229 return tie(std::make_index_sequence<
sizeof...(DataMembers)>{});
232 data_members data_members_;
basic_member(const basic_member &)
Definition: member.h:27
owning_member(const DataMembers &...data_members)
Definition: member.h:140
persistent_connection(Owner &owner)
Assumption: owner will always outlive the connection.
Definition: member.h:77
owning_member()
Definition: member.h:134
void serialize(Archive &archive)
Definition: member.h:160
const std::shared_ptr< item_t > & item() const
Definition: member.h:98
Definition: capsule_base.h:9
owning_member(const owning_member &other)
Definition: member.h:146
owning_member & operator=(const owning_member &other)
Definition: member.h:154