/* 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_FORMATEXCEPTION_HPP
#define NMM_FORMATEXCEPTION_HPP NMM_FORMATEXCEPTION_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/comm/serialize/SerializedException.hpp"
#include "Parameter.hpp"
#include "nmm/utils/string_utils.hpp"

#include "visibility.hpp"

namespace NMM
{

  /** Superclass for exceptions concerning formats.
   */
  class DLLEXPORT FormatException  : public SerializedException
  {
  public:

    /** Constructor.
     *
     * @param message Exception message
     */
    FormatException(const std::string& message = "") 
      : SerializedException( string("FormatException : ") + message) {};

    /** Virtual Destructor.
     */
    virtual ~FormatException(){};
    
  };

  /** Superclass for exceptions concerning parameter of formats.
   */
  class DLLEXPORT ParameterException : public FormatException
  {
  public:
     
    /** Constructor.
     *
     * @param message Exception message
     */
    ParameterException(const std::string& message = "") 
      : FormatException( string("ParameterException : ") + message) {};

    /** Virtual Destructor.
     */
    virtual ~ParameterException(){};

  };

  /** Exception throwm if a parameter does not exist.
   */
  class DLLEXPORT ParameterExceptionNotExist : public ParameterException
  {
  public:
    /** Constructor.
     *
     * @param message Exception message
     */
    ParameterExceptionNotExist(const std::string& message = "")
      : ParameterException( string("FormatException : ") + message) {};
    
    /** Virtual Destructor.
     */
    virtual ~ParameterExceptionNotExist(){};
  };

  /** Exception throwm if weight of parameter does not match given weight range.
   */
  class DLLEXPORT ParameterExceptionWeightRangeError : public ParameterException
  {
  public:
    float m_weight; ///< weight that does not match

    /** Constructor.
     *
     * @param parameter_name name of parameter that caused the exception
     * @param weight parameter weight that does not match
     */
    ParameterExceptionWeightRangeError(const string& parameter_name, float weight)
      : ParameterException("ParameterExceptionFalseType: " + parameter_name + "@" + ftoa(weight)) {} ;
    
    /** Virtual Destructor.
     */
    virtual ~ParameterExceptionWeightRangeError(){};

  };


  /** Exception throwm if parameter has wrong type.
   */
  class DLLEXPORT ParameterExceptionFalseType : public ParameterException
  {
  public:
    Parameter * m_parameter_false; ///< parameter that caused the exception
    Parameter::PType m_original;   ///< type parameter should have
    Parameter::PType m_fail;       ///< type parameter has

    /** Constructor.
     *
     * @param parameter_name name of parameter that caused the exception
     */
    ParameterExceptionFalseType(const char * parameter_name);

    
    /** Constructor.
     *
     * @param parameter_name name of parameter that caused the exception
     * @param parameter_false pointer to parameter that had false type
     */
    ParameterExceptionFalseType(const char * parameter_name, Parameter * parameter_false);

    /** Constructor.
     *
     * @param parameter_name name of parameter that caused the exception
     * @param first first type that does not match
     * @param second second type that does not match
     */
    ParameterExceptionFalseType(const string& parameter_name, Parameter::PType first, Parameter::PType second)
      : ParameterException("ParameterExceptionFalseType: " + parameter_name + " : " + itoa(first) + " != " + itoa(second)) {} ;

    /** Virtual Destructor.
     */
    virtual ~ParameterExceptionFalseType(){};

  };

}


#include "nmm/nmm_suffix.hpp"

#endif
