ResourceManagementSystem.cpp
Go to the documentation of this file.
2 #include "ResourceProvider.hpp"
4 
5 namespace iv
6 {
7 
9  System( sc ),
10  root( "resources", sc )
11 {
12 }
13 
15 {
16 }
17 
19 {
20  this->providers.insert( std::make_pair( priority, provider ) );
21 }
22 
24 {
25  for( auto it = this->providers.begin(); it != this->providers.end(); ++it )
26  if( it->second == provider )
27  {
28  this->providers.erase( it );
29  break;
30  }
31 }
32 
34 {
35  auto & out = context->out();
36 
37  for( auto const & p_provider : this->providers )
38  {
39  size_t priority = p_provider.first;
40  ResourceProvider * provider = p_provider.second;
41 
42  out << "priority " << priority << " | " << provider->cm.root_name_id() << ":" << std::endl;
43 
44  std::vector< std::type_index > types;
45 
46  provider->each_type(
47  [ & ]( std::type_index type )
48  {
49  types.push_back( type );
50  }
51  );
52 
53  for( std::type_index type : types )
54  {
55  out << " type " << type.name() << ":" << std::endl;
56  provider->each_resource(
57  type,
58  [&]( ResourcePath const & path )
59  {
60  out << " " << path << std::endl;
61  }
62  );
63  }
64 
65  out << std::endl;
66  }
67 }
68 
69 ResourceProvider * ResourceManagementSystem::choose_provider( ResourcePath const & path, std::type_index type )
70 {
71  for( auto & p_provider : this->providers )
72  if( p_provider.second->has_path( path, type ) )
73  return p_provider.second;
74 
75  return nullptr;
76 }
77 
78 }