8 : job(
std::move(job)) {}
24 : callbacks(callbacks) {}
30 for (
const auto& callback : callbacks) {
34 control.
addAccessor(callback.owner.lock(), functor);
41 if (!accessors.empty()) {
53 accessors.insert(owner, accessor);
66 "Cannot connect node '" + job->
instanceName() +
"', it does not return any data.");
67 }
else if (provided.
value() != slots[slotName]) {
70 "', the slot expects different type of node.");
74 dependents.
push(node);
81 for (
const auto& element : slots) {
82 list += element.key +
", ";
85 "'.\nShould be one of: " + list);
91 bool dependentRemoved =
false;
93 for (
Size i = 0; i < dependents.
size(); ++i) {
94 if (dependents[i].lock() == dependent) {
96 dependentRemoved =
true;
100 if (!dependentRemoved) {
102 "Node '" + dependent->
instanceName() +
"' to be disconnected is not a dependent node.");
108 bool providerRemoved =
false;
109 for (
auto& element : dependent->providers) {
110 if (element.value ==
self) {
111 dependent->providers.
remove(element.key);
112 providerRemoved =
true;
116 if (!providerRemoved) {
118 "' to be disconnected does not list node '" + this->instanceName() +
127 while (!dependents.
empty()) {
139 if (index >= slots.
size()) {
141 "' has only " + std::to_string(slots.
size()) +
" slots");
144 const auto iter = slots.
begin() + index;
145 const bool used = required.
contains(iter->key);
148 if (
auto optProvider = providers.
tryGet(iter->key)) {
149 provider = optProvider.value();
151 return { iter->key, iter->value, used, provider };
155 return dependents.
size();
159 return dependents[index].lock();
167 std::set<JobNode*> visited;
173 std::set<JobNode*>& visited) {
174 auto pair = visited.insert(
this);
179 for (
auto& element : providers) {
180 element.value->enumerate(func, depth + 1, visited);
185 std::set<JobNode*> visited;
186 this->
run(global, callbacks, visited);
190 std::set<JobNode*> visited;
191 this->
prepare(global, callbacks, visited);
196 for (
auto& element : providers) {
197 if (!job->requires().contains(element.key)) {
203 if (visited.find(&*provider) == visited.end()) {
204 visited.insert(&*provider);
205 provider->
run(global, callbacks, visited);
211 result = result.
clone();
213 job->inputs.insert(element.key, result);
218 this->
prepare(global, callbacks, visited);
225 job->evaluate(global, callbacks);
229 callbacks.
onEnd(data->storage, data->stats);
235 for (
auto& element : providers) {
251 if (name !=
"name") {
257 static std::string clonedName(
const std::string& name) {
258 const std::size_t n1 = name.find_last_of(
'(');
259 const std::size_t n2 = name.find_last_of(
')');
260 if (n1 != std::string::npos && n2 != std::string::npos && n1 < n2) {
261 const std::string numStr = name.substr(n1 + 1, n2 - n1 - 1);
262 const int num = stoi(numStr);
263 return name.substr(0, n1) +
" (" + std::to_string(num + 1) +
")";
265 return name +
" (1)";
279 return makeAuto<JobNode>(std::move(job));
295 nodeMap.
insert(node, clonedNode);
303 nodeMap[slot.
provider]->connect(nodeMap[node], slot.
name);
#define SPH_ASSERT(x,...)
uint32_t Size
Integral type used to index arrays (by default).
RawPtr< IJobDesc > getJobDesc(const std::string &name)
Returns a job descriptor for given class name.
SharedPtr< JobNode > cloneHierarchy(JobNode &node, const Optional< std::string > &prefix)
Clones all nodes in the hierarchy.
AutoPtr< JobNode > cloneNode(const JobNode &node, const std::string &name)
Clones a single node.
#define NAMESPACE_SPH_END
Holder of quantity values and their temporal derivatives.
Statistics gathered and periodically displayed during the run.
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
void remove(const TCounter idx)
Removes an element with given index from the array.
INLINE T & back() noexcept
INLINE TCounter size() const noexcept
INLINE bool empty() const noexcept
INLINE RawPtr< T > get() const
CopyEntriesProc(VirtualSettings &target)
virtual void onEntry(const std::string &name, IVirtualEntry &entry) const override
Called for every entry in the current category.
virtual void onCategory(const std::string &UNUSED(name)) const override
Helper object, allowing to add units, tooltips and additional properties into the entry created with ...
EntryControl & addAccessor(const SharedToken &owner, const Accessor &accessor)
Adds a functor called when the entry changes, i.e. when set function is called.
Container of key-value pairs.
INLINE TValue & insert(const TKey &key, const TValue &value)
Adds a new element into the map or sets new value of element with the same key.
Interface used during job evaluation.
virtual void onEnd(const Storage &storage, const Statistics &stats)=0
Notifies the caller that the current job ended.
virtual void onStart(const IJob &job)=0
Notifies the caller that a new job started running.
virtual JobContext getResult() const =0
Returns the result of the job.
virtual UnorderedMap< std::string, ExtJobType > getSlots() const =0
Lists all potential inputs of the job.
virtual VirtualSettings getSettings()=0
Returns a settings object which allows to query and modify the state of the job.
virtual std::string instanceName() const
Unique name representing this job.
virtual std::string className() const =0
Name representing the type of the job (e.e. "SPH").
virtual UnorderedMap< std::string, ExtJobType > requires() const
List of slots that need to be connected to evaluate the job.
virtual Optional< ExtJobType > provides() const =0
Specifies the type of the job, i.e. what kind of data the job provides.
virtual bool shouldAbortRun() const =0
Returns whether current run should be aborted or not.
Represents a virtual entry in the settings.
virtual Value get() const =0
Returns the currently stored value.
Thrown when components of the run are mutually incompatible.
JobContext clone() const
Duplicates the stored data.
void release()
Releases all allocated data.
SharedPtr< TValue > tryGetValue() const
Returns the stored value or nullptr if the provided type TValue does not match the type of the stored...
Building block of a simulation hierarchy.
Size getSlotCnt() const
Returns the number of provider slots of this node.
virtual void run(const RunSettings &global, IJobCallbacks &callbacks) override
Evaluates the node and all its providers.
void addAccessor(const SharedToken &owner, const Accessor &accessor)
Adds an accessor for entries returned by the getSettings function.
Size getDependentCnt() const
Returns the number of dependent nodes.
std::string instanceName() const
Returns the instance name of the job.
std::string className() const
Returns the class name of the job.
Optional< ExtJobType > provides() const
Returns the type of the job.
RawPtr< IJob > getJob() const
Returns the underlying job.
SlotData getSlot(const Size index) const
Returns the information about given slot.
virtual void prepare(const RunSettings &global, IJobCallbacks &callbacks)
Evaluates all provides, without executing the node itself.
void disconnect(SharedPtr< JobNode > dependent)
Disconnects this node from given dependent node.
void disconnectAll()
Disconnects all dependent nodes from this node.
void connect(SharedPtr< JobNode > dependent, const std::string &slotName)
Connects this node to given dependent node.
SharedPtr< JobNode > getDependent(const Size index) const
Returns a dependent node with given index.
JobNode(AutoPtr< IJob > &&job)
Creates a new node, given a job object.
void enumerate(Function< void(const SharedPtr< JobNode > &job)> func)
Enumerates all nodes in the hierarchy.
VirtualSettings getSettings() const
Returns settings object allowing to access and modify the state of the job.
Wrapper of type value of which may or may not be present.
INLINE Type & value()
Returns the reference to the stored value.
Non-owning wrapper of pointer.
virtual void onCategory(const std::string &UNUSED(name)) const override
virtual void onEntry(const std::string &key, IVirtualEntry &entry) const override
Called for every entry in the current category.
SetAccessorsProc(const CallbackSet< JobNode::Accessor > &callbacks)
SharedPtr< JobNode > sharedFromThis() const
Object holding various statistics about current run.
Container storing all quantities used within the simulations.
INLINE Size size() const
Returns the number of elements in the map.
INLINE bool contains(const TKey &key) const
Returns true if the map contains element of given key.
INLINE TValue & insert(const TKey &key, const TValue &value)
Adds a new element into the map or sets new value of element with the same key.
INLINE Iterator< Element > begin()
Returns the iterator pointing to the first element.
INLINE void remove(const TKey &key)
Removes element with given key from the map.
INLINE Optional< TValue & > tryGet(const TKey &key)
Returns a reference to the value matching the given key, or NOTHING if no such value exists.
Variant, an implementation of type-safe union, similar to std::variant or boost::variant.
Interface allowing to enumerate all entries in the settings.
Holds a map of virtual entries, associated with a unique name.
void enumerate(const IEntryProc &proc)
Enumerates all entries stored in the settings.
void set(const std::string &key, const IVirtualEntry::Value &value)
Modifies an existing entry in the settings.
SharedPtr< T > lock() const
Overload of std::swap for Sph::Array.
std::string name
Identifier of the slot, used by the job to obtain the provided data.
SharedPtr< JobNode > provider
Node currently connected to the slot.