// file: $isip/class/algo/Math/math_06.cc
// version: $Id: math_06.cc 8283 2002-07-03 21:08:37Z picone $
//

// isip include files
//
#include "Math.h"

// method: getOperation
//
// arguments:
//  String& output: (output) string with all operations listed
//
// return: logical error status
//
// create a string out of all the operations
//
boolean Math::getOperation(String& output_a) const {

  // initialize the output
  //
  output_a.clear();

  for (long i = 0; i < operation_d.length(); i++) {

    if (i == 0) {
      output_a.assign(OPER_MAP(operation_d(i)));
    }
    else {
      output_a.concat(DELIM);
      output_a.concat(OPER_MAP(operation_d(i)));
    }
  }

  // exit gracefully
  // 
  return true;
}

// method: getFunction
//
// arguments:
//  String& output: (output) string with all functions listed
//
// return: logical error status
//
// create a string out of all the functions
//
boolean Math::getFunction(String& output_a) const {

  // initialize the output
  //
  output_a.clear();

  for (long i = 0; i < function_d.length(); i++) {

    if (i == 0) {
      output_a.assign(FUNC_MAP(function_d(i)));
    }
    else {
      output_a.concat(DELIM);
      output_a.concat(FUNC_MAP(function_d(i)));
    }
  }

  // exit gracefully
  // 
  return true;
}

// method: setOperation
//
// arguments:
//  const String& operations: (input) string with all operations listed
//
// return: logical error status
//
// set the operations by parsing this input string
//
boolean Math::setOperation(const String& operations_a) {


  // determine the number of tokens and create a vector
  //
  long size = operations_a.countTokens(DELIM);
  VectorLong vec(size);

  // local variables for tokenization
  //
  long pos = 0;
  String token;

  // tokenize the string into the VectorLong
  //
  long i = 0;
  while (operations_a.tokenize(token, pos, DELIM)) {
    token.trim();
    vec(i++) = OPER_MAP(token);
  }

  // call the master method
  //
  return setOperation(vec);
}

// method: setFunction
//
// arguments:
//  const String& functions: (input) string with all functions listed
//
// return: logical error status
//
// set the functions by parsing this input string
//
boolean Math::setFunction(const String& functions_a) {


  // determine the number of tokens and create a vector
  //
  long size = functions_a.countTokens(DELIM);
  VectorLong vec(size);

  // local variables for tokenization
  //
  long pos = 0;
  String token;

  // tokenize the string into the VectorLong
  //
  long i = 0;
  while (functions_a.tokenize(token, pos, DELIM)) {
    token.trim();
    vec(i++) = FUNC_MAP(token);
  }

  // call the master method
  //
  return setFunction(vec);
}
