Utopia  2
Framework for studying models of complex & adaptive systems.
write_task.hh
Go to the documentation of this file.
1 #ifndef UTOPIA_DATAIO_DATA_MANAGER_WRITE_TASK_HH
2 #define UTOPIA_DATAIO_DATA_MANAGER_WRITE_TASK_HH
3 
4 // metaprogramming
5 #include "../../core/metaprogramming.hh"
6 #include "../../core/type_traits.hh"
7 
8 // for hdf5 support
9 #include "../hdfdataset.hh"
10 #include "../hdfgroup.hh"
11 
12 namespace Utopia
13 {
14 namespace DataIO
15 {
16 
48 template < class BGB, class DW, class DB, class AWG, class AWD >
49 struct WriteTask final // inheriting from this thing is useless, hence can be final
50 {
51  using BasegroupBuilder = BGB;
52  using Writer = DW;
53  using Builder = DB;
54  using AttributeWriterGroup = AWG;
56 
61 
65  std::shared_ptr< HDFGroup > base_group;
66 
70  std::shared_ptr< HDFDataset> active_dataset;
71 
76 
81 
86 
92 
98  std::string
100  {
101  if (active_dataset != nullptr)
102  {
103  return active_dataset->get_path();
104  }
105  else
106  {
107  return "";
108  }
109  }
110 
116  std::string
118  {
119  if (base_group != nullptr)
120  {
121  return base_group->get_path();
122  }
123  else
124  {
125  return "";
126  }
127  }
128 
134  void
135  swap(WriteTask& other)
136  {
137  if (this == &other)
138  {
139  return;
140  }
141  else
142  {
143  using std::swap;
145  swap(base_group, other.base_group);
147  swap(write_data, other.write_data);
152  }
153  }
154 
169  template < typename Basegroupbuilder,
170  typename Writertype,
171  typename Buildertype,
172  typename AWritertypeG,
173  typename AWritertypeD >
174  WriteTask(Basegroupbuilder&& bgb,
175  Writertype&& w,
176  Buildertype&& b,
177  AWritertypeG&& ag,
178  AWritertypeD&& ad) :
179  build_basegroup(bgb),
180  base_group(nullptr), active_dataset(nullptr), write_data(w),
183  {
184  }
185 
189  WriteTask() = default;
190 
197  WriteTask(const WriteTask& other) = default;
198 
204  WriteTask(WriteTask&& other) = default;
205 
212  WriteTask&
213  operator=(const WriteTask& other) = default;
214 
221  WriteTask&
222  operator=(WriteTask&& other) = default;
223 
227  ~WriteTask() = default;
228 };
229 
238 template < class BGB, class DW, class DB, class AWG, class AWD >
239 void
242 {
243  lhs.swap(rhs);
244 }
245 
246 // Deduction guide for WriteTask
247 template < typename Basegroupbuilder,
248  typename Writertype,
249  typename Buildertype,
250  typename AWritertypeG,
251  typename AWritertypeD >
252 WriteTask(Basegroupbuilder&& bgb,
253  Writertype&& w,
254  Buildertype&& b,
255  AWritertypeG&& ad,
256  AWritertypeD&& ag)
257  ->WriteTask< std::decay_t< Basegroupbuilder >,
258  std::decay_t< Writertype >,
259  std::decay_t< Buildertype >,
260  std::decay_t< AWritertypeG >,
261  std::decay_t< AWritertypeD > >;
262 
267 } // namespace DataIO
268 } // namespace Utopia
269 
270 #endif
void swap(WriteTask< BGB, DW, DB, AWG, AWD > &lhs, WriteTask< BGB, DW, DB, AWG, AWD > &rhs)
Swaps the state of lhs and rhs.
Definition: write_task.hh:240
WriteTask(Basegroupbuilder &&bgb, Writertype &&w, Buildertype &&b, AWritertypeG &&ad, AWritertypeD &&ag) -> WriteTask< std::decay_t< Basegroupbuilder >, std::decay_t< Writertype >, std::decay_t< Buildertype >, std::decay_t< AWritertypeG >, std::decay_t< AWritertypeD > >
Definition: agent.hh:11
Encapsulate a task for writing data to a destination. Containes a callable 'writer' responisible for ...
Definition: write_task.hh:50
WriteTask(const WriteTask &other)=default
Writer write_data
Callable to write data.
Definition: write_task.hh:75
WriteTask()=default
Construct a new writer Task object.
std::shared_ptr< HDFDataset > active_dataset
pointer to the dataset which is currently active
Definition: write_task.hh:70
std::string get_base_path()
Get the path to the base group object.
Definition: write_task.hh:117
AWD AttributeWriterDataset
Definition: write_task.hh:55
BasegroupBuilder build_basegroup
Function building a base group.
Definition: write_task.hh:60
WriteTask(WriteTask &&other)=default
Construct a new writer Task object.
AWG AttributeWriterGroup
Definition: write_task.hh:54
WriteTask(Basegroupbuilder &&bgb, Writertype &&w, Buildertype &&b, AWritertypeG &&ag, AWritertypeD &&ad)
Construct a new Write Task object.
Definition: write_task.hh:174
WriteTask & operator=(const WriteTask &other)=default
Copy assign caller from 'other'.
Builder build_dataset
Callable to build new dataset.
Definition: write_task.hh:80
std::string get_active_path()
Get the path of active dataset relative to the base_group.
Definition: write_task.hh:99
void swap(WriteTask &other)
Swap the state of the caller with 'other'.
Definition: write_task.hh:135
BGB BasegroupBuilder
Definition: write_task.hh:51
std::shared_ptr< HDFGroup > base_group
pointer to the hdfgroup in which all produced datasets live.
Definition: write_task.hh:65
AttributeWriterDataset write_attribute_active_dataset
Callable to write attributes to dataset; invoked after task write.
Definition: write_task.hh:85
WriteTask & operator=(WriteTask &&other)=default
Move assign from 'other'.
~WriteTask()=default
Destroy the writer Task object.
DB Builder
Definition: write_task.hh:53
DW Writer
Definition: write_task.hh:52
AttributeWriterGroup write_attribute_basegroup
Callabel to write attributes to base group, invoked after task build.
Definition: write_task.hh:91