// SpaFEDTe, a Template based C++ library for creating 
// Discontinuous Finite Element Spaces,
// Copyright (C) 2012 Lorenzo Alessio Botti

/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */ 
/* License as published by the Free Software Foundation either */ 
/* version 3.0 of the License, or (at your option) any later version. */

/* This software 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 */
/* Lesser General Public License for more details. */

/* You should have received a copy of the GNU Lesser General Public */
/* License along with this software; if not, a copy of the full */
/* GNU Lesser General Public License can be found at */
/* http://www.gnu.org/licenses/ */

#include "FELib.hpp"

namespace FELib
{
  namespace FELibPrivateData 
  {
    extern bool _is_initialized;
  }
 
  bool FELib::FELibPrivateData::_is_initialized = false;
  int FELib::FELibPrivateData::_n_processors = 1;
  int FELib::FELibPrivateData::_processor_id = 0;
  
  bool initialized()
  {
     return FELibPrivateData::_is_initialized;
  }
  
  bool closed()
  {
     return !FELibPrivateData::_is_initialized;
  }
  
  void _init(int& argc, char** & argv)
  {
    assert (!FELib::initialized());
  
    FELibPrivateData::_n_processors = 1;
    FELibPrivateData::_processor_id = 0;
    FELibPrivateData::_is_initialized = true;
  }
  
  void _close()
  {
    assert(!FELib::closed());
  
    if (std::uncaught_exception())
    {  
        std::cerr << "Uncaught exception - aborting" << std::endl;
    }
    FELibPrivateData::_is_initialized = false;
  }
    
  FELibInit::FELibInit(int& argc, char** & argv) 
  {
    FELib::_init(argc, argv);
  }
    
  FELibInit::~FELibInit() 
  {
    FELib::_close();
  }

}
