// file: $isip/class/pr/ProductionRule/prdrl_03.cc
// version: $Id: prdrl_03.cc 10371 2006-01-19 15:34:30Z may $

// ISIP include files
//
#include "ProductionRule.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 ProductionRule::read(Sof& sof_a, long tag_a, const String& name_a) {
  
  // 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;
  }
 
  // 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 ProductionRule::readData(Sof& sof_a, const String& pname_a,
			      long size_a, boolean param_a,
			      boolean nested_a) {

  SofParser parser;
  String pname;

  parser.setDebug(Integral::NONE);

  // are we nested?
  //
  if (nested_a) {
    parser.setNest();
  }
  
  // load the parser
  //
  if (!parser.load(sof_a, size_a)) {
    return Error::handle(name(), L"readData", Error::READ,
			 __FILE__, __LINE__, Error::WARNING);
  }

  // read the type
  //
  TYPE_MAP.readElementData((long&)rule_type_d, sof_a, PARAM_RULE_TYPE,
  		   parser.getEntry(sof_a, PARAM_RULE_TYPE));
  
  if (!rule_name_d.readData(sof_a, PARAM_RULE_NAME, parser.getEntry(sof_a, PARAM_RULE_NAME),
		       true, false)) {
    return Error::handle(name(), L"readData", Error::READ, __FILE__,
			 __LINE__, Error::WARNING);
  }

  if (!rule_d.readData(sof_a, PARAM_RULE, parser.getEntry(sof_a, PARAM_RULE),
		       false, false)) {
    return Error::handle(name(), L"readData", Error::READ, __FILE__,
			 __LINE__, Error::WARNING);
  }
  
  // indicate success
  //
  return true;
}
