// file: $isip/class/search/SearchNode/snod_08.cc
// version: $Id: snod_08.cc 8444 2002-07-24 17:06:49Z huang $
//

// isip include files
//
#include "SearchNode.h"
#include <Trace.h>
#include <Instance.h>
#include <SearchLevel.h>

// method: setSymbolId
//
// arguments:
//  long symbol_id: (input) the input symbol id
//
// return: a boolean value indicating status
//
// this method sets the symbol id for this node
//
boolean SearchNode::setSymbolId(long symbol_id_a) {

  // make sure the search level has been initialized
  //
  if (level_d == (SearchLevel*)NULL) {
    return Error::handle(name(), L"setSymbolId", Error::ARG, __FILE__, __LINE__);
  }
  
  // check with the search level to make sure this is a valid symbol and
  // assign the symbol id
  //
  if ( !level_d->isDummySymbol(symbol_id_a) ){
    return (level_d->isValidSymbol(symbol_id_a) &&
	    symbol_id_d.assign(symbol_id_a));
  }

  // if this is a dummy symbol index
  //
  if ( symbol_id_a >= 0 ){
    symbol_id_a = DEF_DUMMY_SYMBOL_ID - symbol_id_a;
  }
  return symbol_id_d.assign(symbol_id_a);
}

// method: setSymbol
//
// arguments:
//  const SearchSymbol& symbol: (input) the input symbol
//
// return: a boolean indicating status
//
// this method sets the symbol for this node
//
boolean SearchNode::setSymbol(const SearchSymbol& symbol_a) {

  // make sure the search level has been initialized
  //
  if (level_d == (SearchLevel*)NULL) {
    return Error::handle(name(), L"setSymbol", Error::ARG, __FILE__, __LINE__);
  }

  // get symbol id first
  //
  long symbol_id = level_d->getSymbolIndex(symbol_a);

  return setSymbolId(symbol_id);
  
}

// method: getSymbol
//
// arguments:
//  SearchSymbol& output_symbol: (output) the symbol to lookup
//
// return: logical error status
//
// this method gets the symbol from this node
//
boolean SearchNode::getSymbol(SearchSymbol& output_symbol_a) const {

  // make sure the search level has been initialized
  //
  if (level_d == (SearchLevel*)NULL) {
    return Error::handle(name(), L"getSymbol", Error::ARG, __FILE__, __LINE__);
  }

  long index = getSymbolId();
  
  // return the symbol
  //
  return level_d->getSymbol(output_symbol_a, index);
}



