diff --git a/src/voy/basic/values.h b/src/voy/basic/values.h new file mode 100644 index 0000000..7839e8a --- /dev/null +++ b/src/voy/basic/values.h @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2018 Ivan Čukić + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + * If not, see . + */ + +#ifndef VOY_BASIC_VALUES_H +#define VOY_BASIC_VALUES_H + +// STL +#include +#include +#include + +// Self +#include "../utils.h" +#include "../traits.h" +#include "../dsl/node_tags.h" + +namespace voy { + +using voy::utils::non_copyable; +using voy::dsl::source_node_tag; +using voy::dsl::continuator_base; + +// `values` creates a reactive stream that emits the predefined +// values as soon as the pipeline is initialized + +template +class values: non_copyable { + voy_assert_value_type(T); + +public: + using node_category = source_node_tag; + + explicit values(std::initializer_list values) + : m_values{values} + { + } + + template + explicit values(C&& values) + : m_values{voy_fwd(values)} + { + } + + template + class node: public continuator_base, non_copyable { + node(std::vector&& values, Cont&& cont) + : m_values{std::move(values)} + , m_continuation{std::move(cont)} + { + } + + void init() + { + } + + private: + std::vector m_values; + Cont m_continuation; + }; + + + +private: + std::vector m_values; + +}; + + + +} // namespace voy + +#endif // include guard + diff --git a/src/voy/dsl/node_tags.h b/src/voy/dsl/node_tags.h new file mode 100644 index 0000000..cec2fa7 --- /dev/null +++ b/src/voy/dsl/node_tags.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2018 Ivan Čukić + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + * If not, see . + */ + +#ifndef VOY_DSL_NODE_TAGS_H +#define VOY_DSL_NODE_TAGS_H + +namespace voy::dsl { + +// The nodes in the graph are connected only when both the source +// and a sink exist on a path. The node tags are used to detect whether +// something is a source or a sink. + +struct source_node_tag {}; // node that only emits messages + +struct sink_node_tag {}; // node that only receives messages + +struct transformation_node_tag {}; // middle node that defines transformations + // this one does not force establishing + // connectiond + +template +class continuator_base { + voy_assert_value_type(Cont); + +public: + continuator_base(Cont&& continuation) + : m_continuation{std::move(continuation)} + { + } + + void init() + { + m_continuation.init(); + } + + void notify_ended() const + { + m_continuation.notify_ended(); + } + +protected: + Cont m_continuation; +}; + +} // namespace voy::dsl + +#endif // include guard + diff --git a/src/voy/main.cpp b/src/voy/main.cpp new file mode 100644 index 0000000..93738ed --- /dev/null +++ b/src/voy/main.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2018 Ivan Čukić + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + * If not, see . + */ + +#include "basic/values.h" + +int main(int argc, char *argv[]) +{ + + + return 0; +} + diff --git a/src/voy/traits.h b/src/voy/traits.h index ddb4821..491e98e 100644 --- a/src/voy/traits.h +++ b/src/voy/traits.h @@ -1,125 +1,130 @@ /* * Copyright (C) 2018 Ivan Čukić * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. * If not, see . */ #ifndef VOY_TRAITS_H #define VOY_TRAITS_H // STL #include // Some meta-programming utility functions and meta-functions, // including the detection idiom - the poor man's concepts #define voy_concept inline constexpr bool + #define voy_require(Condition) typename std::enable_if_t = 0 +#define voy_assert_value_type(Type) \ + static_assert(std::is_same_v>, \ + "This needs to be a value type") + namespace voy::traits { // Meta-function to force the compiler to print out the exact type passed // to it by creating a compilation error because the type is not implemented template struct print_types; // Meta-function that always returns false. It is useful for marking a // particular if-constexpr branch to be erroneous template voy_concept always_fail = false; #define voy_fail(Type, Msh) static_assert(voy::traits::always_fail, Msg> // C++20 Stuff // Meta-function which strips out the reference and cv qualifiers from the type template using remove_cvref_t = std::remove_reference_t>; // The detection idiom -- static introspection made easy struct nonesuch { nonesuch() = delete; ~nonesuch() = delete; nonesuch(const nonesuch&) = delete; nonesuch& operator=(const nonesuch&) = delete; }; namespace detail { template < typename Default , typename Void , template typename Operation , typename... Args > struct detector { using value_t = std::false_type; using type = Default; }; template < typename Default , template typename Operation , typename... Args > struct detector < Default , std::void_t> , Operation , Args... > { using value_t = std::true_type; using type = Operation; }; } // namespace detail template < template typename Operation , typename... Args > using is_detected = typename detail::detector < nonesuch , void , Operation , Args... >::value_t; template < template typename Operation , typename... Args > voy_concept is_detected_v = is_detected::value; template < template typename Operation , typename... Args > using is_detected_t = typename is_detected::type; template < template typename Operation , typename... Args > using detected_t = typename detail::detector < nonesuch , void , Operation , Args...>::type; } // namespace voy::traits #endif // include guard