MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
aspiring_actor.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <mbgl/actor/mailbox.hpp>
4 #include <mbgl/actor/message.hpp>
6 
7 #include <memory>
8 #include <future>
9 #include <type_traits>
10 #include <cassert>
11 
12 namespace mbgl {
13 
14 template <class Object>
15 class EstablishedActor;
16 
17 template <class Object>
18 class Actor;
19 
34 template <class Object>
36 public:
37  AspiringActor() : mailbox(std::make_shared<Mailbox>()) {
38  // mailbox starts closed because the `Object` hasn't yet been constructed
39  assert(!mailbox->isOpen());
40  }
41 
42  AspiringActor(const AspiringActor&) = delete;
43 
45  return ActorRef<std::decay_t<Object>>(object(), mailbox);
46  }
47 
48 private:
49  std::shared_ptr<Mailbox> mailbox;
50  std::aligned_storage_t<sizeof(Object)> objectStorage;
51 
52  Object& object() {
53  return *reinterpret_cast<Object *>(&objectStorage);
54  }
55 
56  friend class EstablishedActor<Object>;
57  friend class Actor<Object>;
58 };
59 
60 } // namespace mbgl
AspiringActor(const AspiringActor &)=delete
constexpr ObjectType Object
Definition: type.hpp:89
Definition: actor.hpp:15
Definition: tile_id.hpp:256