/* Fesslix-library finan
 * Copyright (C) 2014-2014 Wolfgang Betz
 */


#include "flxlibs_interface.h"



flxlibs_interface::~flxlibs_interface()
{
  #if FLX_DEBUG
    if (obj_list.empty()==false)    throw FlxException_Crude("flxlibs_interface::~flxlibs_interface_1");
    if (fun_list.empty()==false)    throw FlxException_Crude("flxlibs_interface::~flxlibs_interface_2");
  #endif
}

void flxlibs_interface::set_boxes(FlxObjectReadBox* objReadBoxV, FlxFunctionBox* funBoxV)
{
  objReadBox = objReadBoxV;
  funBox = funBoxV;
}

void flxlibs_interface::free_memory()
{
  for (std::list<std::string>::iterator it = obj_list.begin(); it!=obj_list.end(); ++it) {
    FlxObjReadBase* to = objReadBox->get(*it);
    #if FLX_DEBUG
      if (to==NULL) throw FlxException_Crude("flxlibs_interface::~flxlibs_interface_1");
    #endif
    objReadBox->remove(*it);
    delete to;
  }
  obj_list.clear();
  for (std::list<std::string>::iterator it = fun_list.begin(); it!=fun_list.end(); ++it) {
    FunReadFunBase* to = funBox->get(*it);
    funBox->remove(*it);
    if (to) delete to;
  }
  fun_list.clear();
}


void flxlibs_interface::add_obj(const std::string name, FlxObjReadBase* obj)
{
  obj_list.push_back(name);
  objReadBox->insert(name, obj); 
}

void flxlibs_interface::add_fun(const std::string name, FunReadFunBase* fun)
{
  fun_list.push_back(name);
  funBox->insert(name, fun);
}



