/* Blinker
   Copyright 2011-2019 Stefan Schuermans <stefan@blinkenarea.org>
   Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
   a blinkenarea.org project */

#ifndef BLINKER_LISTTRACKER_H
#define BLINKER_LISTTRACKER_H

#include <list>
#include <string>

#include "Directory.h"
#include "File.h"

namespace Blinker {

/**
 * @brief tracker of a list kept in a directory
 * @param[in] PARENT type of parent object
 * @param[in] TYPE type of objects to allocate for list entries
 * @param[in] FIDI if to track files or subdirs in directory
                   (File or Directory)
 */
template<typename PARENT, typename TYPE, typename FIDI>
class ListTracker
{
public:
  /// list entry
  struct Entry {
    std::string m_name;  ///< name of list entry
    TYPE        *m_pObj; ///< object
  };

  /// list
  typedef std::list<Entry> List;

  /// list iterator
  typedef typename List::const_iterator ListIt;

  /// reverse list iterator
  typedef typename List::const_reverse_iterator ListRevIt;

public:
  /**
   * @brief constructor
   * @param[in] parent parent object
   * @param[in] dir directory containing list and begin tracked
   */
  ListTracker(PARENT &parent, const Directory &dir);

  /// destructor
  virtual ~ListTracker();

private:
  /// copy constructor disabled
  ListTracker(const ListTracker &that);

  /// assignment operator disabled
  const ListTracker & operator=(const ListTracker &that);

public:
  /// initialize list by reading directory
  void init();

  /// clear list
  void clear();

  /// check for update of configuration
  void updateConfig();

protected:
  /// light update of list, i.e. check all entries in current list
  void updateListLight();

  /// full update of list, i.e. scan files/subdirs in list directory
  void updateListFull();

public:
  PARENT    &m_parent; ///< parent object
  Directory m_dir;     ///< directory containing list and being tracked
  List      m_list;    ///< list begin tracked
}; // class ListTracker<PARENT, TYPE, FIDI>

} // namespace Blinker

#endif // #ifndef BLINKER_LISTTRACKER_H

