suanPan
ExternalModule.h
Go to the documentation of this file.
1/*******************************************************************************
2 * Copyright (C) 2017-2024 Theodore Chang
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 ******************************************************************************/
30#ifndef EXTERNALMODULE_H
31#define EXTERNALMODULE_H
32
33#include <Domain/DomainBase.h>
34#include <Toolbox/utility.h>
35
36class Element;
37class Load;
38class Material;
39class Section;
40class Solver;
41class Amplitude;
42class Modifier;
43class Constraint;
44
46 void* ext_library = nullptr;
47 void* ext_creator = nullptr;
48
49 bool locate_module(string);
50
51public:
52 const string library_name;
53
54 explicit ExternalModule(string);
60
61 bool locate_c_module(const string&);
62 bool locate_cpp_module(const string&);
63
64 void new_object(unique_ptr<Element>&, istringstream&) const;
65 void new_object(unique_ptr<Load>&, istringstream&) const;
66 void new_object(unique_ptr<Material>&, istringstream&) const;
67 void new_object(unique_ptr<Section>&, istringstream&) const;
68 void new_object(unique_ptr<Solver>&, istringstream&) const;
69 void new_object(unique_ptr<Amplitude>&, istringstream&) const;
70 void new_object(unique_ptr<Modifier>&, istringstream&) const;
71 void new_object(unique_ptr<Constraint>&, istringstream&) const;
72
73 void new_adapter(unique_ptr<Element>&, istringstream&) const;
74 void new_adapter(unique_ptr<Load>&, istringstream&) const;
75 void new_adapter(unique_ptr<Material>&, istringstream&) const;
76 void new_adapter(unique_ptr<Section>&, istringstream&) const;
77 void new_adapter(unique_ptr<Solver>&, istringstream&) const;
78 void new_adapter(unique_ptr<Amplitude>&, istringstream&) const;
79 void new_adapter(unique_ptr<Modifier>&, istringstream&) const;
80 void new_adapter(unique_ptr<Constraint>&, istringstream&) const;
81};
82
83class load {
84public:
85 template<typename T> static void object(unique_ptr<T>&, const shared_ptr<DomainBase>&, const string&, istringstream&);
86};
87
88template<typename T> void load::object(unique_ptr<T>& new_object, const shared_ptr<DomainBase>& domain, const string& id, istringstream& command) {
89 // check if the library is already loaded
90 auto loaded = false;
91 for(const auto& I : domain->get_external_module_pool())
92 if(is_equal(I->library_name, id) || I->locate_cpp_module(id) || I->locate_c_module(id)) {
93 loaded = true;
94 break;
95 }
96
97 // not loaded then try load it
98 // if loaded find corresponding function
99 if(loaded || domain->insert(make_shared<ExternalModule>(id)))
100 for(const auto& I : domain->get_external_module_pool()) {
101 if(I->locate_cpp_module(id)) I->new_object(new_object, command);
102 if(new_object != nullptr) break;
103 if(I->locate_c_module(id)) I->new_adapter(new_object, command);
104 if(new_object != nullptr) break;
105 }
106}
107
108#endif
An Amplitude class that can generate Amplitude pattern.
Definition: Amplitude.h:67
A Constraint class.
Definition: Constraint.h:36
A Element class.
Definition: Element.h:117
A ExternalModule class handles communication between the main program and external library.
Definition: ExternalModule.h:45
A Load class.
Definition: Load.h:37
A Material abstract base class.
Definition: Material.h:111
A Modifier class.
Definition: Modifier.h:36
A Section class.
Definition: Section.h:77
A Solver class defines solvers used in analysis.
Definition: Solver.h:38
Definition: ExternalModule.h:83
ExternalModule & operator=(const ExternalModule &)=delete
~ExternalModule()
Definition: ExternalModule.cpp:94
ExternalModule(string)
Definition: ExternalModule.cpp:54
bool locate_c_module(const string &)
Definition: ExternalModule.cpp:102
void new_object(unique_ptr< Element > &, istringstream &) const
Definition: ExternalModule.cpp:106
ExternalModule(const ExternalModule &)=delete
ExternalModule(ExternalModule &&)=delete
bool locate_cpp_module(const string &)
Definition: ExternalModule.cpp:104
const string library_name
Definition: ExternalModule.h:52
static void object(unique_ptr< T > &, const shared_ptr< DomainBase > &, const string &, istringstream &)
Definition: ExternalModule.h:88
ExternalModule & operator=(ExternalModule &&)=delete
void new_adapter(unique_ptr< Element > &, istringstream &) const
Definition: ExternalModule.cpp:122
bool is_equal(const char *A, const char *B)
Definition: utility.cpp:103