#include "Param.h"

Param::Param()
{
  paramState=PARAM_STATE_CLEAR;
}

Param::~Param()
{
  clearParamState();
}

//resets the state to PARAM_STATE_CLEAR
void Param::clear()
{
  clearParamState();
}

void Param::clearParamState()
{
  paramState=PARAM_STATE_CLEAR;
  dataString.clear();
  dataInt.clear();
  dataBool.clear();
}

//returns the state
uint8_t Param::getParamState ()
{
  return paramState;
}

//bool objects
void Param::getBool (const string & key, bool & val)
{
  map <string, bool> :: iterator iter;
  iter = dataBool.find (key);

  if (iter != dataBool.end())
    val = dataBool[key];
}

void Param::setBool (const string & key, bool val)
{
  paramState=PARAM_STATE_DIRTY;
  dataBool.erase(key);
  dataBool[key]=val;
}

//int objects
void Param::getInt (const string & key, int & val)
{
  map <string, int> :: iterator iter;
  iter = dataInt.find (key);

  if (iter != dataInt.end())
    val = dataInt[key];
}

void Param::setInt (const string & key, int val)
{
  paramState=PARAM_STATE_DIRTY;
  dataInt.erase(key);
  dataInt[key]=val;
}

//string objects
void Param::getString (const string & key, string & val)
{
  map <string, string> :: iterator iter;
  iter = dataString.find (key);

  if (iter != dataString.end())
    val = dataString[key];
}

void Param::setString (const string & key, const string & val)
{
  paramState=PARAM_STATE_DIRTY;
  dataString.erase(key);
  dataString[key]=val;
}
