1 /**
2  * @copyright
3  * ====================================================================
4  *    Licensed to the Apache Software Foundation (ASF) under one
5  *    or more contributor license agreements.  See the NOTICE file
6  *    distributed with this work for additional information
7  *    regarding copyright ownership.  The ASF licenses this file
8  *    to you under the Apache License, Version 2.0 (the
9  *    "License"); you may not use this file except in compliance
10  *    with the License.  You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *    Unless required by applicable law or agreed to in writing,
15  *    software distributed under the License is distributed on an
16  *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  *    KIND, either express or implied.  See the License for the
18  *    specific language governing permissions and limitations
19  *    under the License.
20  * ====================================================================
21  * @endcopyright
22  */
23 
24 #ifndef SVNXX_PRIVATE_FUTURE_HPP
25 #define SVNXX_PRIVATE_FUTURE_HPP
26 
27 #include "svnxx/detail/future.hpp"
28 
29 #include "../private/init_private.hpp"
30 #include "../aprwrap.hpp"
31 
32 namespace apache {
33 namespace subversion {
34 namespace svnxx {
35 namespace detail {
36 namespace future_ {
37 
38 
39 // Encapsulates a result pool that will contain pool-allocated
40 // objects returned from asynchronous operations. Consequently,
41 // keeps a reference to the global state that holds the root pool
42 // that is the parent of this result pool.
43 class result
44 {
45 public:
result(const detail::global_state::ptr & state_)46   explicit result(const detail::global_state::ptr& state_)
47     : state(state_),
48       result_pool(state_)
49     {}
50 
get_pool()51   apr::pool& get_pool() noexcept
52     {
53       return result_pool;
54     }
55 
56 private:
57   const detail::global_state::ptr state;
58   apr::pool result_pool;
59 };
60 
61 } // namespace future_
62 } // namespace detail
63 namespace impl {
64 
65 
66 // Creates a detail::future_::result pointer for initializing
67 // detail::future objects.
68 inline detail::future_::unique_ptr
make_future_result(const detail::global_state::ptr & state)69 make_future_result(const detail::global_state::ptr& state)
70 {
71   using namespace detail::future_;
72   return unique_ptr(new result(state));
73 }
74 
75 // Creates a null detail::future_::result pointer for cases where we
76 // do not need a result pool.
77 inline detail::future_::unique_ptr
make_future_result()78 make_future_result()
79 {
80   return detail::future_::unique_ptr();
81 }
82 
83 
84 // Wrapper for detail::future with public constructor.
85 template<typename T>
86 struct future final : public detail::future_::future<T>
87 {
88   using inherited = typename detail::future_::future<T>::inherited;
futureapache::subversion::svnxx::impl::future89   future(inherited that, detail::future_::unique_ptr&& ctx) noexcept
90     : detail::future_::future<T>(std::move(that), std::move(ctx))
91     {}
92 };
93 
94 
95 // Wrapper for detail::shared_future with public constructor.
96 template<typename T>
97 struct shared_future final : public detail::future_::shared_future<T>
98 {
99   using inherited = typename detail::future_::shared_future<T>::inherited;
shared_futureapache::subversion::svnxx::impl::shared_future100   shared_future(inherited that, detail::future_::shared_ptr ctx) noexcept
101     : detail::future_::shared_future<T>(std::move(that), ctx)
102     {}
103 };
104 
105 } // namespace impl
106 } // namespace svnxx
107 } // namespace subversion
108 } // namespace apache
109 
110 #endif // SVNXX_PRIVATE_FUTURE_HPP
111