// file: $isip/class/math/vector/VectorComplexFloat/VectorComplexFloat.h
// version: $Id: VectorComplexFloat.h 10636 2007-01-26 22:18:09Z tm334 $
//

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

#ifndef ISIP_MVECTOR
#include <MVector.h>
#endif

#ifndef ISIP_VECTOR_FLOAT
#include <VectorFloat.h>
#endif

// VectorComplexFloat: this is a vector of ComplexFloat objects, which
// inherits the MVector template class.
//
class VectorComplexFloat : public MVector<ComplexFloat, complexfloat> {

  //---------------------------------------------------------------------------
  //
  // public constants
  //
  //---------------------------------------------------------------------------
public:

  // define the class name
  //
  static const String CLASS_NAME;

  //----------------------------------------
  //
  // default values and arguments
  //
  //----------------------------------------  
  
  //----------------------------------------
  //
  // error codes
  //
  //----------------------------------------  
  
  static const long ERR = 23000;

  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:

  // static 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);

  // method: setDebug
  //  these methods are inherited from the MVector template class
  //
  
  // method: debug
  //
  boolean debug(const unichar* message) const {
    return MVector<ComplexFloat, complexfloat>::debug(name(), message);
  }
  
  // method: destructor
  //
  ~VectorComplexFloat() {}
    
  // method: default constructor
  //
  VectorComplexFloat(long length = DEF_LENGTH,
		     complexfloat value = DEF_VALUE) {
    assign(length, value);
  }

  // method: copy constructor
  //
  VectorComplexFloat(const VectorComplexFloat& vector) {
    assign(vector);
  }
  
  // assign methods:
  //  these methods are inherited from the MVector template class
  //

  // method: operator=
  //
  //  note that we need to have the overloaded operator '=' defined in the
  //  derived classes instead of the base template class. this is required
  //  since c++ predefines the operator '=' for any class by default
  //  and this hides any other definition of this operator in the base class
  //
  VectorComplexFloat& operator= (const VectorComplexFloat& vector) {
    assign(vector);
    return *this;
  }
  
  // i/o methods:
  //  the sofSize, readData and writeData are inherited from the MVector
  //  template class
  //

  // method: read
  //
  boolean read(Sof& sof, long tag, const String& name = CLASS_NAME) {
    return MVector<ComplexFloat, complexfloat>::read(sof, tag, name);
  }
  
  // method: write
  //
  boolean write(Sof& sof, long tag, const String& name = CLASS_NAME) {
    return MVector<ComplexFloat, complexfloat>::write(sof, tag, name);
  }    

  // equality methods:
  //  these methods are inherited from the MVector template class
  //

  // 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:
  //  the clear method is inherited from the MVector template class
  // 

  //---------------------------------------------------------------------------
  //
  // class-specific public methods
  //
  //---------------------------------------------------------------------------
public:
  
  // method: constructor
  //  this method constructs a vector with a String* object
  //
  VectorComplexFloat(const String& arg, unichar delim = DEF_DELIM) {
    assign(arg, delim);
  }
  
  // method: constructor
  //  this method constructs a vector with a unichar* object
  //
  VectorComplexFloat(const unichar* arg, unichar delim = DEF_DELIM) {
    assign(arg, delim);
  }
  
  // method: operator=
  //  this method assigns a float value to the vector
  //
  VectorComplexFloat& operator= (complexfloat value) {
    assign(value);
    return *this;
  }

  //---------------------------------------------------------------------------
  //
  // class-specific public methods: complex functionality
  //
  //---------------------------------------------------------------------------
public:

  // method: real
  //
  boolean real(VectorFloat& arg) const {
    arg.setLength(length_d);
    for (long i = (long)length_d - 1; i >= 0; i--) {
      arg(i) = v_d[i].real();
    }
    return true;
  }

  // method: imag
  //
  boolean imag(VectorFloat& arg) const {
    arg.setLength(length_d);
    for (long i = (long)length_d - 1; i >= 0; i--) {
      arg(i) = v_d[i].imag();
    }
    return true;
  }

  // method: abs
  //
  boolean abs(VectorFloat& arg) const {
    arg.setLength(length_d);
    for (long i = (long)length_d - 1; i >= 0; i--) {
      arg(i) = v_d[i].mag();
    }
    return true;
  }

  // method: mag
  //
  boolean mag(VectorFloat& arg) const {
    arg.setLength(length_d);
    for (long i = (long)length_d - 1; i >= 0; i--) {
      arg(i) = v_d[i].mag();
    }
    return true;
  }
  
  // method: angle
  //
  boolean angle(VectorFloat& arg) const {
    arg.setLength(length_d);
    for (long i = (long)length_d - 1; i >= 0; i--) {
      arg(i) = v_d[i].angle();
    }
    return true;
  }
  
  // method: conjugate
  //
  boolean conjugate(const VectorComplexFloat& arg) {
    setLength(arg.length_d);
    for (long i = (long)(arg.length_d) - 1; i >= 0; i--) {
      v_d[i] = arg(i).conjugate();
    }
    return true;
  }

  // method: conjugate
  //
  boolean conjugate() {
    return conjugate(*this);
  }

  // method: limitMin
  //
  template<class TIntegral>
  boolean limitMin(TIntegral min_val) {
    return false;
  }
  
  template<class TScalar, class TIntegral>
    boolean limitMin(TIntegral min_val, const MVector<TScalar, TIntegral>& vector) {
    return false;
  }

  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
private:

  //declare those methods as private because they cannot be
  //defined for Complex value
  //  
  boolean operator %(const VectorComplexFloat& vector);
  boolean operator %=(const VectorComplexFloat& vector);
  boolean band();
  boolean bor();
  boolean bxor();
  boolean brs();
  boolean bls();
  boolean bcmpl();

  boolean mod();

  boolean centerClip();
  boolean fraction();
  boolean limit();
  boolean limitMag();
  
};

// end of include file
//
#endif
