Hermes2D  3.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://www.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 using namespace xercesc;
27 
28 namespace Hermes
29 {
30  namespace Hermes2D
31  {
32  template<typename T>
34  {
35  this->default_val = default_val;
36  this->user_set = false;
37  }
38 
39  template<typename T>
41  {
42  }
43 
44  Api2D::Api2D()
45  {
46  // Xerces initialization - for better performance.
47  XMLPlatformUtils::Initialize();
48 
49  this->text_parameters.insert(std::pair<Hermes2DApiParam, Parameter<std::string>*>(Hermes::Hermes2D::xmlSchemasDirPath, new Parameter<std::string>(std::string(H2D_XML_SCHEMAS_DIRECTORY))));
50  std::stringstream ss;
51  ss << H2D_PRECALCULATED_FORMS_DIRECTORY;
52  if (ss.str().at(ss.str().length() - 1) == '\\' || ss.str().at(ss.str().length() - 1) == '/')
53  this->text_parameters.insert(std::pair<Hermes2DApiParam, Parameter<std::string>*>(Hermes::Hermes2D::precalculatedFormsDirPath, new Parameter<std::string>(std::string(H2D_PRECALCULATED_FORMS_DIRECTORY))));
54  else
55  {
56  ss << '/';
57  this->text_parameters.insert(std::pair<Hermes2DApiParam, Parameter<std::string>*>(Hermes::Hermes2D::precalculatedFormsDirPath, new Parameter<std::string>(std::string(ss.str()))));
58  }
59 
60  XMLPlatformUtils::Terminate();
61 
62 #ifdef WITH_PJLIB
63  pj_init();
64  pj_caching_pool_init(&Hermes2DMemoryPoolCache, NULL, 1024 * 1024 * 1024);
65 #endif
66  }
67 
68  Api2D::~Api2D()
69  {
70  for (std::map<Hermes2DApiParam, Parameter<std::string>*>::const_iterator it = this->text_parameters.begin(); it != this->text_parameters.end(); ++it)
71  delete it->second;
72 
73  for (std::map<Hermes2DApiParam, Parameter<int>*>::const_iterator it = this->integral_parameters.begin(); it != this->integral_parameters.end(); ++it)
74  delete it->second;
75 
76 #ifdef WITH_PJLIB
77  pj_caching_pool_destroy(&Hermes2DMemoryPoolCache);
78 #endif
79  }
80 
81  int Api2D::get_integral_param_value(Hermes2DApiParam param)
82  {
83  if (this->integral_parameters.find(param) == integral_parameters.end())
84  throw Hermes::Exceptions::Exception("Wrong Hermes::Api parameter name:%i", param);
85  if (this->integral_parameters.find(param)->second->user_set)
86  return this->integral_parameters.find(param)->second->user_val;
87  else
88  return this->integral_parameters.find(param)->second->default_val;
89  }
90 
91  void Api2D::set_integral_param_value(Hermes2DApiParam param, int value)
92  {
93  if (this->integral_parameters.find(param) == integral_parameters.end())
94  throw Hermes::Exceptions::Exception("Wrong Hermes::Api parameter name:%i", param);
95  this->integral_parameters.find(param)->second->user_set = true;
96  this->integral_parameters.find(param)->second->user_val = value;
97  }
98 
99  std::string Api2D::get_text_param_value(Hermes2DApiParam param)
100  {
101  if (this->text_parameters.find(param) == text_parameters.end())
102  throw Hermes::Exceptions::Exception("Wrong Hermes::Api parameter name:%i", param);
103  if (this->text_parameters.find(param)->second->user_set)
104  return this->text_parameters.find(param)->second->user_val;
105  else
106  return this->text_parameters.find(param)->second->default_val;
107  }
108 
109  void Api2D::set_text_param_value(Hermes2DApiParam param, std::string value)
110  {
111  if (this->text_parameters.find(param) == text_parameters.end())
112  throw Hermes::Exceptions::Exception("Wrong Hermes::Api parameter name:%i", param);
113  this->text_parameters.find(param)->second->user_val = value;
114  this->text_parameters.find(param)->second->user_set = true;
115  }
116 
118 #ifdef WITH_PJLIB
119  pj_caching_pool HERMES_API Hermes2DMemoryPoolCache;
120 #endif
121  }
122 }
Definition: adapt.h:24
HERMES_API Hermes::Hermes2D::Api2D Hermes2DApi
Global instance used inside Hermes which is also accessible to users.
Definition: api2d.cpp:117
Hermes2DApiParam
Enumeration of potential keys in the Api2D::parameters storage.
Definition: api2d.h:38
API Class containing settings for the whole Hermes2D.
Definition: api2d.h:45
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.