/* Fesslix - Stochastic Analysis
 * Copyright (C) 2010-2016 Wolfgang Betz
 *
 * Fesslix is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Fesslix is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Fesslix.  If not, see <http://www.gnu.org/licenses/>. 
 */

#include "flxlibs_interface.h"

#ifdef __WINDOWS__
  #pragma comment(lib, "flxlib")
  #pragma comment(lib, "flxkernel")
#endif


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);
}



