// file: $isip/class/mmedia/FeatureFile/ftrf_00.cc
// version: $Id: ftrf_00.cc 10597 2006-08-08 21:28:39Z ss754 $
//

// isip include files
//
#include "FeatureFile.h"

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

// method: default constructor
//
// arguments:
//  
// return: none
//
// this is the default constructor for the FeatureFile class.
//
FeatureFile::FeatureFile() {

  // initialize the main configuration parameters
  //
  name_d = DEF_FEATURE_NAME;
  file_type_d = DEF_FILE_TYPE;
  file_format_d = DEF_FILE_FORMAT;
  compression_type_d = DEF_COMP_TYPE;

  num_frames_d = DEF_NUM_FRAMES;  
  amplitude_range_d = DEF_AMPLITUDE_RANGE;
  num_channels_d = DEF_NUM_CHANNELS;
  id_d = DEF_FEATURE_NAME;
  num_features_d.assign(DEF_NUM_FEATURES);
  data_type_d = DEF_DATA_TYPE;
  coef_type_d = AlgorithmData::DEF_CTYPE;

  tag_d = DEF_TAG;
  buffers_d.setLength((long)num_channels_d);
  block_size_d = DEF_BLOCK_SIZE;
  buf_size_d = DEF_BUF_SIZE;  

  frame_duration_d.assign(DEF_FRAME_DURATION);
  sample_frequency_d.assign(DEF_SAMPLE_FREQ);

  // initialize other miscellaneous parameters
  //
  buf_end_ftr_d.setLength((long)num_channels_d);
  Long num((long)-1);
  buf_end_ftr_d.assign(num);
  end_of_file_d = false;
  
  // set the capacity of each channel's buffer
  //
  setBufferSize(DEF_BUF_SIZE);

  // exit gracefully
  //
}

// method: assign
//
// arguments:
//  const FeatureFile& arg: (input) FeatureFile object to copy
//
// return: a boolean value indicating status
//
// this method assign the input object to the current one.
//
boolean FeatureFile::assign(const FeatureFile& arg_a) {

  // copy the type and format related parameters
  //
  name_d.assign(arg_a.name_d);
  file_type_d = arg_a.file_type_d;
  file_format_d = arg_a.file_format_d;
  compression_type_d = arg_a.compression_type_d;
  
  // copy the data value related parameters
  //
  num_frames_d = arg_a.num_frames_d;  
  amplitude_range_d = arg_a.amplitude_range_d;
  num_channels_d.assign(arg_a.num_channels_d);
  id_d.assign(arg_a.id_d);
  data_type_d = arg_a.data_type_d;
  coef_type_d = arg_a.coef_type_d;
  
  // copy the buffer related parameters
  //
  tag_d.assign(arg_a.tag_d);
  block_size_d = arg_a.block_size_d;
  buf_size_d = arg_a.buf_size_d;

  // copy the signal processing related parameters
  //
  frame_duration_d.assign(arg_a.frame_duration_d);
  sample_frequency_d.assign(arg_a.sample_frequency_d);

  // reset all buffers and exit
  //
  return setNumChannels(num_channels_d);
}

// method: clear
//
// arguments:
//  Integral::CMODE cmode: (input) clear mode
//
// return: a boolean value indicating status
//
// this method clears the contents of the FeatureFile vector.
//
boolean FeatureFile::clear(Integral::CMODE cmode_a) {

  // reset the name
  //
  name_d = DEF_FEATURE_NAME;

  file_type_d = DEF_FILE_TYPE;
  file_format_d = DEF_FILE_FORMAT;
  compression_type_d = DEF_COMP_TYPE;

  num_frames_d = DEF_NUM_FRAMES;  
  amplitude_range_d = DEF_AMPLITUDE_RANGE;
  num_channels_d = DEF_NUM_CHANNELS;
  id_d = DEF_FEATURE_NAME;
  num_features_d.assign(DEF_NUM_FEATURES);
  data_type_d = DEF_DATA_TYPE;
  coef_type_d = AlgorithmData::DEF_CTYPE;

  tag_d = DEF_TAG;
  block_size_d = DEF_BLOCK_SIZE;
  buf_size_d = DEF_BUF_SIZE;  

  frame_duration_d.assign(DEF_FRAME_DURATION);
  sample_frequency_d.assign(DEF_SAMPLE_FREQ);

  v_d.clear(cmode_a);
  buffers_d.setLength((long)num_channels_d);
  
  // initialize other miscellaneous parameters
  //
  buf_end_ftr_d.setLength((long)num_channels_d);
  Long num((long)-1);
  buf_end_ftr_d.assign(num);
  end_of_file_d = false;

  // set the capacity of each channel's buffer
  //
  setBufferSize(DEF_BUF_SIZE);
  
  // exit gracefully
  //
  return true;
}

