File indexing completed on 2024-09-22 04:57:52

0001 /*
0002     SPDX-FileCopyrightText: 2018 Ivan Čukić <ivan.cukic(at)kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef VOY_BASIC_SINK_H
0008 #define VOY_BASIC_SINK_H
0009 
0010 // STL
0011 #include <functional>
0012 
0013 // Self
0014 #include "../utils.h"
0015 #include "../dsl/node_tags.h"
0016 
0017 namespace voy {
0018 
0019 using voy::utils::non_copyable;
0020 using voy::dsl::sink_node_tag;
0021 
0022 template <typename F>
0023 class sink: non_copyable {
0024 public:
0025     using node_category = sink_node_tag;
0026 
0027     explicit sink(F function)
0028         : m_function{std::move(function)}
0029     {
0030     }
0031 
0032     template <typename T>
0033     void operator() (T&& value) const
0034     {
0035         voy_fwd_invoke(m_function, value);
0036     }
0037 
0038     void init()
0039     {
0040     }
0041 
0042     void notify_ended() const
0043     {
0044     }
0045 
0046 private:
0047     F m_function;
0048 };
0049 
0050 template <>
0051 class sink<void>: non_copyable {
0052 public:
0053     using node_category = sink_node_tag;
0054 
0055     explicit sink()
0056     {
0057     }
0058 
0059     template <typename T>
0060     void operator() (T&& value) const
0061     {
0062     }
0063 
0064     void init()
0065     {
0066     }
0067 
0068     void notify_ended() const
0069     {
0070     }
0071 };
0072 
0073 
0074 } // namespace voy
0075 
0076 #endif // include guard
0077