Back to index

nux  3.0.0
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends
nux::TResourceCache< IdType, ResourceType > Class Template Reference

#include <GLResourceManager.h>

Inheritance diagram for nux::TResourceCache< IdType, ResourceType >:
Inheritance graph
[legend]
Collaboration diagram for nux::TResourceCache< IdType, ResourceType >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TResourceCache ()
void Flush ()
void AddCachedResource (const IdType &Id, ObjectPtr< ResourceType > Resource)
ObjectPtr< ResourceType > FindCachedResourceById (const IdType &Id)
void FlushResourceId (const IdType &Id)
 Remove a cached resource from the cache.
virtual void FlushResource (CachedResourceData *Resource)
virtual void InitializeResourceFactories ()=0
std::vector< NResourceFactory * > & GetResourceFactories (void)
std::vector< NResourceUpdater * > & GetResourceUpdaters (void)

Public Attributes

std::map< IdType, ObjectPtr
< ResourceType > > 
ResourceMap
std::vector< NResourceFactory * > ResourceFactories
std::vector< NResourceUpdater * > ResourceUpdaters

Protected Member Functions

virtual void FreeResource (ResourceData *Resource)

Protected Attributes

CachedResourceDataFirstResource

Friends

class CachedResourceData

Detailed Description

template<typename IdType, typename ResourceType>
class nux::TResourceCache< IdType, ResourceType >

Definition at line 256 of file GLResourceManager.h.


Constructor & Destructor Documentation

template<typename IdType, typename ResourceType>
nux::TResourceCache< IdType, ResourceType >::TResourceCache ( ) [inline]

Definition at line 268 of file GLResourceManager.h.

      :   NResourceSet()
    {}

Member Function Documentation

template<typename IdType, typename ResourceType>
void nux::TResourceCache< IdType, ResourceType >::AddCachedResource ( const IdType &  Id,
ObjectPtr< ResourceType >  Resource 
) [inline]

Definition at line 290 of file GLResourceManager.h.

    {
      typedef std::map< IdType, ObjectPtr< ResourceType > >  MapType;
      ResourceMap.insert(typename MapType::value_type(Id, Resource));
      Resource->_cached = 1;
    }
template<typename IdType, typename ResourceType>
ObjectPtr<ResourceType> nux::TResourceCache< IdType, ResourceType >::FindCachedResourceById ( const IdType &  Id) [inline]

Definition at line 297 of file GLResourceManager.h.

    {
      typedef std::map< IdType, ObjectPtr< ResourceType > >  MapType;
      typename MapType::iterator it = ResourceMap.find(Id);

      if (it != ResourceMap.end())
        return(*it).second;

      return ObjectPtr<ResourceType> (0);
    }

Here is the caller graph for this function:

template<typename IdType, typename ResourceType>
void nux::TResourceCache< IdType, ResourceType >::Flush ( ) [inline, virtual]

Reimplemented from nux::NResourceSet.

Definition at line 272 of file GLResourceManager.h.

    {
      // See the language FAQ 35.18 at http://www.parashift.com/c++-faq-lite/templates.html  for why the "typename".
      typename std::map< IdType, ObjectPtr< ResourceType > >::iterator It;

      for (It = ResourceMap.begin(); It != ResourceMap.end(); It++)
      {
//         ObjectPtr< ResourceType >      CachedResource = (*It).second;
//         CachedResource->_cached = 0;
//         CachedResource.Release();
        (*It).second->_cached = 0;
        (*It).second.Release();
      }

      // Erases all elements from the map.
      ResourceMap.clear();
    }

Here is the caller graph for this function:

template<typename IdType, typename ResourceType>
virtual void nux::TResourceCache< IdType, ResourceType >::FlushResource ( CachedResourceData Resource) [inline, virtual]

Reimplemented from nux::NResourceSet.

Definition at line 329 of file GLResourceManager.h.

    {
      typedef std::map< IdType, ObjectPtr< ResourceType > >  MapType;
      typename MapType::iterator it;

      for (it = ResourceMap.begin(); it != ResourceMap.end(); it++)
      {
        ObjectPtr< ResourceType >  CachedResource = (*it).second;

        if (CachedResource == Resource)
        {
          ResourceMap.erase(it);
          CachedResource->_cached = 0; // Make sure that if the following line deletes the resource, it doesn't try to remove itself from the TDynamicMap we're iterating over.
          return;
        }
      }
    }
template<typename IdType, typename ResourceType>
void nux::TResourceCache< IdType, ResourceType >::FlushResourceId ( const IdType &  Id) [inline]

Remove a cached resource from the cache.

The cached resource may still have references to it. The resource internal flag "_cached" is set to false.

Definition at line 312 of file GLResourceManager.h.

    {
      ObjectPtr<ResourceType>      CachedResource(0);

      typedef std::map<IdType, ObjectPtr<ResourceType> >  MapType;
      typename MapType::iterator it = ResourceMap.find(Id);

      if (it != ResourceMap.end())
        CachedResource = (*it).second;

      if (CachedResource.IsValid())
      {
        ResourceMap.erase(it);
        CachedResource->_cached = false;
      }
    }

Here is the caller graph for this function:

virtual void nux::NResourceSet::FreeResource ( ResourceData Resource) [inline, protected, virtual, inherited]

Definition at line 95 of file GLResourceManager.h.

{}
template<typename IdType, typename ResourceType>
std::vector<NResourceFactory *>& nux::TResourceCache< IdType, ResourceType >::GetResourceFactories ( void  ) [inline]

Definition at line 350 of file GLResourceManager.h.

    {
      return(ResourceFactories);
    }
template<typename IdType, typename ResourceType>
std::vector<NResourceUpdater *>& nux::TResourceCache< IdType, ResourceType >::GetResourceUpdaters ( void  ) [inline]

Definition at line 354 of file GLResourceManager.h.

    {
      return(ResourceUpdaters);
    }

Here is the caller graph for this function:

template<typename IdType, typename ResourceType>
virtual void nux::TResourceCache< IdType, ResourceType >::InitializeResourceFactories ( ) [pure virtual]

Implemented in nux::NResourceCache.


Friends And Related Function Documentation

friend class CachedResourceData [friend, inherited]

Definition at line 100 of file GLResourceManager.h.


Member Data Documentation

Definition at line 86 of file GLResourceManager.h.

template<typename IdType, typename ResourceType>
std::vector<NResourceFactory *> nux::TResourceCache< IdType, ResourceType >::ResourceFactories

Definition at line 262 of file GLResourceManager.h.

template<typename IdType, typename ResourceType>
std::map< IdType, ObjectPtr< ResourceType > > nux::TResourceCache< IdType, ResourceType >::ResourceMap

Definition at line 259 of file GLResourceManager.h.

template<typename IdType, typename ResourceType>
std::vector<NResourceUpdater *> nux::TResourceCache< IdType, ResourceType >::ResourceUpdaters

Definition at line 265 of file GLResourceManager.h.


The documentation for this class was generated from the following file: