| helics 3.6.1

CoreFactory.hpp
1 /*
2 Copyright (c) 2017-2025,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7 #pragma once
8
9 #include "Core.hpp"
10 #include "CoreTypes.hpp"
11
12 #include <chrono>
13 #include <memory>
14 #include <string>
15 #include <type_traits>
16 #include <vector>
17
18 namespace helics {
25 namespace CoreFactory {
27 class CoreBuilder {
28 public:
29 virtual std::shared_ptr<Core> build(std::string_view name) = 0;
30 };
31
33 template<class CoreTYPE>
34 class CoreTypeBuilder final: public CoreBuilder {
35 public:
36 static_assert(std::is_base_of<Core, CoreTYPE>::value,
37 "Type does not inherit from helics::Core");
38
39 using core_build_type = CoreTYPE;
40 virtual std::shared_ptr<Core> build(std::string_view name) override
41 {
42 return std::make_shared<CoreTYPE>(name);
43 }
44 };
45
46 //** define a new Core Builder from the builder give a name and build code*/
47 void defineCoreBuilder(std::shared_ptr<CoreBuilder> builder,
48 std::string_view coreTypeName,
49 int code);
50
52 template<class CoreTYPE>
53 std::shared_ptr<CoreBuilder> addCoreType(std::string_view coreTypeName, int code)
54 {
55 auto bld = std::make_shared<CoreTypeBuilder<CoreTYPE>>();
56 std::shared_ptr<CoreBuilder> cbld = std::static_pointer_cast<CoreBuilder>(bld);
57 defineCoreBuilder(cbld, coreTypeName, code);
58 return cbld;
59 }
60
62 std::vector<std::string> getAvailableCoreTypes();
63
69 std::shared_ptr<Core>
70 create(CoreType type, std::string_view coreName, std::string_view configureString);
76 std::shared_ptr<Core> create(CoreType type, std::string_view configureString);
77
83 std::shared_ptr<Core> create(CoreType type, int argc, char* argv[]);
84
91 std::shared_ptr<Core> create(std::vector<std::string> args);
92
97 std::shared_ptr<Core> create(CoreType type, std::vector<std::string> args);
98
106 std::shared_ptr<Core> create(int argc, char* argv[]);
107
115 std::shared_ptr<Core> create(CoreType type, std::string_view coreName, int argc, char* argv[]);
116
123 std::shared_ptr<Core>
124 create(CoreType type, std::string_view coreName, std::vector<std::string> args);
125
128 std::shared_ptr<Core>
129 FindOrCreate(CoreType type, std::string_view coreName, std::string_view configureString);
130
133 std::shared_ptr<Core>
134 FindOrCreate(CoreType type, std::string_view coreName, int argc, char* argv[]);
135
138 std::shared_ptr<Core>
139 FindOrCreate(CoreType type, std::string_view coreName, std::vector<std::string> args);
141 std::shared_ptr<Core> findJoinableCoreOfType(CoreType type);
142
146 std::shared_ptr<Core> findCore(std::string_view name);
147
149 std::shared_ptr<Core> getEmptyCore();
150
152 Core* getEmptyCorePtr();
153
160 bool registerCore(const std::shared_ptr<Core>& core, CoreType type);
161
165 void unregisterCore(std::string_view name);
166
168 void addAssociatedCoreType(std::string_view name, CoreType type);
169
175 size_t cleanUpCores();
182 size_t cleanUpCores(std::chrono::milliseconds delay);
183
187 bool copyCoreIdentifier(std::string_view copyFromName, std::string_view copyToName);
188
190 void displayHelp(CoreType type = CoreType::UNRECOGNIZED);
191
193 void terminateAllCores();
195 void abortAllCores(int errorCode, std::string_view errorString);
196
198 size_t getCoreCount();
199 } // namespace CoreFactory
200
201 } // namespace helics
CoreTypes.hpp
helics::CoreFactory::CoreBuilder
Definition: CoreFactory.hpp:27
helics::CoreFactory::CoreTypeBuilder
Definition: CoreFactory.hpp:34
helics::Core
Definition: core/Core.hpp:41
helics::CoreFactory::unregisterCore
void unregisterCore(std::string_view name)
Definition: CoreFactory.cpp:410
helics::CoreFactory::cleanUpCores
size_t cleanUpCores()
Definition: CoreFactory.cpp:367
helics::CoreFactory::abortAllCores
void abortAllCores(int errorCode, std::string_view errorString)
Definition: CoreFactory.cpp:386
helics::CoreFactory::getAvailableCoreTypes
std::vector< std::string > getAvailableCoreTypes()
Definition: CoreFactory.cpp:98
helics::CoreFactory::getEmptyCore
std::shared_ptr< Core > getEmptyCore()
Definition: CoreFactory.cpp:124
helics::CoreFactory::getEmptyCorePtr
Core * getEmptyCorePtr()
Definition: CoreFactory.cpp:129
helics::CoreFactory::addCoreType
std::shared_ptr< CoreBuilder > addCoreType(std::string_view coreTypeName, int code)
Definition: CoreFactory.hpp:53
helics::CoreFactory::FindOrCreate
std::shared_ptr< Core > FindOrCreate(CoreType type, std::string_view coreName, std::vector< std::string > args)
Definition: CoreFactory.cpp:241
helics::CoreFactory::registerCore
bool registerCore(const std::shared_ptr< Core > &core, CoreType type)
Definition: CoreFactory.cpp:353
helics::CoreFactory::terminateAllCores
void terminateAllCores()
Definition: CoreFactory.cpp:377
helics::CoreFactory::addAssociatedCoreType
void addAssociatedCoreType(std::string_view name, CoreType type)
Definition: CoreFactory.cpp:417
helics::CoreFactory::displayHelp
void displayHelp(CoreType type)
Definition: CoreFactory.cpp:425
helics::CoreFactory::findCore
std::shared_ptr< Core > findCore(std::string_view name)
Definition: CoreFactory.cpp:323
helics::CoreFactory::copyCoreIdentifier
bool copyCoreIdentifier(std::string_view copyFromName, std::string_view copyToName)
Definition: CoreFactory.cpp:405
helics::CoreFactory::getCoreCount
size_t getCoreCount()
Definition: CoreFactory.cpp:401
helics::CoreFactory::findJoinableCoreOfType
std::shared_ptr< Core > findJoinableCoreOfType(CoreType type)
Definition: CoreFactory.cpp:328
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::CoreType
CoreType
Definition: CoreTypes.hpp:46
helics::CoreType::UNRECOGNIZED
@ UNRECOGNIZED
unknown