WRApplication
External kratos "application" for multiscale time integration.
pipe.hpp
Go to the documentation of this file.
1 
3 #pragma once
4 
5 // --- Core Includes ---
6 #include "includes/kratos_parameters.h"
7 #include "includes/define.h" // KRATOS_TRY, KRATOS_CATCH
8 
9 // --- STL Includes ---
10 #include <type_traits> // std::true_type, std::false_type
11 #include <utility> // std::move
12 
13 
14 namespace Kratos {
15 
16 
21 
61 namespace Pipes {
62 
63 
70 template <class TInput, class TOutput>
71 struct Traits
72 {
74  using InputType = TInput;
75 
77  using OutputType = TOutput;
78 }; // struct Traits
79 
80 
89 template <class TPipe>
90 using IsPipe = std::integral_constant<bool,
91  // Has operator() with the following signature: OutputType operator()(InputType) const
92  std::is_same_v<decltype(std::declval<const TPipe>().operator()(std::declval<typename TPipe::InputType>())), typename TPipe::OutputType>
93 
94  // Has non-void InputType
95  && !std::is_same_v<typename TPipe::InputType,void>
96 
97  // Has non-void OutputType
98  && !std::is_same_v<typename TPipe::OutputType,void>
99 >;
100 
101 
103 template <class TInput, class TPipe, std::enable_if_t<IsPipe<TPipe>::value && std::is_convertible_v<TInput,typename TPipe::InputType>, bool> = true>
104 typename TPipe::OutputType operator>>(TInput&& rInput, const TPipe& rPipe);
105 
106 
107 namespace Detail{
108 
109 // Forward declare Factory because it needs to be a friend of CompoundPipe.
110 template <class>
111 class Factory;
112 
113 } // namespace Detail
114 
115 
123 template <class TInputPipe, class TOutputPipe>
124 class CompoundPipe : public Traits<typename TInputPipe::InputType, typename TOutputPipe::OutputType>
125 {
126 public:
127  using InputPipe = TInputPipe;
128 
129  using OutputPipe = TOutputPipe;
130 
133 
135  CompoundPipe(CompoundPipe&& rOther) noexcept = default;
136 
138  CompoundPipe(const CompoundPipe& rOther) = default;
139 
154  template <class TInPipe = TInputPipe, class TOutPipe = TOutputPipe>
155  CompoundPipe(const Parameters& rParameters,
156  std::enable_if_t<std::is_constructible_v<TInPipe,Parameters>
157  && std::is_constructible_v<TOutPipe,Parameters>>* = 0);
158 
160  CompoundPipe(TInputPipe&& rInputPipe, TOutputPipe&& rOutputPipe) noexcept;
161 
163  CompoundPipe(const TInputPipe& rInputPipe, const TOutputPipe& rOutputPipe);
164 
167 
169  static Parameters GetDefaultParameters() noexcept;
170 
171 private:
172  template <class>
173  friend class Detail::Factory;
174 
175  TInputPipe mInputPipe;
176 
177  TOutputPipe mOutputPipe;
178 }; // class CompoundPipe
179 
180 
182 template <class TInputPipe,
183  class TOutputPipe,
184  std::enable_if_t<
185  IsPipe<TInputPipe>::value && IsPipe<TOutputPipe>::value,
186  bool> = true
187  >
188 CompoundPipe<TInputPipe,TOutputPipe> operator|(TInputPipe&& rInputPipe, TOutputPipe&& rOutputPipe);
189 
190 
192 template <class TInputPipe,
193  class TOutputPipe,
194  std::enable_if_t<
195  IsPipe<TInputPipe>::value && IsPipe<TOutputPipe>::value,
196  bool> = true
197  >
198 CompoundPipe<TInputPipe,TOutputPipe> operator|(const TInputPipe& rInputPipe, const TOutputPipe& rOutputPipe);
199 
200 
202 template <class TPipe>
203 class SingleSegmentPipeline : public Traits<typename TPipe::InputType,typename TPipe::OutputType>
204 {
205 public:
207 
208  SingleSegmentPipeline(SingleSegmentPipeline&& rOther) noexcept = default;
209 
211 
212  SingleSegmentPipeline(const Parameters& rParameters);
213 
214  typename TPipe::OutputType operator()(typename TPipe::InputType input) const;
215 
216  static Parameters GetDefaultParameters();
217 
218 private:
219  TPipe mPipe;
220 }; // class SingleSegmentPipeline
221 
222 
224 template <class ...TPipes>
225 using Pipeline = decltype((... | std::declval<TPipes>()));
226 
227 
230 
231 
232 } // namespace Pipes
233 } // namespace Kratos
234 
235 // Include definitions
236 #include "wrapp/pipes/impl/pipe_impl.hpp"
A composable pipe that takes the output of one pipe and feeds its result into another.
Definition: pipe.hpp:125
CompoundPipe(const TInputPipe &rInputPipe, const TOutputPipe &rOutputPipe)
Copy construct the input- and output pipes.
static Parameters GetDefaultParameters() noexcept
Return an array of subparameters, containing the defaults for each pipe segment in order.
TInputPipe InputPipe
Definition: pipe.hpp:127
CompoundPipe::OutputType operator()(typename CompoundPipe::InputType Input) const
Feed the result of the input pipe into the output pipe.
CompoundPipe()
Default construct the input- and output pipes.
CompoundPipe(const Parameters &rParameters, std::enable_if_t< std::is_constructible_v< TInPipe, Parameters > &&std::is_constructible_v< TOutPipe, Parameters >> *=0)
Construct from a Parameters object.
CompoundPipe(TInputPipe &&rInputPipe, TOutputPipe &&rOutputPipe) noexcept
Move construct the input- and output pipes.
CompoundPipe(const CompoundPipe &rOther)=default
Copy construct the input- and output pipes.
CompoundPipe(CompoundPipe &&rOther) noexcept=default
Move construct the input- and output pipes.
TOutputPipe OutputPipe
Definition: pipe.hpp:129
An adaptor class for pipelines consisting of a single segment.
Definition: pipe.hpp:204
SingleSegmentPipeline(SingleSegmentPipeline &&rOther) noexcept=default
SingleSegmentPipeline(const Parameters &rParameters)
static Parameters GetDefaultParameters()
SingleSegmentPipeline(const SingleSegmentPipeline &rOther)=default
TPipe::OutputType operator()(typename TPipe::InputType input) const
TPipe::OutputType operator>>(TInput &&rInput, const TPipe &rPipe)
Operator for calling operator() of the pipe.
decltype((...|std::declval< TPipes >())) Pipeline
Convenience type alias for complex pipes.
Definition: pipe.hpp:225
std::integral_constant< bool, std::is_same_v< decltype(std::declval< const TPipe >().operator()(std::declval< typename TPipe::InputType >())), typename TPipe::OutputType > &&!std::is_same_v< typename TPipe::InputType, void > &&!std::is_same_v< typename TPipe::OutputType, void > > IsPipe
Bool constant checking whether TPipe satisfies the requirements of a pipe.
Definition: pipe.hpp:99
Definition: AddIOToPython.hpp:12
"CheckpointProcess" Factory(KratosMultiphysics.Parameters parameters, KratosMultiphysics.Model model)
Definition: CheckpointProcess.py:228
Definition: CheckpointID.hpp:68
Metaclass containing type information every pipe must inherit from.
Definition: pipe.hpp:72
TInput InputType
cv-qualified argument type of operator()
Definition: pipe.hpp:74
TOutput OutputType
qualified return type of operator()
Definition: pipe.hpp:77