/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2022,  Regents of the University of California,
 *                           Arizona Board of Regents,
 *                           Colorado State University,
 *                           University Pierre & Marie Curie, Sorbonne University,
 *                           Washington University in St. Louis,
 *                           Beijing Institute of Technology,
 *                           The University of Memphis.
 *
 * This file is part of NFD (Named Data Networking Forwarding Daemon).
 * See AUTHORS.md for complete list of NFD authors and contributors.
 *
 * NFD is free software: you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef NFD_DAEMON_TABLE_STRATEGY_INFO_HOST_HPP
#define NFD_DAEMON_TABLE_STRATEGY_INFO_HOST_HPP

#include "fw/strategy-info.hpp"

#include <unordered_map>

namespace nfd {

/** \brief Base class for an entity onto which StrategyInfo items may be placed
 */
class StrategyInfoHost
{
public:
  /** \brief Get a StrategyInfo item
   *  \tparam T type of StrategyInfo, must be a subclass of fw::StrategyInfo
   *  \return an existing StrategyInfo item of type T, or nullptr if it does not exist
   */
  template<typename T>
  T*
  getStrategyInfo() const
  {
    static_assert(std::is_base_of_v<fw::StrategyInfo, T>);

    auto it = m_items.find(T::getTypeId());
    if (it == m_items.end()) {
      return nullptr;
    }
    return static_cast<T*>(it->second.get());
  }

  /** \brief Insert a StrategyInfo item
   *  \tparam T type of StrategyInfo, must be a subclass of fw::StrategyInfo
   *  \return a new or existing StrategyInfo item of type T,
   *          and true for new item, false for existing item
   */
  template<typename T, typename ...A>
  std::pair<T*, bool>
  insertStrategyInfo(A&&... args)
  {
    static_assert(std::is_base_of_v<fw::StrategyInfo, T>);

    auto& item = m_items[T::getTypeId()];
    bool isNew = item == nullptr;
    if (isNew) {
      item = make_unique<T>(std::forward<A>(args)...);
    }
    return {static_cast<T*>(item.get()), isNew};
  }

  /** \brief Erase a StrategyInfo item
   *  \tparam T type of StrategyInfo, must be a subclass of fw::StrategyInfo
   *  \return number of items erased
   */
  template<typename T>
  size_t
  eraseStrategyInfo()
  {
    static_assert(std::is_base_of_v<fw::StrategyInfo, T>);

    return m_items.erase(T::getTypeId());
  }

  /** \brief Clear all StrategyInfo items
   */
  void
  clearStrategyInfo()
  {
    m_items.clear();
  }

private:
  std::unordered_map<int, unique_ptr<fw::StrategyInfo>> m_items;
};

} // namespace nfd

#endif // NFD_DAEMON_TABLE_STRATEGY_INFO_HOST_HPP
