// file: $isip/class/sp/FrontEnd/fe_00.cc
// version: $Id: fe_00.cc 8416 2002-07-17 20:22:13Z gao $
//

// system include files
//
#include <typeinfo>

// isip include files
//
#include "FrontEnd.h"
#include <AudioFrontEnd.h>

//------------------------------------------------------------------------
//
// required public methods
//
//-----------------------------------------------------------------------

// method: assign
//
// arguments:
//  const FrontEndBase& arg: (input) object to assign
//
// return: a boolean value
//
// this method assigns input argument to current argument
//
boolean FrontEnd::assign(const FrontEndBase& arg_a) {
  
  // assign the data
  //
  reset();

  // case: type is AudioFrontEnd
  //
  if (typeid(arg_a) == typeid(AudioFrontEnd)) {
    setType(AUDIO);
  }

  // case: other types
  //
  else {
    return Error::handle(name(), L"assign", Error::ENUM, __FILE__, __LINE__);
  }
  
  // exit gracefully
  //
  return virtual_fe_d->assign(arg_a);
  
}

// method: setType
//
// arguments:
//  TYPES type: (input) type of algorithm
//  
// return: a boolean value indicating status
//
// this method sets the type of the front end
//
boolean FrontEnd::setType(TYPES type_a) {

  // case: type is AudioFrontEnd
  //
  if (virtual_fe_d != (FrontEndBase*)&NO_FRONTEND) {
    return Error::handle(name(), L"setType", Error::ENUM, __FILE__, __LINE__);
  }

  // case: other types
  //
  if (type_a == AUDIO) {
    virtual_fe_d = new AudioFrontEnd();
  }
  
  // invalid type
  //
  else {
    return Error::handle(name(), L"setType", Error::ENUM, __FILE__, __LINE__);
  }
  
  // exit gracefully
  //
  return true;
}

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

// method: reset
//
// arguments: none
//
// return: a boolean value indicating status
//
// reset the type of transform
//
boolean FrontEnd::reset() {

  if (virtual_fe_d != (FrontEndBase*)&NO_FRONTEND) {
    delete virtual_fe_d;
    virtual_fe_d = (FrontEndBase*)&NO_FRONTEND;
  }

  // exit gracefully
  //
  return true;
}

//---------------------------------------------------------------------------
//
// we define non-integral constants in the default constructor
//      
//---------------------------------------------------------------------------

// constants: class name and default parameter
//      
const String FrontEnd::CLASS_NAME(L"FrontEnd");

// constants: i/o related constants
//
const String FrontEnd::PARAM_TYPES(L"name");

// constants: NameMap(s) for enumerated types
//
const NameMap FrontEnd::TYPES_MAP(L"AudioFrontEnd, VideoFrontEnd");

// constants: static undefined object
//
FrontEndUndefined FrontEnd::NO_FRONTEND;

// static instantiations: memory manager
//
MemoryManager FrontEnd::mgr_d(sizeof(FrontEnd), FrontEnd::name());
