out.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 
23 // Copyright: 2014, 2015, Ableton AG, Berlin. All rights reserved.
28 #pragma once
29 
34 
35 namespace atria {
36 namespace funken {
37 
38 namespace detail {
39 
40 template <typename SignalT>
41 class output_impl
42 {
43  template <typename T> friend class output_impl;
44  friend class detail::access;
45 
46  using signal_ptr_t = std::shared_ptr<SignalT>;
47  signal_ptr_t signal_;
48  const signal_ptr_t& signal() const { return signal_; }
49 
50 public:
51  using value_type = meta::value_t<SignalT>;
52 
53  output_impl() = default;
54  output_impl(output_impl&&) = default;
55  output_impl& operator=(output_impl&&) = default;
56  output_impl(const output_impl&) = delete;
57  output_impl& operator=(const output_impl&) = delete;
58 
59  template <typename T>
60  output_impl& operator=(output_impl<T>&& x)
61  {
62  signal_ = std::move(x.signal_);
63  return *this;
64  }
65 
66  template <typename T>
67  output_impl(output_impl<T>&& x)
68  : signal_(std::move(x.signal_))
69  {}
70 
71  output_impl(signal_ptr_t sig)
72  : signal_(std::move(sig)) {}
73 
74  template <typename T>
75  void set(T&& value)
76  {
77  return signal_->send_up(std::forward<T>(value));
78  }
79 };
80 
81 } // namespace detail
82 
88 template <typename T>
89 class output : public detail::output_impl<detail::up_down_signal<T> >
90 {
91  using base_t = detail::output_impl<detail::up_down_signal<T> >;
92 public:
93  using base_t::base_t;
94  using base_t::operator=;
95 };
96 
101 template <typename OutT>
102 auto out(OutT&& object)
104  (Out_value<OutT>()),
105  detail::output_impl<detail::signal_type_t<OutT> > >
106 {
107  return detail::access::signal(std::forward<OutT>(object));
108 }
109 
110 } // namespace funken
111 } // namespace atria
auto out(OutT &&object) -> estd::enable_if_t< (Out_value< OutT >()), detail::output_impl< detail::signal_type_t< OutT > > >
Creates an out from another out value.
Definition: out.hpp:102
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.
Provides access to writing values of type T.
Definition: out.hpp:89
This module implements the signal flow in funken.
C++ amazing templates and reusable implementations awesomeness.
Definition: _doc.hpp:35
Fork me on GitHub