Hermes2D  2.0
api2d.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 "callstack.h"
21 #include "api.h"
22 #include "common.h"
23 #include "exceptions.h"
24 #include "api2d.h"
25 #include <xercesc/util/PlatformUtils.hpp>
26 
27 using namespace xercesc;
28 
29 namespace Hermes
30 {
31  namespace Hermes2D
32  {
33  template<typename T>
35  {
36  this->default_val = default_val;
37  this->user_set = false;
38  }
39 
40  Api2D::Api2D()
41  {
42  signal(SIGABRT, CallStack::dump);
43  signal(SIGFPE, CallStack::dump);
44  signal(SIGILL, CallStack::dump);
45  signal(SIGSEGV, CallStack::dump);
46  signal(SIGTERM, CallStack::dump);
47 
48  // Xerces initialization - for better performance.
49  XMLPlatformUtils::Initialize();
50 
51  this->integral_parameters.insert(std::pair<Hermes2DApiParam, Parameter<int>*> (Hermes::Hermes2D::numThreads,new Parameter<int>(NUM_THREADS)));
52  this->text_parameters.insert(std::pair<Hermes2DApiParam, Parameter<std::string>*> (Hermes::Hermes2D::xmlSchemasDirPath,new Parameter<std::string>(*(new std::string(H2D_XML_SCHEMAS_DIRECTORY)))));
53  std::stringstream ss;
54  ss << H2D_PRECALCULATED_FORMS_DIRECTORY;
55  if(ss.str().at(ss.str().length() - 1) == '\\' || ss.str().at(ss.str().length() - 1) == '/')
56  this->text_parameters.insert(std::pair<Hermes2DApiParam, Parameter<std::string>*> (Hermes::Hermes2D::precalculatedFormsDirPath,new Parameter<std::string>(*(new std::string(H2D_PRECALCULATED_FORMS_DIRECTORY)))));
57  else
58  {
59  ss << '/';
60  this->text_parameters.insert(std::pair<Hermes2DApiParam, Parameter<std::string>*> (Hermes::Hermes2D::precalculatedFormsDirPath,new Parameter<std::string>(*(new std::string(ss.str())))));
61  }
62 
63  XMLPlatformUtils::Terminate();
64  }
65 
66  Api2D::~Api2D()
67  {
68  for(std::map<Hermes2DApiParam, Parameter<std::string>*>::const_iterator it = this->text_parameters.begin(); it != this->text_parameters.end(); ++it)
69  delete it->second;
70 
71  for(std::map<Hermes2DApiParam, Parameter<int>*>::const_iterator it = this->integral_parameters.begin(); it != this->integral_parameters.end(); ++it)
72  delete it->second;
73  }
74 
75  int Api2D::get_integral_param_value(Hermes2DApiParam param)
76  {
77  if(this->integral_parameters.find(param) == integral_parameters.end())
78  throw Hermes::Exceptions::Exception("Wrong Hermes::Api parameter name:%i", param);
79  if(this->integral_parameters.find(param)->second->user_set)
80  return this->integral_parameters.find(param)->second->user_val;
81  else
82  return this->integral_parameters.find(param)->second->default_val;
83  }
84 
85  void Api2D::set_integral_param_value(Hermes2DApiParam param, int value)
86  {
87  if(this->integral_parameters.find(param) == integral_parameters.end())
88  throw Hermes::Exceptions::Exception("Wrong Hermes::Api parameter name:%i", param);
89  this->integral_parameters.find(param)->second->user_set = true;
90  this->integral_parameters.find(param)->second->user_val = value;
91  }
92 
93  std::string Api2D::get_text_param_value(Hermes2DApiParam param)
94  {
95  if(this->text_parameters.find(param) == text_parameters.end())
96  throw Hermes::Exceptions::Exception("Wrong Hermes::Api parameter name:%i", param);
97  if(this->text_parameters.find(param)->second->user_set)
98  return this->text_parameters.find(param)->second->user_val;
99  else
100  return this->text_parameters.find(param)->second->default_val;
101  }
102 
103  void Api2D::set_text_param_value(Hermes2DApiParam param, std::string value)
104  {
105  if(this->text_parameters.find(param) == text_parameters.end())
106  throw Hermes::Exceptions::Exception("Wrong Hermes::Api parameter name:%i", param);
107  this->text_parameters.find(param)->second->user_set = true;
108  this->text_parameters.find(param)->second->user_val = value;
109  }
110 
112  }
113 }