Skip to content

Commit b514331

Browse files
committed
Move HeapAllocator to separate file
1 parent 5666088 commit b514331

4 files changed

Lines changed: 40 additions & 30 deletions

File tree

include/cpp_event_framework/Concepts.hxx

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,46 +21,21 @@ namespace cpp_event_framework
2121
*/
2222
template <typename T>
2323
concept Mutex = std::is_constructible_v<T> && std::is_destructible_v<T> && requires(T a) {
24-
{
25-
a.lock()
26-
};
27-
{
28-
a.unlock()
29-
};
24+
{ a.lock() };
25+
{ a.unlock() };
3026
};
3127

3228
template <typename T>
3329
concept Semaphore = std::is_constructible_v<T, std::ptrdiff_t> && std::is_destructible_v<T> && requires(T a) {
34-
{
35-
a.acquire()
36-
};
37-
{
38-
a.release()
39-
};
30+
{ a.acquire() };
31+
{ a.release() };
4032
};
4133

4234
/**
4335
* @brief Concept for a provider of a polymorphic allocator (std::pmr::memory_resource)
4436
*/
4537
template <typename T>
4638
concept PolymorphicAllocatorProvider = requires(T a) {
47-
{
48-
a.GetAllocator()
49-
} -> std::convertible_to<std::pmr::memory_resource*>;
50-
};
51-
52-
/**
53-
* @brief Use this allocator to allocate from heap
54-
*/
55-
class HeapAllocator
56-
{
57-
public:
58-
/**
59-
* @brief Default heap-based allocator
60-
*/
61-
static std::pmr::memory_resource* GetAllocator()
62-
{
63-
return std::pmr::new_delete_resource();
64-
}
39+
{ a.GetAllocator() } -> std::convertible_to<std::pmr::memory_resource*>;
6540
};
6641
} // namespace cpp_event_framework
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @file HeapAllocator.hxx
3+
* @author your name (you@domain.com)
4+
* @brief
5+
* @version 0.1
6+
* @date 2024-08-24
7+
*
8+
* @copyright Copyright (c) 2024
9+
*
10+
*/
11+
12+
#pragma once
13+
14+
#include <memory_resource>
15+
16+
namespace cpp_event_framework
17+
{
18+
/**
19+
* @brief Use this allocator to allocate from heap
20+
*/
21+
class HeapAllocator
22+
{
23+
public:
24+
/**
25+
* @brief Default heap-based allocator
26+
*/
27+
static std::pmr::memory_resource* GetAllocator()
28+
{
29+
return std::pmr::new_delete_resource();
30+
}
31+
};
32+
} // namespace cpp_event_framework

include/cpp_event_framework/Signal.hxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include <cpp_event_framework/Concepts.hxx>
2020
#include <cpp_event_framework/DemangledTypeName.hxx>
21+
#include <cpp_event_framework/HeapAllocator.hxx>
22+
2123

2224
namespace cpp_event_framework
2325
{

include/cpp_event_framework/Statemachine.hxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <span>
1717

1818
#include <cpp_event_framework/Concepts.hxx>
19+
#include <cpp_event_framework/HeapAllocator.hxx>
1920

2021
namespace cpp_event_framework
2122
{

0 commit comments

Comments
 (0)