#include "parseObj.h"

parseObj::parseObj(paramObj *o)
{
  init(o);
}

parseObj::~parseObj()
{
  values.clear();
}

void parseObj::init(paramObj *o) {
  isValid = false;
  data = o;
  values.clear();
  wasPrable = true;
  wasUsed = false;
}

// ------------------------------------

void parseObj::setValid() {
  isValid = true;
}

void parseObj::setInvalid() {
  isValid = false;
}

void parseObj::addValue(string s) {
  values.push_back(s);
}

bool parseObj::processable() {
  // tests whether object has already been process AND is valid.
  // whatever the results, setUsed will set set true afterwards,
  // so further calls will return false
  bool b = (isValid & !wasUsed);
  wasPrable = b;       // for debugging purpose
  wasUsed = true;
  return b;
}

bool parseObj::wasProcessable() {
  return wasPrable;    // for debugging purpose
}

optList* parseObj::getValues() {
  return &values;
}

string parseObj::getValue(int n) {
  if ((n >= 0) && (n < values.size())) {
    return values[n];
  }
  return "";
}

void parseObj::show() {
  static int cnt = 0;
  cnt++;
  printf("..option %d, %s = %s: ", cnt, data->par1.c_str(), data->par2.c_str());
  for (int l=0; l < size(); l++) {
    printf("%s, ", values[l].c_str());
  }
  printf("\n");
}

int parseObj::isOption(string s1, string s2) {
  // tests whether the paramObj is of given type. types should coincide!
  if (s1 == "") return 0;
  if ((data->par1 == s1) || (data->par2 == s1)) {	
    if (s2 != "") {
      if ((data->par1 == s2) || (data->par2 == s2)) {
	return 1;
      } else {
	// if we are here, s1 and s2 reference different options or one is not defined (mistyping?)
	return -1;
      }
    }
    return 1;
  }
  return 0;
}
