/* 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_R_FPARAMETER_HPP
#define _NMM_R_FPARAMETER_HPP

#include "nmm/nmm_prefix.hpp"

#include "Parameter.hpp"

namespace NMM {

  /** This class stores ranges of float parameters.
   *  The range itself is implemented by the R_FLOAT class.
   */
  
  class R_FParameter : public Parameter 
  {
    
  protected:

    r_float_list m_value_list; ///< The STL-List of the range values.
    mutable list<NMM::R_FLOAT *>::const_iterator m_counter;  ///< list of R_FLOATs
    float m_default_value;  ///< The default value
    NMM::R_FLOAT * m_default_range;  ///< The default range

    /** This function computes the value of the fraction. 
     *
     *   (HighWeight - LowWeight)
     *   ------------------------
     *   (HighValue  - LowValue)
     * 
     * for the specified R_FLOAT range.
     * @param range a R_FLOAT range.
     * @return the value of the fraction.
     */
    float computeFactor(NMM::R_FLOAT * range) const;

    /** Tests if ranges intersect.
     *
     * This function checks if there is an intersection between the
     * interval (m_lValue - m_hValue) and (lValue - hValue).
     * Note: The difference to the inherited function 
     *       bool isValueIncluded(void *, void *) is that you have
     *       to specify both of the interval limits instead of
     *       iterating the hole m_value_list!
     *
     * @param m_lValue the lower bound of the first range.
     * @param m_hValue the upper bound of the first range.
     * @param lValue the lower bound of the second range.
     * @param hValue the upper bound of the second range.
     * @return true if the intersection is not empty, otherwise false.
     */
    bool isRangeIntersection(float m_lValue, float m_hValue, float lValue, float hValue) const;
    
  public:
    
    /** The default Constructor.
     *
     * @param parameter_name the name of the parameter.
    */
    R_FParameter(const string & parameter_name = "");
    
    /** Constructor with an additional parameter pValue that is directly added to the Value-List.
     *
     * @param parameter_name the name of the parameter.
     * @param pValue a value.
    */
    R_FParameter(const string & parameter_name, void * pValue);
    
    /** The default Destructor.
    */
    virtual ~R_FParameter();
    
    /** Adds value.
     *
     * Adds the value specified in pValue to the set or set of range 
     * of this parameter. This is an abstract function an must be 
     * implemented in every inherited class to cast the void-ptr in
     * the proper type.
     *
     * @param pValue pointer to value 
     */
    virtual void addValue(void *pValue);
    
    /** Adds value.
     *
     * Adds the value specified in value to the set or set of range 
     * of this parameter. This is an abstract function an must be 
     * implemented in every inherited class to cast the void-ptr in
     * the proper type.
     *
     * @param value pointer to value
     */
    virtual void addValue(NMM::R_FLOAT *value);

    /** Checks if value is included.
     *
     * @param lValue pointer to lowest value
     * @param hValue pointer to highest value
     * @return true if value is included, false otherwise.
     */
    virtual bool isValueIncluded(void *lValue,void *hValue) const;
    
    /** Checks if value is included.
     *
     * @param lValue lowest value
     * @param hValue highest value
     * @return true if value is included, false otherwise.
     */
    virtual bool isValueIncluded(float lValue, float hValue) const;

    /** Checks if ranges are matching.
     *
     * @param lValue lowest value
     * @param hValue highest value
     * @return true if ranges are matching, false otherwise.
     */
    virtual bool isRangeMatching(float lValue, float hValue) const;

    /** Checks if ranges are identical.
     *
     * @param lValue lowest value
     * @param hValue highest value
     * @return true if ranges are identical, false otherwise.
     */
    virtual bool isRangeIdentical(float lValue, float hValue) const;

    /** Checks if value is included.
     *
     * @param pValue pointer to value
     * @return true if value is included, false otherwise.
     */
    virtual bool isValueIncluded(void *pValue) const;

    /** Checks if value is included.
     *
     * @param value float value
     * @return true if value is included, false otherwise.
     */
    virtual bool isValueIncluded(float value) const;
    
    /** Returns pointer to next value.
     *
     * @return pointer to next value
     */
    virtual void *nextValue() const;
    
    /** Prints out every Parameter-Value.	
     *
     * Debugging method, prints out every Parameter-Value.
     */
    virtual void showParameter() const;

    /** Prints out every Parameter-Value to the given ostream.
     *
     * @param os ostream to write parameter to
     */
    virtual ostream& showParameter(ostream& os) const;

    /** Prints out every Parameter-Value to the given ostream verbose.
     *
     * @param os ostream to write parameter to
     */
    virtual ostream& showParameterVerbose(ostream& os) const;

    /** Duplicates parameter.
     *
     * @return pointer to duplicated parameter
     */
    virtual Parameter * duplicate() const;

    /** Returns intersection between this and given parameter.
     *
     * This function creates a new parameter from the current
     * instance and the argument of the function by computing
     * intersections from the intervals.
     *
     * @param reference a parameter
     * @return the new "intersected" parameter
     **/
    virtual Parameter * getIntersection(const Parameter * reference) const;

    /** Returns the weight of the argument pValue.
     *
     * @param weight the desired value.
     * @return float the weight of the value.
     */
    virtual float getWeight(void *weight) const;

    /** Returns the number of values stored in the data-structures.
     *
     * return the number of values
    **/
    virtual uint getNumberOfValues() const;

    /** Returns first value.
     *
     * This function returns the first value stored in the
     * appropriate set and increases the internal value counter.
     * If you want to iterate over all values of a parameter, this
     * function guaranties to start always with the first value. After a
     * call of this function, just use the nextValue() function above.
     *
     * @return pointer to first value
    **/
    virtual void *getFirstValue() const;

    /** Tests if parameter are identical.
     *
     * Checks if the given argument has the same co-domain.
     *
     * @param reference the parameter which will be compared with.
     * @return true if the given parameter has the same co-domain, otherwise false.
     */
    virtual bool isParameterIdentical(const Parameter *reference) const;

     /** Tests if parameter are matching.
      *
      * Checks if the given argument has an intersection in the co-domain of the values.
      *
      * @param reference the parameter that will be matched.
      * @return true if the parameters are matching, otherwise false.
      */
    virtual bool isParameterMatching(const Parameter *reference) const;

    /** Returns standardized weight.
     *
     * This functions computes a standardized weight for the included
     * co-domain, depending on the parameter-type.
     *
     * @return the standardized weight
     */
    virtual float getStandardizedWeight() const;

    /** Get default value.
     *
     * @return default value
     */
    virtual float getDefaultValue() const;

    /** Set default value.
     *
     * @param value default float value
     */
    virtual void setDefaultValue(float value);

    /** Get lowest value.
     *
     * @return lowest value
     */
    virtual float getLowestValue() const;

    /** Get heighest value.
     *
     * @return heighest value
     */
    virtual float getHighestValue() const;

    /** Get RFloat value list.
     *
     * @return RFloat value list
     */
    virtual const r_float_list & getRFloatValueList() const;

    /** Get default range.
     *
     * @return default range
     */
    virtual NMM::R_FLOAT * getDefaultRange() const;

    /** Set input stream.
     *
     * @param stream input stream to set
     */
    virtual void fromStream(IValueStream& stream) ;
    
    /** Set output stream.
     *
     * @param stream output stream to set
     */
    virtual void toStream(OValueStream& stream)  const ;
  };
}
#include "nmm/nmm_suffix.hpp"

#endif
