SPH
Job.inl.h
Go to the documentation of this file.
1 #include "Job.h" // only for syntax highlighting
2 
4 
5 template <typename TValue>
6 class JobData : public IJobData {
7 private:
8  SharedPtr<TValue> value;
9 
10 public:
11  explicit JobData(SharedPtr<TValue> value)
12  : value(value) {}
13 
15  return value;
16  }
17 };
18 
19 template <typename TValue>
21  data = makeShared<JobData<TValue>>(value);
22 }
23 
24 template <typename TValue>
26  SharedPtr<TValue> value = this->tryGetValue<TValue>();
27  if (value) {
28  return value;
29  } else {
30  throw InvalidSetup("Expected different type when accessing job context.");
31  }
32 }
33 
34 template <typename TValue>
36  RawPtr<JobData<TValue>> typedData = dynamicCast<JobData<TValue>>(data.get());
37  if (typedData != nullptr) {
38  return typedData->getValue();
39  } else {
40  return nullptr;
41  }
42 }
43 
44 template <typename T>
45 SharedPtr<T> IJob::getInput(const std::string& name) const {
46  if (!inputs.contains(name)) {
47  throw InvalidSetup(
48  "Input '" + name + "' for job '" + instName +
49  "' was not found, either it was not connected or the node has not been successfully evaluated.");
50  }
51 
52  JobContext context = inputs[name];
53  return context.getValue<T>();
54 }
55 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
#define NAMESPACE_SPH_END
Definition: Object.h:12
Definition: Job.h:18
SharedPtr< T > getInput(const std::string &name) const
Convenient function to return input data for slot of given name.
Definition: Job.inl.h:45
std::string instName
Definition: Job.h:100
UnorderedMap< std::string, JobContext > inputs
Contains all input data, identified by names of input slots.
Definition: Job.h:103
Thrown when components of the run are mutually incompatible.
Definition: Exceptions.h:24
Data exchanged by jobs.
Definition: Job.h:52
JobContext()=default
SharedPtr< TValue > tryGetValue() const
Returns the stored value or nullptr if the provided type TValue does not match the type of the stored...
Definition: Job.inl.h:35
SharedPtr< TValue > getValue() const
Returns the stored value.
Definition: Job.inl.h:25
Definition: Job.inl.h:6
JobData(SharedPtr< TValue > value)
Definition: Job.inl.h:11
SharedPtr< TValue > getValue() const
Definition: Job.inl.h:14
Non-owning wrapper of pointer.
Definition: RawPtr.h:19
INLINE RawPtr< T > get() const
Definition: SharedPtr.h:223
INLINE bool contains(const TKey &key) const
Returns true if the map contains element of given key.
Definition: UnorderedMap.h:126