// file: $isip/class/asr/JSGFToken/jt_00.cc
// version: $Id: jt_00.cc 10500 2006-03-15 21:44:09Z may $
//

// isip include files
//
#include "JSGFToken.h"
 
//------------------------------------------------------------------------
//
// required public methods
//
//-----------------------------------------------------------------------

// method: default constructor
//
// arguments: none
//
// return: none
//
JSGFToken::JSGFToken() {

  // initialize class data:
  //  note that debug_level_d is initialized by default.
  //
  header_d = DEF_HEADER;
  keyword_d = DEF_KEYWORD;
  grammar_name_d = DEF_GRAMMAR_NAME;
  import_grammar_d = DEF_IMPORT_GRAMMAR;
  rulename_d = DEF_RULENAME;
  terminal_d = DEF_TERMINAL;

  operator_d.setLength(DEF_OPERATOR_SIZE);
  
  for (long i = 0; i < DEF_OPERATOR_SIZE; i++) {
    operator_d(i) = DEF_OPERATOR;
  }
  
  tag_d = DEF_TAG;
  weight_d = DEF_WEIGHT;
  term_row_d = DEF_TERM_ROW;
  term_col_d = DEF_TERM_COL;
  weighted_terminal_d = DEF_WEIGHTED_TERMINAL;
  term_rule_name_d = DEF_TERM_RULE_NAME;
  vertex_index_d = DEF_VERTEX_INDEX;
  is_head_group_d = DEF_IS_HEAD_GROUP;
}

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

  // assign all protected data
  //
  token_type_d = arg_a.token_type_d;
  weight_d = arg_a.weight_d;
  term_row_d = arg_a.term_row_d;
  term_col_d = arg_a.term_col_d;
  weighted_terminal_d = arg_a.weighted_terminal_d;
  term_rule_name_d = arg_a.term_rule_name_d;
  vertex_index_d = arg_a.vertex_index_d;
  is_head_group_d = arg_a.is_head_group_d;

  operator_d(0) = arg_a.operator_d(0);	   
  operator_d(1) = arg_a.operator_d(1);	   
  
  return(header_d.assign(arg_a.header_d) &&
	 keyword_d.assign(arg_a.keyword_d) &&
	 grammar_name_d.assign(arg_a.grammar_name_d) &&
	 //import_grammar_d.assign(arg_a.import_grammar_d) &&
	 rulename_d.assign(arg_a.rulename_d) &&
	 terminal_d.assign(arg_a.terminal_d) &&
	 tag_d.assign(arg_a.tag_d));
    
}

// method: eq
//
// arguments:
//  const JSGFToken& arg: (input) input object to assign
//
// return: a boolean value indicating status
//
// this method checks whether the current object is identical to the
// input object
//
boolean JSGFToken::eq(const JSGFToken& arg_a) const {

  // compare all protected data
  //
  return ((token_type_d == arg_a.token_type_d) &&
	  (header_d.eq(arg_a.header_d)) &&
	  (keyword_d.eq(arg_a.keyword_d)) &&
	  (grammar_name_d.eq(arg_a.grammar_name_d)) &&
	  (import_grammar_d.eq(arg_a.import_grammar_d)) &&
	  (rulename_d.eq(arg_a.rulename_d)) &&
	  (terminal_d.eq(arg_a.terminal_d)) &&
	  (operator_d.eq(arg_a.operator_d)) &&
	  (tag_d.eq(arg_a.tag_d)) &&
	  (weight_d == arg_a.weight_d) &&
	  (term_row_d == arg_a.term_row_d) &&
	  (term_col_d == arg_a.term_col_d) &&
	  (term_rule_name_d.eq(arg_a.term_rule_name_d)) &&
	  (vertex_index_d == arg_a.vertex_index_d) &&
	  (is_head_group_d == arg_a.is_head_group_d) &&
	  (weighted_terminal_d == arg_a.weighted_terminal_d));  
}

// method: clear
//
// arguments:
//  Integral::CMODE ctype: (input) clear mode
//
// return: a boolean value indicating status
//
// this method resets the data members to the default values
//
boolean JSGFToken::clear(Integral::CMODE ctype_a) {

  // reset all protected data
  //
  if (ctype_a != Integral::RETAIN) {
    token_type_d = DEF_TYPE;
    header_d = DEF_HEADER;
    keyword_d = DEF_KEYWORD;
    grammar_name_d = DEF_GRAMMAR_NAME;
    import_grammar_d = DEF_IMPORT_GRAMMAR;
    rulename_d = DEF_RULENAME;
    terminal_d = DEF_TERMINAL;

    operator_d.setLength(DEF_OPERATOR_SIZE);

    for (long i = 0; i < DEF_OPERATOR_SIZE; i++) {
      operator_d(i) = DEF_OPERATOR;
    }
  
    tag_d = DEF_TAG;
    weight_d = DEF_WEIGHT;
    term_row_d = DEF_TERM_ROW;
    term_col_d = DEF_TERM_COL;
    weighted_terminal_d = DEF_WEIGHTED_TERMINAL;
    term_rule_name_d = DEF_TERM_RULE_NAME;
    vertex_index_d = DEF_VERTEX_INDEX;
    is_head_group_d = DEF_IS_HEAD_GROUP;  
  }
  
  // gracefully exit
  //
  return true;
}

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

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

// constants: i/o related constants
//
const String JSGFToken::DEF_HEADER(L"");
const String JSGFToken::DEF_KEYWORD(L"");
const String JSGFToken::DEF_GRAMMAR_NAME(L"");
const String JSGFToken::DEF_IMPORT_GRAMMAR(L"");
const String JSGFToken::DEF_RULENAME(L"");
const String JSGFToken::DEF_TERMINAL(L"");
const String JSGFToken::DEF_OPERATOR(L"");
const String JSGFToken::DEF_TAG(L"");
const String JSGFToken::DEF_TERM_RULE_NAME(L"");
const float JSGFToken::DEF_WEIGHT(0);
const long JSGFToken::DEF_TERM_ROW(0);
const long JSGFToken::DEF_TERM_COL(0);
const long JSGFToken::DEF_VERTEX_INDEX(-1);
const long JSGFToken::DEF_OPERATOR_SIZE(2);
const boolean JSGFToken::DEF_IS_HEAD_GROUP(false);
const boolean JSGFToken::DEF_WEIGHTED_TERMINAL(false);
// static instantiations: memory manager
//
MemoryManager JSGFToken::mgr_d(sizeof(JSGFToken), JSGFToken::name());
