HermesCommon  2.0
api.cpp
1 // This file is part of Hermes2D
2 //
3 // Copyright (c) 2009 hp-FEM group at the University of Nevada, Reno (UNR).
4 // Email: hpfem-group@unr.edu, home page: http://hpfem.org/.
5 //
6 // Hermes2D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published
8 // by the Free Software Foundation; either version 2 of the License,
9 // or (at your option) any later version.
10 //
11 // Hermes2D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with Hermes2D; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20 #include "api.h"
21 #include <utility>
22 #include "callstack.h"
23 #include "common.h"
24 #include "exceptions.h"
25 #include "matrix.h"
26 
27 namespace Hermes
28 {
29  Api::Parameter::Parameter(int default_val)
30  {
31  this->default_val = default_val;
32  this->user_set = false;
33  }
34 
35  Api::Api()
36  {
37  signal(SIGABRT, CallStack::dump);
38  signal(SIGFPE, CallStack::dump);
39  signal(SIGILL, CallStack::dump);
40  signal(SIGSEGV, CallStack::dump);
41  signal(SIGTERM, CallStack::dump);
42 
43  this->parameters.insert(std::pair<HermesCommonApiParam, Parameter*> (Hermes::exceptionsPrintCallstack,new Parameter(0)));
44  this->parameters.insert(std::pair<HermesCommonApiParam, Parameter*> (Hermes::matrixSolverType,new Parameter(SOLVER_UMFPACK)));
45  }
46 
47  Api::~Api()
48  {
49  this->parameters.clear();
50  }
51 
52  int Api::get_integral_param_value(HermesCommonApiParam param)
53  {
54  if(this->parameters.find(param) == parameters.end())
55  throw Hermes::Exceptions::Exception("Wrong Hermes::Api parameter name:%i", param);
56  if(this->parameters.find(param)->second->user_set)
57  return this->parameters.find(param)->second->user_val;
58  else
59  return this->parameters.find(param)->second->default_val;
60  }
61 
62  void Api::set_integral_param_value(HermesCommonApiParam param, int value)
63  {
64  if(this->parameters.find(param) == parameters.end())
65  throw Hermes::Exceptions::Exception("Wrong Hermes::Api parameter name:%i", param);
66  this->parameters.find(param)->second->user_set = true;
67  this->parameters.find(param)->second->user_val = value;
68  }
69 
71 }