-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pool_Manager.h
38 lines (30 loc) · 1.02 KB
/
Pool_Manager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef POOL_MANAGER_H
#define POOL_MANAGER_H
#include <unordered_map>
#include <memory>
#include <mutex>
#include <stack>
#include <limits>
#include <cstdint>
#include "LiquidityPool.h"
/**
* Pool Manager will manage a list of pools, where Pools are labelled with a UINT_64t ID.
* Pool Manager itself uses singleton pattern because there should be only one such instance.
*/
class Pool_Manager {
private:
std::unordered_map<uint64_t, std::shared_ptr<LiquidityPool>> pools;
std::stack<uint64_t> reusableIds; // Stack to store reusable IDs
static std::unique_ptr<Pool_Manager> instance;
static std::mutex mutex;
uint64_t nextPoolId = 0;
Pool_Manager() = default;
public:
static Pool_Manager* getInstance();
uint64_t addPool(std::shared_ptr<LiquidityPool> pool);
std::weak_ptr<LiquidityPool> getPool(uint64_t id);
std::shared_ptr<LiquidityPool> removePool(uint64_t id);
Pool_Manager(const Pool_Manager&) = delete;
Pool_Manager& operator=(const Pool_Manager&) = delete;
};
#endif