// file: $isip/class/algo/DisplayData/DisplayData.h
// version: $Id: DisplayData.h 8259 2002-07-01 20:56:00Z picone $
//

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

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

#ifndef ISIP_LONG
#include <Long.h>
#endif

#ifndef ISIP_STRING
#include <String.h>
#endif

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

// DisplayData: a class used to display data as it is processed through
// a recipe in isip_transform. this class is mainly used as a diagnostic
// tool - it lets users obtain debugging output at any point in a recipe.
//
class DisplayData : public AlgorithmBase {

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

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

  // define the algorithm choices
  //
  enum ALGORITHM { EVERY = 0, FIRST, LAST, ONCE, DEF_ALGORITHM = EVERY };

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

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

  //----------------------------------------
  //
  // constants for building the output
  //
  //----------------------------------------  

  static const String ELEMENT_HEADER_00;
  static const String ELEMENT_HEADER_01;
  static const String LABEL_DELIM;
  static const String EMPTY_MATRIX;
  static const String MATRIX_START;
  static const String MATRIX_DELIM;
  static const String MATRIX_END;
  
  //----------------------------------------
  //
  // i/o related constants
  //
  //----------------------------------------  

  static const String DEF_PARAM;
  static const String PARAM_ALGORITHM;
  static const String PARAM_IMPLEMENTATION;
  static const String PARAM_NUMBER;
  static const String PARAM_LABEL;
  static const String PARAM_PREFIX;
  static const String PARAM_SUFFIX;
  
  //----------------------------------------
  //
  // default values and arguments
  //
  //----------------------------------------  

  // define the default value(s) of the class data
  //  
  static const long DEF_NUMBER = 0;
  static const Integral::DEBUG DEF_DEBUG_LEVEL = Integral::BRIEF;

  static const String DEF_LABEL;
  static const String DEF_PREFIX;
  static const String DEF_SUFFIX;
  
  //----------------------------------------
  //
  // error codes
  //
  //----------------------------------------  
  
  static const long ERR = 73100;
  
  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:
  
  // algorithm name
  //
  ALGORITHM algorithm_d;

  // implementation name
  //
  IMPLEMENTATION implementation_d;
  
  // the number
  //
  Long number_d;

  // strings that define the output
  //
  String label_d;
  String prefix_d;
  String suffix_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
  //
  ~DisplayData() {}

  // method: constructor
  //
  DisplayData(ALGORITHM algorithm = DEF_ALGORITHM,
	      IMPLEMENTATION implementation = DEF_IMPLEMENTATION,
	      Long number = DEF_NUMBER,
	      Integral::DEBUG debug_level = DEF_DEBUG_LEVEL) {
    algorithm_d = algorithm;
    implementation_d = implementation;
    number_d = number;
    debug_level_d = debug_level;
  }

  // method: copy constructor
  //  
  DisplayData(const DisplayData& arg) {
    debug_level_d = DEF_DEBUG_LEVEL;
    assign(arg);
  }

  // method: assign
  //
  boolean assign(const DisplayData& arg);
  
  // method: operator=
  //
  DisplayData& operator= (const DisplayData& 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 DisplayData& arg) const {
    return ((algorithm_d == arg.algorithm_d) &&
	    (implementation_d == arg.implementation_d) &&
	    (number_d == arg.number_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: setNumber
  //
  boolean setNumber(long arg) {
    return number_d.assign(arg);
    is_valid_d = false;
  }

  // method: setLabel
  //
  boolean setLabel(const String& arg) {
    return label_d.assign(arg);
  }

  // method: setPrefix
  //
  boolean setPrefix(const String& arg) {
    return prefix_d.assign(arg);
  }

  // method: setSuffix
  //
  boolean setSuffix(const String& arg) {
    return suffix_d.assign(arg);
  }

  // method: set
  //
  boolean set(ALGORITHM algorithm = DEF_ALGORITHM,
	      IMPLEMENTATION implementation = DEF_IMPLEMENTATION,
	      Long number = DEF_NUMBER,
	      Integral::DEBUG debug_level = DEF_DEBUG_LEVEL) {
    algorithm_d = algorithm;
    implementation_d = implementation;
    number_d = number;
    debug_level_d = debug_level;
    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: getNumber
  //
  long getNumber() const {
    return number_d;
  }

  // method: getLabel
  //
  const String& getLabel() const {
    return label_d;
  }

  // method: getPrefix
  //
  const String& getPrefix() const {
    return prefix_d;
  }

  // method: getSuffix
  //
  const String& getSuffix() const {
    return suffix_d;
  }

  // method: get
  //
  boolean get(ALGORITHM& algorithm,
	      IMPLEMENTATION& implementation,
	      long& number,
	      Integral::DEBUG& debug_level) const {
    algorithm = algorithm_d;
    implementation = implementation_d;
    number = number_d;
    debug_level = debug_level_d;
    return true;
  }
  
  //---------------------------------------------------------------------------
  //
  // class-specific public methods:
  //  computational methods
  //
  //---------------------------------------------------------------------------

  boolean compute(AlgorithmData& output, const AlgorithmData& input);
  
  //---------------------------------------------------------------------------
  //
  // 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:

  // method to determine if this frame's data should be displayed
  //
  boolean shouldDisplayFrame() const;

  // method to create a nice display for anything but a combination
  //
  boolean displayObject(const AlgorithmData& input) const;
};

// end of include file
// 
#endif
