// file: $isip/class/pr/LanguageModelABNF/lmabnf_03.cc
// version: $Id: lmabnf_03.cc 10495 2006-03-15 21:37:57Z may $

// ISIP include files
//
#include "LanguageModelABNF.h"

// method: read
//
// arguments:
//  Sof& sof: (input) sof file object
//  long tag: (input) sof object instance tag
//  const String& name: (input) sof object instance name
//
// return: a boolean value indicating status
//
// this method has the object read itself from an Sof file
//
boolean LanguageModelABNF::read(Sof& sof_a, long tag_a, const String& name_a) {
  
  if (debug_level_d > Integral::BRIEF) {
    Console::put(L"reading model");
    Console::increaseIndention();			  
  }
  
  // read the instance of the object from the Sof file
  //
  if (!sof_a.find(name_a, tag_a)) {
    return false;
  }

  // read the actual data from the sof file
  //
  if (!readData(sof_a)) {
    return false;
  }
 if (debug_level_d > Integral::BRIEF) {
    Console::decreaseIndention();
  }
  
  // exit gracefully
  //
  return true;  
}

// method: readData
//
// arguments:
//  Sof& sof: (input) sof file object
//  const String& pname: (input) parameter name
//  long size: (input) size in bytes of object (or full_size)
//  boolean param: (input) is the parameter name in the file
//  boolean nested: (input) are we nested?
//
// return: a boolean value indicating status
//
// this method has the object read itself from an Sof file. it assumes
// that the Sof file is already positioned correctly.
//
boolean LanguageModelABNF::readData(Sof& sof_a, const String& pname_a,
			      long size_a, boolean param_a,
			      boolean nested_a) {

  SofParser parser;
  String pname;

  // if param is false, this means implicit parameter
  //
  if (!param_a) {
    parser.setImplicitParam();
    pname.assign(parser.implicitPname());
  }
  else {
    pname.assign(pname_a);
  }
  
  parser.setDebug(Integral::NONE);

  // are we nested?
  //
  if (nested_a) {
    parser.setNest();
  }
  
  // load the parser
  //

  // RE CHECK THIS
  //
  if (!parser.load(sof_a, size_a)) {
    return Error::handle(name(), L"readData", Error::READ,
			 __FILE__, __LINE__, Error::WARNING);
  }

  if (!abnf_model_d.readData(sof_a, PARAM_ABNF,
			     parser.getEntry(sof_a, PARAM_ABNF),
			     false, false)) {
    return Error::handle(name(), L"readData", Error::READ, __FILE__,
			 __LINE__, Error::WARNING);
  }

  // indicate success
  //
  return true;
}
