// file: $isip/class/algo/CoefficientLabel/CoefficientLabel.h
// version: $Id: CoefficientLabel.h 8251 2002-06-29 18:02:58Z picone $
//

// make sure definitions are only made once
//
#ifndef ISIP_COEFFICIENT_LABEL
#define ISIP_COEFFICIENT_LABEL

// isip include files
//
#ifndef ISIP_ALGORITHM_BASE
#include <AlgorithmBase.h>
#endif

#ifndef ISIP_ALGORITHM_DATA
#include <AlgorithmData.h>
#endif

#ifndef ISIP_MEMORY_MANAGER
#include <MemoryManager.h>
#endif

// CoefficientLabel: a class that is used to label feature streams, and
// to change the type of a parameter. this is an internal class used by
// isip_transform that is normally not used by programmers in conventional
// algorithm programming.
//
class CoefficientLabel : public AlgorithmBase {

  //---------------------------------------------------------------------------
  //
  // public constants
  //
  //---------------------------------------------------------------------------
public:
  
  // define the class name
  //
  static const String CLASS_NAME;
  static const String CNAME;

  //----------------------------------------
  //
  // other important constants
  //
  //----------------------------------------

  // define the algorithm choices
  //
  enum ALGORITHM { DATA = 0, DEF_ALGORITHM = DATA };

  // define the implementation choices
  //
  enum IMPLEMENTATION { COPY = 0, DEF_IMPLEMENTATION = COPY };

  // define the type
  //
  enum TYPE { INPUT = 0, OUTPUT, INTERNAL, DEF_TYPE = INTERNAL };

  // define the static NameMap objects
  //
  static const NameMap ALGO_MAP;
  static const NameMap IMPL_MAP;
  static const NameMap TYPE_MAP;

  //----------------------------------------
  //
  // i/o related constants
  //
  //----------------------------------------  

  static const String DEF_PARAM;
  static const String PARAM_ALGORITHM;
  static const String PARAM_IMPLEMENTATION;
  static const String PARAM_TYPE;
  static const String PARAM_VARIABLE;
  static const String PARAM_COEF_TYPE;
  
  //----------------------------------------
  //
  // default values and arguments
  //
  //----------------------------------------  

  // define the default value(s) of the class data
  //  
  static const AlgorithmData::COEF_TYPE DEF_COEF_TYPE =
  AlgorithmData::PROPAGATE;
  //----------------------------------------
  //
  // error codes
  //
  //----------------------------------------  
  
  static const long ERR = 71500;
  
  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:
  
  // algorithm name
  //
  ALGORITHM algorithm_d;

  // implementation name
  //
  IMPLEMENTATION implementation_d;
  
  // the variable name and type
  //
  String variable_d;
  TYPE type_d;

  // the output coefficient type
  //
  AlgorithmData::COEF_TYPE coef_type_d;
  
  // memory manager
  //
  static MemoryManager mgr_d;
  
  //---------------------------------------------------------------------------
  //
  // required public methods
  //
  //---------------------------------------------------------------------------
public:
    
  // method: name
  //
  static const String& name() {
    return CLASS_NAME;
  }

  // other static methods
  //
  static boolean diagnose(Integral::DEBUG debug_level);
  
  // debug methods:
  //  setDebug method is inherited from the base class
  //
  boolean debug(const unichar* msg) const;

  // method: destructor
  //
  ~CoefficientLabel() {}

  // method: constructor
  //
  CoefficientLabel(ALGORITHM algorithm = DEF_ALGORITHM,
		   IMPLEMENTATION implementation = DEF_IMPLEMENTATION,
		   AlgorithmData::COEF_TYPE coef_type = DEF_COEF_TYPE,
		   TYPE type = DEF_TYPE) {
    algorithm_d = algorithm;
    implementation_d = implementation;
    coef_type_d = coef_type;
    type_d = type;
  }

  // method: copy constructor
  //  
  CoefficientLabel(const CoefficientLabel& arg) {
    assign(arg);
  }

  // method: assign
  //
  boolean assign(const CoefficientLabel& arg);
  
  // method: operator=
  //
  CoefficientLabel& operator= (const CoefficientLabel& arg) {
    assign(arg);
    return *this;
  }
  
  // i/o methods
  //
  long sofSize() const;
  
  boolean read(Sof& sof, long tag, const String& name = CLASS_NAME);
  boolean write(Sof& sof, long tag, const String& name = CLASS_NAME) const;

