helics 3.7.0
Loading...
Searching...
No Matches
CoreFactory.hpp
1/*
2Copyright (c) 2017-2026,
3Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Energy
4Innovation LLC. See the top-level NOTICE for additional details. All rights reserved.
5SPDX-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
18namespace helics {
25namespace CoreFactory {
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
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
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
Definition CoreFactory.hpp:27
Definition CoreFactory.hpp:34
Definition core/Core.hpp:41
void unregisterCore(std::string_view name)
Definition CoreFactory.cpp:468
size_t cleanUpCores()
Definition CoreFactory.cpp:410
void abortAllCores(int errorCode, std::string_view errorString)
Definition CoreFactory.cpp:444
std::vector< std::string > getAvailableCoreTypes()
Definition CoreFactory.cpp:179
std::shared_ptr< Core > getEmptyCore()
Definition CoreFactory.cpp:190
Core * getEmptyCorePtr()
Definition CoreFactory.cpp:195
std::shared_ptr< Core > FindOrCreate(CoreType type, std::string_view coreName, std::vector< std::string > args)
Definition CoreFactory.cpp:302
bool registerCore(const std::shared_ptr< Core > &core, CoreType type)
Definition CoreFactory.cpp:396
void terminateAllCores()
Definition CoreFactory.cpp:432
void addAssociatedCoreType(std::string_view name, CoreType type)
Definition CoreFactory.cpp:476
void displayHelp(CoreType type)
Definition CoreFactory.cpp:484
std::shared_ptr< Core > findCore(std::string_view name)
Definition CoreFactory.cpp:365
bool copyCoreIdentifier(std::string_view copyFromName, std::string_view copyToName)
Definition CoreFactory.cpp:463
size_t getCoreCount()
Definition CoreFactory.cpp:459
std::shared_ptr< Core > create(CoreType type, std::string_view configureString)
Definition CoreFactory.cpp:201
std::shared_ptr< CoreBuilder > addCoreType(std::string_view coreTypeName, int code)
Definition CoreFactory.hpp:53
std::shared_ptr< Core > findJoinableCoreOfType(CoreType type)
Definition CoreFactory.cpp:370
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition AsyncFedCallInfo.hpp:14
CoreType
Definition CoreTypes.hpp:46
@ UNRECOGNIZED
unknown