// method: eq
//
// arguments:
//  const FeatureFile& arg: (input) FeatureFile object to compare
//
// return: a boolean value indicating status
//
// this method checks if the input object is the same as the current one.
//
boolean FeatureFile::eq(const FeatureFile& arg_a) const {

  if ((!name_d.eq(arg_a.name_d)) ||
      (!file_type_d == arg_a.file_type_d) ||
      (!file_format_d == arg_a.file_format_d) ||
      (!compression_type_d == arg_a.compression_type_d) ||
      (!amplitude_range_d.eq(arg_a.amplitude_range_d)) ||          
      (!num_channels_d.eq(arg_a.num_channels_d)) ||
      (!id_d.eq(arg_a.id_d)) ||
      (!num_features_d.eq(arg_a.num_features_d)) ||
      (!data_type_d == arg_a.data_type_d) ||
      (!coef_type_d == arg_a.coef_type_d) ||                  
      (!tag_d.eq(arg_a.tag_d)) ||
      (!block_size_d.eq(arg_a.block_size_d)) ||      
      (!buf_size_d.eq(arg_a.buf_size_d)) ||
      (!frame_duration_d.eq(arg_a.frame_duration_d)) ||
      (!sample_frequency_d.eq(arg_a.sample_frequency_d))) {
    return false;
  }
  else {
    return true;
  }
}

//-----------------------------------------------------------------------------
//
// class-specific public methods
//
//-----------------------------------------------------------------------------


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

// constants: class name
//
const String FeatureFile::CLASS_NAME(L"FeatureFile");

// constants: i/o related constants
//
const String FeatureFile::PARAM_NAME(L"name");
const String FeatureFile::PARAM_FILE_TYPE(L"file_type");
const String FeatureFile::PARAM_FILE_FORMAT(L"file_format");
const String FeatureFile::PARAM_COMP_TYPE(L"compression_type");

const String FeatureFile::PARAM_RANGE(L"amplitude_range");
const String FeatureFile::PARAM_NUM_CHANNELS(L"num_channels");
const String FeatureFile::PARAM_ID(L"id");
const String FeatureFile::PARAM_NUM_FEATURES(L"num_features");
const String FeatureFile::PARAM_DATA_TYPE(L"data_type");
const String FeatureFile::PARAM_COEF_TYPE(L"coef_type");

const String FeatureFile::PARAM_TAG(L"tag");
const String FeatureFile::PARAM_BLOCK_SIZE(L"block_size");
const String FeatureFile::PARAM_BUF_SIZE(L"buf_size");

const String FeatureFile::PARAM_FRAME_DURATION(L"frame_duration");
const String FeatureFile::PARAM_SAMPLE_FREQUENCY(L"sample_frequency");

const String FeatureFile::PARAM_DATA(L"values");

// constants: default values of the class data
//
const String FeatureFile::DEF_FEATURE_NAME(L"FEATURES");

// static instantiations: namemaps for enumerations
//
NameMap FeatureFile::FILE_TYPE_MAP(L"TEXT, BINARY");
NameMap FeatureFile::FILE_FORMAT_MAP(L"SOF, RAW");
NameMap FeatureFile::COMP_TYPE_MAP(L"LINEAR, ULAW, ALAW");
NameMap FeatureFile::SAMPLE_PRECISION_MAP(L"NONE, USE_SIZE, EIGHT_BITS, TWELVE_BITS, SIXTEEN_BITS, TWENTY_BITS, TWENTY_FOUR_BITS, THIRTY_TWO_BITSNONE");
NameMap FeatureFile::DATA_TYPE_MAP(L"ALGORITHM_DATA, VECTOR_FLOAT");

// static instantiations: debug level and memory manager
//
Integral::DEBUG FeatureFile::debug_level_d = Integral::NONE;
MemoryManager FeatureFile::mgr_d(sizeof(FeatureFile), FeatureFile::name());