  boolean readData(Sof& sof, const String& pname = DEF_PARAM,
		   long size = SofParser::FULL_OBJECT,
		   boolean param = true,
                   boolean nested = false);
  boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const;
  
  // method: eq
  //
  boolean eq(const CoefficientLabel& arg) const {
    return (variable_d.eq(arg.variable_d) &&
	    (algorithm_d == arg.algorithm_d) &&
	    (implementation_d == arg.implementation_d) &&
	    (coef_type_d == arg.coef_type_d) &&
	    (type_d == arg.type_d));
  }
  
  // method: new
  //
  static void* operator new(size_t size) {
    return mgr_d.get();
  }

  // method: new[]
  //
  static void* operator new[](size_t size) {
    return mgr_d.getBlock(size);
  }

  // method: delete
  //
  static void operator delete(void* ptr) {
    mgr_d.release(ptr);
  }
  
  // method: delete[]
  //
  static void operator delete[](void* ptr) {
    mgr_d.releaseBlock(ptr);
  }
  
  // method: setGrowSize
  //
  static boolean setGrowSize(long grow_size) {
    return mgr_d.setGrow(grow_size);
  }

  // other memory management methods
  //  
  boolean clear(Integral::CMODE ctype = Integral::DEF_CMODE);
  
  //---------------------------------------------------------------------------
  //
  // class-specific public methods:
  //  set methods
  //
  //---------------------------------------------------------------------------

  // method: setAlgorithm
  //
  boolean setAlgorithm(ALGORITHM algorithm) {
    algorithm_d = algorithm;
    is_valid_d = false;    
    return true;
  }

  // method: setImplementation
  //
  boolean setImplementation(IMPLEMENTATION implementation) {
    implementation_d = implementation;
    is_valid_d = false;    
    return true;  
  }
  
  // method: setVariable
  //
  boolean setVariable(const String& variable) {
    return variable_d.assign(variable);
  }

  // method: setType
  //
  boolean setType(TYPE arg) {
    type_d = arg;
    is_valid_d = false;        
    return true;
  }

  // method: setCoefType
  //
  boolean setType(AlgorithmData::COEF_TYPE arg) {
    coef_type_d = arg;
    is_valid_d = false;        
    return true;
  }

  // method: set
  //
  boolean set(ALGORITHM algorithm = DEF_ALGORITHM,
	      IMPLEMENTATION implementation = DEF_IMPLEMENTATION,
	      AlgorithmData::COEF_TYPE coef_type = DEF_COEF_TYPE,
	      TYPE type = DEF_TYPE) {
    algorithm_d = algorithm;
    implementation_d = implementation;
    coef_type_d = coef_type;
    type_d = type;
    is_valid_d = false;
    return true;
  }
  
  //---------------------------------------------------------------------------
  //
  // class-specific public methods:
  //  get methods
  //
  //---------------------------------------------------------------------------

  // method: getAlgorithm
  //
  ALGORITHM getAlgorithm() const {
    return algorithm_d;
  }  

  // method: getImplementation
  //
  IMPLEMENTATION getImplementation() const {
    return implementation_d;
  }
  
  // method: getVariable
  //
  const String& getVariable() const {
    return variable_d;
  }

  // method: getType
  //
  TYPE getType() const {
    return type_d;
  }

  // method: getCoefType
  //
  AlgorithmData::COEF_TYPE getCoefType() const {
    return coef_type_d;
  }

  // method: get
  //
  boolean get(ALGORITHM& algorithm, IMPLEMENTATION& implementation,
	      AlgorithmData::COEF_TYPE& coef_type, TYPE& type) const {
    algorithm = algorithm_d;
    implementation = implementation_d;
    coef_type = coef_type_d;
    type = type_d;
    return true;
  }
  
  //---------------------------------------------------------------------------
  //
  // class-specific public methods:  
  //  AlgorithmBase interface contract methods
  //
  //---------------------------------------------------------------------------

  // assign method
  //
  boolean assign(const AlgorithmBase& arg);

  // equality method
  //  
  boolean eq(const AlgorithmBase& arg) const;

  // method: className
  //
  const String& className() const {
    return CLASS_NAME;
  }
  
  // apply method
  //
  boolean apply(Vector<AlgorithmData>& output,
		const Vector< CircularBuffer<AlgorithmData> >& input);

  // parser methods
  //
  boolean setParser(SofParser* parser);
  
  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
private:
};

// end of include file
// 
#endif
