suanPan
Loading...
Searching...
No Matches
ExternalModule.h
Go to the documentation of this file.
1/*******************************************************************************
2 * Copyright (C) 2017-2025 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(std::string);
50
51public:
52 const std::string library_name;
53
54 explicit ExternalModule(std::string);
60
61 bool locate_c_module(const std::string&);
62 bool locate_cpp_module(const std::string&);
63
64 template<typename T> void new_object(unique_ptr<T>& return_obj, std::istringstream& command) const {
65 if(ext_creator) reinterpret_cast<void (*)(unique_ptr<T>&, std::istringstream&)>(ext_creator)(return_obj, command);
66 }
67
68 void new_adapter(unique_ptr<Element>&, std::istringstream&) const;
69 void new_adapter(unique_ptr<Load>&, std::istringstream&) const;
70 void new_adapter(unique_ptr<Material>&, std::istringstream&) const;
71 void new_adapter(unique_ptr<Section>&, std::istringstream&) const;
72 void new_adapter(unique_ptr<Solver>&, std::istringstream&) const;
73 void new_adapter(unique_ptr<Amplitude>&, std::istringstream&) const;
74 void new_adapter(unique_ptr<Modifier>&, std::istringstream&) const;
75 void new_adapter(unique_ptr<Constraint>&, std::istringstream&) const;
76};
77
78namespace external_module {
79 template<typename T> void object(unique_ptr<T>& new_object, const shared_ptr<DomainBase>& domain, const std::string& id, std::istringstream& command) {
80 // check if the library is already loaded
81 auto loaded = false;
82 for(const auto& I : domain->get_external_module_pool())
83 if(is_equal(I->library_name, id) || I->locate_cpp_module(id) || I->locate_c_module(id)) {
84 loaded = true;
85 break;
86 }
87
88 // not loaded then try load it
89 // if loaded find corresponding function
90 if(loaded || domain->insert(std::make_shared<ExternalModule>(id)))
91 for(const auto& I : domain->get_external_module_pool()) {
92 if(I->locate_cpp_module(id)) I->new_object(new_object, command);
93 if(new_object != nullptr) break;
94 if(I->locate_c_module(id)) I->new_adapter(new_object, command);
95 if(new_object != nullptr) break;
96 }
97 }
98} // namespace external_module
99
100#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:118
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:116
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
bool locate_c_module(const std::string &)
Definition ExternalModule.cpp:97
ExternalModule & operator=(const ExternalModule &)=delete
bool locate_cpp_module(const std::string &)
Definition ExternalModule.cpp:99
~ExternalModule()
Definition ExternalModule.cpp:89
void new_adapter(unique_ptr< Element > &, std::istringstream &) const
Definition ExternalModule.cpp:101
ExternalModule(const ExternalModule &)=delete
ExternalModule(ExternalModule &&)=delete
const std::string library_name
Definition ExternalModule.h:52
void object(unique_ptr< T > &new_object, const shared_ptr< DomainBase > &domain, const std::string &id, std::istringstream &command)
Definition ExternalModule.h:79
void new_object(unique_ptr< T > &return_obj, std::istringstream &command) const
Definition ExternalModule.h:64
ExternalModule & operator=(ExternalModule &&)=delete
Definition ExternalModule.h:78
bool is_equal(const char *A, const char *B)
Definition utility.cpp:104