StreamResourceProvider.inl
Go to the documentation of this file.
1 namespace iv
2 {
3 
4 template< class TStreamSubprovider, class TClient, class TParserClient >
6 {
7  static_assert( std::is_base_of< TClient, TParserClient >::value, "TParserClient must inherit TClient." );
8 
9  // init directory
10  if( !StreamResourceProvider::Markers )
11  StreamResourceProvider::Markers = new std::unordered_multimap< std::type_index, std::unique_ptr< Marker > >;
12 
13  StreamResourceProvider::Markers->insert( std::pair< std::type_index, std::unique_ptr< Marker > >( typeid( TClient ), new TMarker< TStreamSubprovider, TClient, TParserClient > ) );
14 }
15 
16 template< class TStreamSubprovider, class TClient, class TParserClient >
17 std::pair< void *, Instance * > StreamResourceProvider::TMarker< TStreamSubprovider, TClient, TParserClient>::MakeResource( StreamResourceProvider * provider, ResourcesRoot * root, ResourcePath const & path ) const
18 {
19  auto subprovider = this->GetSubprovider( provider );
20  auto client = root->heap.create< I< TParserClient > >( "", root->instance(), provider, subprovider, path );
21  return std::pair( reinterpret_cast< void * >( static_cast< TClient * >( client ) ), client->instance() );
22 }
23 
24 template< class TStreamSubprovider, class TClient, class TParserClient >
25 void StreamResourceProvider::TMarker< TStreamSubprovider, TClient, TParserClient>::EachResource( StreamResourceProvider * provider, std::function< void( ResourcePath const & path ) > const & f ) const
26 {
27  auto subprovider = this->GetSubprovider( provider );
28  subprovider->each_resource( f );
29 }
30 
31 template< class TStreamSubprovider, class TClient, class TParserClient >
32 bool StreamResourceProvider::TMarker< TStreamSubprovider, TClient, TParserClient>::HasResource( StreamResourceProvider * provider, ResourcePath const & path ) const
33 {
34  auto subprovider = this->GetSubprovider( provider );
35  return subprovider->has_resource( path );
36 }
37 
38 template< class TStreamSubprovider, class TClient, class TParserClient >
39 TStreamSubprovider * StreamResourceProvider::TMarker< TStreamSubprovider, TClient, TParserClient>::GetSubprovider( StreamResourceProvider * provider ) const
40 {
41  auto it = provider->subproviders.find( this );
42  if( it == provider->subproviders.end() )
43  {
44  it = provider->subproviders.insert(
45  std::pair(
46  this,
47  static_cast< TStreamSubprovider * >( provider->heap.create< I< TStreamSubprovider > >( "", provider->instance(), static_cast< StreamResourceProvider const * >( provider ) ) )
48  )
49  ).first;
50  }
51 
52  return reinterpret_cast< TStreamSubprovider * >( it->second );
53 }
54 
55 template< class TStreamSubprovider, class TClient, class TParserClient >
56 std::type_index StreamResourceProvider::TMarker< TStreamSubprovider, TClient, TParserClient>::GetType() const
57 {
58  return typeid( TClient );
59 }
60 
61 }