VirtualResourceProvider.cpp
Go to the documentation of this file.
2 
3 namespace iv
4 {
5 
6 std::unordered_multimap< std::type_index, std::unique_ptr< VirtualResourceProvider::Marker > > * VirtualResourceProvider::Markers;
7 
9 {
10  if( !VirtualResourceProvider::Markers )
11  return;
12 
13  delete VirtualResourceProvider::Markers; // This should delete all members via unique_ptr.
14  VirtualResourceProvider::Markers = nullptr;
15 }
16 
18  ResourceProvider( inst, priority ),
19  cm( inst, this, "VirtualResourceProvider" )
20 {
21  this->cm.inherits( this->ResourceProvider::cm );
22 }
23 
24 bool VirtualResourceProvider::has_path( ResourcePath const & path, std::type_index type )
25 {
26  if( !Markers )
27  return false;
28 
29  auto const & [ begin, end ] = Markers->equal_range( type );
30  for( auto it = begin; it != end; ++it )
31  {
32  auto & marker = it->second;
33  if( marker->HasResource( this, path ) )
34  return true;
35  }
36 
37  return false;
38 }
39 
40 void VirtualResourceProvider::each_resource( std::type_index type, std::function< void( ResourcePath const & ) > const & f )
41 {
42  if( !Markers )
43  return;
44 
45  auto const & [ begin, end ] = Markers->equal_range( type );
46  for( auto it = begin; it != end; ++it )
47  {
48  auto & marker = it->second;
49  marker->EachResource( this, f );
50  }
51 }
52 
53 void VirtualResourceProvider::each_type( std::function< void( std::type_index type ) > const & f )
54 {
55  if( !Markers )
56  return;
57 
58  for( auto it = Markers->begin(); it != Markers->end(); ++it )
59  f( it->second->GetType() );
60 }
61 
62 std::pair< void *, Instance * > VirtualResourceProvider::create_resource( ResourcePath const & path, std::type_index type, ResourcesRoot * parent )
63 {
64  if( !Markers )
65  return std::pair< void *, Instance * >( nullptr, nullptr );
66 
67  auto const & [ begin, end ] = Markers->equal_range( type );
68  for( auto it = begin; it != end; ++it )
69  {
70  auto & marker = it->second;
71  if( marker->HasResource( this, path ) )
72  return marker->MakeResource( this, parent, path );
73  }
74 
75  return std::pair< void *, Instance * >( nullptr, nullptr );
76 }
77 
78 }