Toggle navigation
ivorium
iv_components
Example project
GitHub
Main Page
Modules
Classes
Files
File List
File Members
ivorium_systems
ResourceManagementSystem
ResourceManagementSystem.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include "
ResourceProvider.hpp
"
4
#include "
ResourcePath.hpp
"
5
#include <
ivorium_core/ivorium_core.hpp
>
6
#include <map>
7
8
namespace
iv
9
{
10
11
class
ResourcesRoot
12
{
13
public
:
14
ClientMarker
cm
;
15
ResourcesRoot
(
Instance
* inst ):
16
cm
( inst, this,
"ResourcesRoot"
),
17
inst( inst )
18
{
19
}
20
21
Instance
*
instance
()
22
{
23
return
this->inst;
24
}
25
26
Heap
heap
;
27
28
private
:
29
Instance
* inst;
30
};
31
32
37
class
ResourceManagementSystem
:
public
System
38
{
39
public
:
40
ResourceManagementSystem
(
SystemContainer
* sc );
41
~ResourceManagementSystem
();
42
virtual
std::string
debug_name
()
const override
{
return
"ResourceManagementSystem"
; }
43
virtual
void
status
(
TextDebugView
* view )
override
;
44
45
//------- resource requests --------
46
template
<
class
TResource >
47
bool
has_path
(
ResourcePath
path );
48
51
template
<
class
TResource >
52
TResource
const
*
get
(
ResourcePath
path );
53
54
template
<
class
TResource >
55
void
each_resource
( std::function<
void
(
ResourcePath
const
& path ) >
const
& );
56
57
//------ provider registration ------
64
void
register_provider
(
ResourceProvider
* provider,
size_t
priority );
65
void
unregister_provider
(
ResourceProvider
* provider );
66
67
private
:
68
ResourceProvider
* choose_provider(
ResourcePath
const
& path, std::type_index type );
69
70
private
:
71
I< ResourcesRoot >
root;
72
73
// provider data
74
using
PriorityCmp = std::greater< size_t >;
75
std::multimap<
size_t
/*priority*/
,
ResourceProvider
*, PriorityCmp > providers;
76
77
// resource data
78
struct
Resource
79
{
80
Resource() : type( typeid( void ) ), client( nullptr ), inst( nullptr ){}
81
82
std::type_index type;
83
void
* client;
84
Instance * inst;
85
};
86
87
std::unordered_multimap< ResourcePath, Resource > resources;
88
};
89
90
}
91
92
#include "
ResourceManagementSystem.inl
"