/* Network-Integrated Multimedia Middleware (NMM)
 * http://www.motama.com/nmm.html
 *  
 * Copyright (C) 2006-2007
 * Motama GmbH, Saarbruecken, Germany
 * http://www.motama.com
 *  
 * This file is part of NMM. 
 * 
 * NMM 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; only version 2 of the License.      
 * 
 * NMM 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 NMM; if not, write to the Free Software Foundation,    
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#ifndef NMM_FORMAT_STRATEGY_MAP_HPP
#define NMM_FORMAT_STRATEGY_MAP_HPP NMM_FORMAT_STRATEGY_MAP_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/comm/format/Format.hpp"
#include "nmm/comm/TSDescription.hpp"

#include <map>
#include <list>

#include "visibility.hpp"

namespace NMM {
  
  /** Format strategy map.
   * Maps NMM formats to transport strategy types. Such maps are used to determine which transport
   * strategy types support a given format.
   */
  class DLLEXPORT FormatStrategyMap {
  public:
    /** @name Constructor & Destructor
     */
    //@{
    /** Default constructor.
     */
    FormatStrategyMap();
    
    /** Virtual destructor.
     */
    virtual ~FormatStrategyMap();
    //@}
    
    /** @name Format Map
     */
    //@{
    /** Adds supported format.
     *
     * This method declares that the given transport strategy supports the given format by adding
     * an entry to the internal format map.
     *
     * @param strategy_type Strategy type
     * @param format The format to add
     */
    void addSupportedFormat(const TSDescription& strategy_type, const Format& format);

    /** Returns list of supported strategies.    
     *
     * This method returns the list of transport strategies that support the given format.
     *
     * @param format Format to be suported
     * @return the list of transport strategies that support the given format.
     */
    std::list<TSDescription> getSupportedStrategies(const Format& format) const;

    /** Returns list of supported formats.
     *
     * This method returns the list of formats which are supported by the given transport strategy.
     *
     * @param strategy_type strategy type 
     * @return list of formats which are supported by the given transport strategy.
     */
    std::list<Format*> getSupportedFormats(const TSDescription& strategy_type);
    
    /** Removes strategy type.
     *
     * This method removes the given strategy type from the map.
     *
     * @param strategy_type Strategy type to remove from map
     */
    void removeStrategyType(const TSDescription& strategy_type);    
    
    /** Tests if a combination of format and transport strategy is supported.
     *
     * @param format Format to check
     * @param strategy_type Transport strategy type
     * @return true iff a combination of format and transport straegy is supported, false otherwise
     */
    bool isSupported(const Format& format, const TSDescription& strategy_type);
    //@}
    
    /** This method displays the map on an output stream.
     *
     * @param out ostream to write map to.
     */
    void display(ostream& out);
    
  private:
    typedef std::pair<Format, TSDescription> FormatMapEntry;
    typedef std::list<FormatMapEntry>  FormatMap;                ///< Type to map a format to a set of strategies
    typedef FormatMap::iterator        FormatMapIterator;
    typedef FormatMap::const_iterator  FormatMapConstIterator;
    
    FormatMap __format_map;                                      ///< The format map
  };
}

#include "nmm/nmm_suffix.hpp"

#endif


