LeviLamina
Loading...
Searching...
No Matches
Service.h
1#pragma once
2
3#include "ll/api/service/ServiceId.h"
4
5namespace ll::service {
6
7class Service : public std::enable_shared_from_this<Service> {
8public:
9 virtual ~Service() = default;
10
11 [[nodiscard]] virtual ServiceId getServiceId() const noexcept = 0;
12
13 // this is called when the service is removed from the service manager
14 virtual void invalidate() = 0;
15
16 static constexpr ServiceIdView ServiceId{EmptyServiceId};
17
18 Service() = default;
19 Service(Service const&) = delete;
20 Service(Service&&) = delete;
21 Service& operator=(Service const&) = delete;
22 Service& operator=(Service&&) = delete;
23};
24
25template <class T>
26concept IsService = std::is_base_of_v<Service, T> && requires {
27 T::ServiceId;
28 requires(std::same_as<std::remove_cvref_t<decltype((T::ServiceId))>, ServiceId> || std::same_as<std::remove_cvref_t<decltype((T::ServiceId))>, ServiceIdView>);
29};
30
31template <class T, size_t version>
32class ServiceImpl : public Service {
33public:
34 [[nodiscard]] class ServiceId getServiceId() const noexcept override { return T::ServiceId; }
35
36 static constexpr class ServiceIdView ServiceId {
37 auto_name_t<T>{}, version
38 };
39};
40
41} // namespace ll::service
Definition ServiceId.h:24
Definition ServiceId.h:12
Definition Service.h:32
Definition Service.h:7
Definition Service.h:26
Definition ServiceId.h:9