Repository: xbmc/xbmc
File: xbmc/filesystem/DirectoryCache.h (C/C++)

Code before:
{
  class CDirectoryCache
  {
    class CDir
    {
    public:
      explicit CDir(CacheType cacheType);
      CDir(CDir&& dir) = default;
      CDir& operator=(CDir&& dir) = default;
      virtual ~CDir();

      void SetLastAccess(unsigned int &accessCounter);
      unsigned int GetLastAccess() const { return m_lastAccess; }

      std::unique_ptr<CFileItemList> m_Items;
      CacheType m_cacheType;

    private:
      CDir(const CDir&) = delete;
      CDir& operator=(const CDir&) = delete;
      unsigned int m_lastAccess;
    };
  public:
    CDirectoryCache(void);
    virtual ~CDirectoryCache(void);
    bool GetDirectory(const CURL& urlPath, CFileItemList& items, bool retrieveAll = false);
    void SetDirectory(const CURL& urlPath, const CFileItemList& items, CacheType cacheType);
    void ClearDirectory(const CURL& urlPath);
    void ClearFile(const CURL& urlFile);
    void ClearSubPaths(const CURL& urlPath);
    void Clear();
    void AddFile(const CURL& urlFile);
    bool FileExists(const CURL& urlFile, bool& bInCache);
#ifdef _DEBUG
    void PrintStats() const;
#endif
  protected:
    void InitCache(const std::set<std::string>& dirs);
    void ClearCache(std::set<std::string>& dirs);
    void CheckIfFull();

    std::map<std::string, CDir> m_cache;

    mutable CCriticalSection m_cs;

    unsigned int m_accessCounter;

#ifdef _DEBUG
    unsigned int m_cacheHits;
    unsigned int m_cacheMisses;
#endif

Review comment (suggestion):
We should probably add `class CURL;` right below `class CFileItem;` forward declaration. CURL is forward-declared in IDirectory.h but now that it's used here it can also be declared in this file in case the IDirectory.h include is ever removed.

Code after:
{
  class CDirectoryCache
  {
    class CDir
    {
    public:
      explicit CDir(CacheType cacheType);
      CDir(CDir&& dir) = default;
      CDir& operator=(CDir&& dir) = default;
      virtual ~CDir();

      void SetLastAccess(unsigned int &accessCounter);
      unsigned int GetLastAccess() const { return m_lastAccess; }

      std::unique_ptr<CFileItemList> m_Items;
      CacheType m_cacheType;

    private:
      CDir(const CDir&) = delete;
      CDir& operator=(const CDir&) = delete;
      unsigned int m_lastAccess;
    };
  public:
    CDirectoryCache(void);
    virtual ~CDirectoryCache(void);
    bool GetDirectory(const CURL& url, CFileItemList& items, bool retrieveAll = false);
    void SetDirectory(const CURL& url, const CFileItemList& items, CacheType cacheType);
    void ClearDirectory(const CURL& url);
    void ClearFile(const CURL& url);
    void ClearSubPaths(const CURL& url);
    void Clear();
    void AddFile(const CURL& url);
    bool FileExists(const CURL& url, bool& foundInCache);
#ifdef _DEBUG
    void PrintStats() const;
#endif
  protected:
    void InitCache(const std::set<std::string>& dirs);
    void ClearCache(std::set<std::string>& dirs);
    void CheckIfFull();

    std::map<std::string, CDir> m_cache;

    mutable CCriticalSection m_cs;

    unsigned int m_accessCounter;

#ifdef _DEBUG
    unsigned int m_cacheHits;
    unsigned int m_cacheMisses;
#endif