Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
result.hpp
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Contact: Jan Olszak <j.olszak@samsung.com>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
17 */
18 
25 #ifndef CARGO_IPC_RESULT_HPP
26 #define CARGO_IPC_RESULT_HPP
27 
28 #include <functional>
29 #include <exception>
30 #include <memory>
31 
32 namespace cargo {
33 namespace ipc {
34 
35 template<typename Data>
36 class Result {
37 public:
39  : mData(nullptr),
40  mExceptionPtr(nullptr)
41  {}
42 
43  Result(std::shared_ptr<Data>&& data, std::exception_ptr&& exceptionPtr)
44  : mData(std::move(data)),
45  mExceptionPtr(std::move(exceptionPtr))
46  {}
47 
48  void rethrow() const
49  {
50  if (mExceptionPtr) {
51  std::rethrow_exception(mExceptionPtr);
52  }
53  }
54 
55  std::shared_ptr<Data> get() const
56  {
57  rethrow();
58  return mData;
59  }
60 
61  bool isValid() const
62  {
63  return (bool)mExceptionPtr || (bool)mData;
64  }
65 
66 private:
67  std::shared_ptr<Data> mData;
68  std::exception_ptr mExceptionPtr;
69 };
70 
71 template<typename Data>
72 struct ResultHandler {
73  typedef std::function < void(Result<Data>&&) > type;
74 };
75 
76 } // namespace ipc
77 } // namespace cargo
78 
79 #endif // CARGO_IPC_RESULT_HPP
std::exception_ptr mExceptionPtr
Definition: result.hpp:68
std::function< void(Result< Data > &&) > type
Definition: result.hpp:73
Result(std::shared_ptr< Data > &&data, std::exception_ptr &&exceptionPtr)
Definition: result.hpp:43
Definition: result.hpp:36
char data[368]
Definition: initctl.cpp:41
Result()
Definition: result.hpp:38
Definition: result.hpp:72
bool isValid() const
Definition: result.hpp:61
std::shared_ptr< Data > mData
Definition: result.hpp:67
void rethrow() const
Definition: result.hpp:48