in.hpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2014, 2015 Ableton AG, Berlin. All rights reserved.
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21 //
22 
27 #pragma once
28 
33 
34 namespace atria {
35 namespace funken {
36 
37 namespace detail {
38 
39 template <typename SignalT>
40 class input_impl
41  : private watchable<meta::value_t<SignalT> >
42 {
43  template <typename T> friend class input_impl;
44  friend class detail::access;
45 
46  using base_t = watchable<meta::value_t<SignalT> >;
47  using signal_ptr_t = std::shared_ptr<SignalT>;
48 
49  signal_ptr_t signal_;
50  const signal_ptr_t& signal() const { return signal_; }
51 
52 public:
53  using value_type = meta::value_t<SignalT>;
54 
55  input_impl() = default;
56  input_impl(input_impl&&) = default;
57  input_impl& operator=(input_impl&&) = default;
58  input_impl(const input_impl&) = delete;
59  input_impl& operator=(const input_impl&) = delete;
60 
61  template <typename T>
62  input_impl& operator=(input_impl<T>&& x)
63  {
64  base_t::operator=(std::move(x));
65  signal_ = std::move(x.signal_);
66  return *this;
67  }
68 
69  template <typename T>
70  input_impl(input_impl<T>&& x)
71  : base_t(std::move(x))
72  , signal_(std::move(x.signal_))
73  {}
74 
75  input_impl(signal_ptr_t sig)
76  : signal_(std::move(sig)) {}
77 
78  auto get() const
79  -> ABL_DECLTYPE_RETURN(signal_->last())
80 };
81 
82 } // namespace detail
83 
89 template <typename T>
90 class input : public detail::input_impl<detail::down_signal<T> >
91 {
92  using base_t = detail::input_impl<detail::down_signal<T> >;
93 public:
94  using base_t::base_t;
95  using base_t::operator=;
96 };
97 
102 template <typename InT>
103 auto in(InT&& object)
105  (In_value<InT>()),
106  detail::input_impl<detail::signal_type_t<InT> > >
107 {
108  return detail::access::signal(std::forward<InT>(object));
109 }
110 
111 } // namespace funken
112 } // namespace atria
#define ABL_DECLTYPE_RETURN(body_expr)
Utility for defining generic functions with a deduced return type, that are composed of a single expr...
Definition: utils.hpp:109
typename std::enable_if< X, T >::type enable_if_t
Similar to C++14 std::enable_if_t.
Definition: type_traits.hpp:84
STL namespace.
auto in(InT &&object) -> estd::enable_if_t< (In_value< InT >()), detail::input_impl< detail::signal_type_t< InT > > >
Creates an in from another in value.
Definition: in.hpp:103
This module implements the signal flow in funken.
C++ amazing templates and reusable implementations awesomeness.
Definition: _doc.hpp:35
Provides access to reading values of type T.
Definition: in.hpp:90
Fork me on GitHub