// file: $isip/class/asr/AudioDatabase/AudioDatabase.h
// version: $Id: AudioDatabase.h 9420 2004-03-10 20:09:46Z parihar $
//

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

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

#ifndef ISIP_FILENAME
#include <Filename.h>
#endif

#ifndef ISIP_HASH_TABLE
#include <HashTable.h>
#endif

#ifndef ISIP_SDB
#include <Sdb.h>
#endif

// AudioDatabase: a class that facilitates the interface between the audio
// database and another application or class
//
class AudioDatabase {
  
  //--------------------------------------------------------------------------
  //
  // public constants
  //
  //--------------------------------------------------------------------------
public:
  
  // define the class name
  //
  static const String CLASS_NAME;

  // i/o related constants
  //
  static const String DEF_PARAM;
  static const String PARAM_KEYS;
  static const String PARAM_NAME;  
  static const String PARAM_VALUES;
    
  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:

  // define the database name
  //
  String name_d;
  
  // define the container object
  //
  HashTable<String, Long> hash_d;

  // define the database file
  //
  Sof database_sof_d;
  
  // declare a static debug level for all class instantiations
  //
  static Integral::DEBUG debug_level_d;
  
  // a static memory manager
  //
  static MemoryManager mgr_d;
  
  //---------------------------------------------------------------------------
  //
  // required public methods
  //
  //---------------------------------------------------------------------------
public:
  
  // method: name
  //
  static const String& name() {
    return CLASS_NAME;
  }
  
  static boolean diagnose(Integral::DEBUG debug_level);
  
  // debug methods
  //
  boolean debug(const unichar* msg) const;

  // method: setDebug
  //
  static boolean setDebug(Integral::DEBUG arg) {
    debug_level_d = arg;
    return true;
  }
  
  // method: destructor
  //
  ~AudioDatabase() {}

  // method: default constructor
  //
  AudioDatabase();

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

  // method: assign
  //
  boolean assign(const AudioDatabase& arg);
  
  // method: sofSize
  //
  long sofSize() const;

  // method: read
  //
  boolean read(Sof& sof, long tag) {
    return read(sof, tag, name());
  }
  boolean read(Sof& sof, long tag, const String& name);
  boolean readData(Sof& sof, const String& pname = DEF_PARAM, long size =
                   SofParser::FULL_OBJECT, boolean param = true,
                   boolean nested = false);

  // method: write
  //
  boolean write(Sof& sof, long tag) const {
    return write(sof, tag, name());
  }
  boolean write(Sof& sof, long tag, const String& name) const;
  boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const;
  
  // method: eq
  //
  boolean eq(const AudioDatabase& arg) const;

  // method: new
  //
  static void* operator new(size_t arg) {
    return mgr_d.get();
  }

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

  // method: delete
  //
  static void operator delete(void* arg) {
    mgr_d.release(arg);
  }

  // method: delete[]
  //
  static void operator delete[](void* arg) {
    mgr_d.releaseBlock(arg);
  }

  // method: setGrowSize
  //
  static boolean setGrowSize(long arg) {
    return mgr_d.setGrow(arg);
  }

  // method: clear
  //
  boolean clear(Integral::CMODE cmode = Integral::DEF_CMODE);

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

  // method: getDataBaseName
  //
  String& getDataBaseName() {
    return name_d;
  }

  // method: setDataBaseName
  //
  boolean setDataBaseName(String& arg) {
    return name_d.assign(arg);
  }  
  
  // method: getSymbolTable
  //
  HashTable<String, Long>& getSymbolTable() {
    return hash_d;
  }  
  
  // method to retrieve a record form the database
  //
  boolean getRecord(String& identifier, Filename& record);

  // method: removeRecord
  //
  boolean removeRecord(String& identifier) {
    return hash_d.remove(identifier);
  }

  // method: insertRecord
  //
  boolean insertRecord(String& identifier, Long& index) {
    return hash_d.insert(identifier, &index);
  }    

  // database open and close method
  //
  boolean open(const Filename& db_sof);
  boolean close();  
  
  // method: load
  //
  boolean load(Sdb& id_list, Sdb& file_list, Vector<Filename>& file_vec);
  
  // method: load
  //
  boolean load(Filename& file_list, Vector<Filename>& file_vec);

  // method: store
  //
  boolean store(Sof& db_sof, long tag, Vector<Filename>& file_vec);

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

};

//end of include file
//
#endif
