#ifndef CLUSTER_CLUSTER_LOADER_HH
# define CLUSTER_CLUSTER_LOADER_HH

# include "utils/GlobalFactory.hh"
# include "utils/dummyConfLoader.hh"

# include "AbstractClassifier.hh"

# include <list>
/** @brief Classifier generator from configuration file
 *
 * This class is able to produce new classifiers based on a
 * configuration file.
 *
 * @author Frederic Py <fpy@mbari.org>
 */
class ClusterLoader :public dummyConfLoader {
public:
  /** @brief Default constructor
   */
  ClusterLoader() {}
  /** @brief Destructor
   */
  ~ClusterLoader() {
    clear();
  }

  /** @brief Check for emptyness
   *
   * Thsis method is used to check if there's any new classifier
   * produced
   *
   * @retval true No classifier in stock
   * @retval false else
   */
  bool empty() const {
    return m_loaded.empty();
  }
  /** @brief Get production
   *
   * @param output destination of the production
   *
   * This function get all classifiers last produced and put them on @e output
   */
  void flushTo(std::list<AbstractClassifier *> &output) {
    output.splice(output.end(), m_loaded);
  }

  /** @brief Remove oldest classifier
   *
   * This method rtemove the oldest classifier in stock 
   *
   * @pre The stock is not empty
   * @return The classifier that was removed from stock
   *
   * @sa bool empty() const
   */
  AbstractClassifier *pop_front() {
    AbstractClassifier *res = m_loaded.front();
    m_loaded.pop_front();
    return res;
  }

  /** @brief destroy all stocks
   *
   * This method destroy all the classifiers actually in stock
   * @post Stock are empty
   */
  void clear();

private:
  /** @brief New classifier to produce
   *
   * This method is called during configuration parsing to produce
   * a new classfier
   *
   * @param args parsing result used to produce the new classifier
   * 
   * @pre @e args is valid 
   * @post A new classifier is in stock
   *
   * @throw ParseError @e args is not valid ort a problem occured
   */
  void parseEvent(ArgList const &arg) /* throw(ParseError) */;

  /** @brief Classifiers factory
   */
  SingletonUse< GlobalFactory<AbstractClassifier, ArgList> > m_factory;
  /** @brief production stock
   */
  std::list<AbstractClassifier *> m_loaded;
}; // ClusterLoader

#endif // CLUSTER_CLUSTER_LOADER_HH
