/* 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_IPARAMETER_HPP
#define _NMM_R_IPARAMETER_HPP

#include "nmm/nmm_prefix.hpp"

#include "Parameter.hpp"

namespace NMM {

/** This class stores ranges of INT32 parameters.
 *  The range itself is implemented by the class R_INT.
 **/

  class R_IParameter : public Parameter {
    
  protected:

    r_int32_t_list m_value_list; ///< The STL-List of the range-values.
    mutable list<R_INT *>::const_iterator m_value_counter;  ///<  Private Variable for browsing the STL-List Value-List
    int32_t m_default_value;  ///< The default value
    R_INT * 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 param  a R_FLOAT range.
     * @return the value of the fraction.
     */
    virtual float computeFactor(R_INT * param) const;

    /** Tests if ranges are intersected.
     *
     * 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(int32_t m_lValue, int32_t m_hValue, int32_t lValue, int32_t hValue) const;

  public:
    /** The default Constructor.
     *
     * @param parameter_name the name of the parameter.
     */
    R_IParameter(const string & parameter_name = "");
    
    /** Constructor with a parameter pValue that is directly added to the Value-List.
     *
     * @param parameter_name the name of the parameter.
     * @param pValue an R_INT pointer.
    */
    R_IParameter(const string & parameter_name, void * pValue);
    
    /** The default Destructor.
    */
    ~R_IParameter();
    
    /** Adds Value.
     * 
     * @param pValue pointer to value
     */
    virtual void addValue(void *pValue);
    
    /** Adds Value.
     * 
     * @param value pointer to value
     */
    virtual void addValue(R_INT *value);

    /** 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 inter32_t value
     * @return true if value is included, false otherwise.
     */
    virtual bool isValueIncluded(int32_t value) const;
    
    /** Checks if value is included.
     * 
     * @param lValue lower value
     * @param hValue higher value
     * @return true if value is included, false otherwise.
     */
    virtual bool isValueIncluded(void *lValue,void *hValue) const;

    /** Checks if value is included.
     * 
     * @param lValue lower value
     * @param hValue higher value
     * @return true if value is included, false otherwise.
     */
    virtual bool isValueIncluded(int32_t lValue, int32_t hValue) const;
    
    /** Checks if ranges are matching.
     * 
     * @param lValue lower value
     * @param hValue higher value
     * @return true if ranges are matching, false otherwise.
     */
    virtual bool isRangeMatching(int32_t lValue, int32_t hValue) const;
    
    /** Checks if ranges are matching.
     * 
     * @param lValue lower value
     * @param hValue higher value
     * @return true if ranges are matching, false otherwise.
     */
    virtual bool isRangeIdentical(int32_t lValue, int32_t hValue) const;
    
    /** Prints parameter.
     */
    virtual void showParameter() const;
    
    /** Prints parameter to given output stream.
     *
     * @param output_stream ostream to print parameter to
     */
    virtual ostream& showParameter(ostream& output_stream) const;
    
    /** Prints parameter verbose to given output stream.
     *
     * @param output_stream ostream to print parameter to
     */
    virtual ostream& showParameterVerbose(ostream& output_stream) const;

    /** Returns pointer to next value.
     */
    virtual void *nextValue() const;

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

    /** Returns intersection of 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 Weight.
     *
     * This function computes the range-value of the parameter value.
     *
     * @param pValue the value that will be "new-weighted".
     * @return the new weight.
     */
    virtual float getWeight(void *pValue) const;

    /** Gets number of values.
     *
     * @return number of values
     */
    virtual uint getNumberOfValues() const;

    /** Checks if parameter is included.
     *
     * @param reference pointer to parameter
     * @return true if parameter is included, false otherwise.
     */
    virtual bool isParameterIdentical(const Parameter *reference) const;

     /** Checks if parameters match.
     *
     * @param reference pointer to parameter
     * @return true if parameter matches each other, false otherwise.
     */
     virtual bool isParameterMatching(const Parameter *reference) const;

    /** Returns pointer to first value.
     *
     * @return pointer to first value
     */
    virtual void *getFirstValue() const;
    
    /** Returns standardized weight.
     *
     * @return standardized weight
     */
    virtual float getStandardizedWeight() const;

    /** Sets default value.
     *
     * @param value int32_t value
     */
    virtual void setDefaultValue(int32_t value);

    /** Returns default value.
     *
     * @return int32_t value
     */
    virtual int32_t getDefaultValue() const;

    /** Returns lowest value.
     *
     * @return lowest value
     */
    virtual int32_t getLowestValue() const;

    /** Returns highest value.
     *
     * @return highest value
     */
    virtual int32_t getHighestValue() const;

    /** Returns RIint value list.
     *
     * @return r_int32_t list
     */
    virtual const r_int32_t_list & getRIntValueList() const;

    /** Returns default range.
     *
     * @return R_INT pointer.
     */
    virtual R_INT * getDefaultRange() const;
    
    /** Sets input stream.
     *
     * @param stream input stream to set
     */
    virtual void fromStream(IValueStream& stream) ;
    
    /** Sets output stream.
     *
     * @param stream output stream to set
     */
    virtual void toStream(OValueStream& stream)  const ;
  };
}
#include "nmm/nmm_suffix.hpp"

#endif
