/* 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_INTERPOLATOR_HPP_
#define _NMM_INTERPOLATOR_HPP_ _NMM_INTERPOLATOR_HPP_

#include "nmm/nmm_prefix.hpp"

#include "nmm/utils/time/Time.hpp"

namespace NMM {

  /**
   * Abstract base class for all interpolators. Interpolators compute
   * a current value by taking the start_value and end_value and
   * applying a specific interpolation in regards to start_time and
   * end_time and the current_time
   */
  class Interpolator 
  {
  public:
    Interpolator() : start_value(0.0f), end_value(0.0f)  { }
    virtual ~Interpolator() { }

    /** set the start time */
    void setStartTime(const Time& time) { start_time = time; }

    /** set the end time */
    void setEndTime(const Time& time)   { end_time   = time; }

    /** set the start value */
    void setStartValue(const float& time) { start_value = time; }

    /** set the end value */
    void setEndValue(const float& time)   { end_value   = time; }

    /** returns true if end time has been reached according to given time */
    bool hasReachedEndTime(const Time& time) { return ( time >= end_time ? true : false ); }

    /** returns true if all necessary parameters have been specified */
    bool isConfigured() { return ( ( (start_time != end_time) && (start_value != end_value) ) ? true : false); }

    /** returns the current value */
    float getCurrentValue(const Time& current_time);

    /** abstract method that implements a certain interpolation, e.g. linear */
    virtual float getCurrentInterpolation(const Time& current_time) = 0;

  protected:
    Time start_time;    ///> start time for interpolation, e.g. from a timestamp of a buffer
    Time end_time;      ///> end time for interpolation, e.g. from a timestamp of a buffer
    float start_value;  ///> start value for interpolation; specific for application of interpolator
    float end_value;    ///> end value for interpolation; specific for application of interpolator
  };
}

#include "nmm/nmm_suffix.hpp"

#endif

