Microsoft Information Protection SDK - C++ 1.17
API Reference Documentation for C++
Loading...
Searching...
No Matches
delegate_response.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (c) Microsoft Corporation.
4 * All rights reserved.
5 *
6 * This code is licensed under the MIT License.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files(the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions :
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 *
26 */
33#ifndef API_MIP_DELEGATE_RESPONSE
34#define API_MIP_DELEGATE_RESPONSE
35
36#include <memory>
37
38#include "mip/error.h"
39#include "mip/mip_namespace.h"
40
41MIP_NAMESPACE_BEGIN
42
46class DelegateResponseBase {
48protected:
49 DelegateResponseBase() : mReserved(0) {}
50 // For internal purpose only
51 long mReserved;
52 static long GetReserved(const DelegateResponseBase& response) {
53 return response.mReserved;
54 }
56};
57
61template <class T> class DelegateResponse : public DelegateResponseBase {
62public:
68 DelegateResponse(std::shared_ptr<T> data) : mData(data), mDelegateResponseError(nullptr) {
69 if (!mData) {
70 throw std::invalid_argument("Created an empty DelegateResponse");
71 }
72 }
73
79 DelegateResponse(mip::Error& error) : mData(nullptr), mDelegateResponseError(new DelegateResponseError(error)) {
80 if (mDelegateResponseError->GetMessage().empty()) {
81 throw std::invalid_argument("Created an empty DelegateResponse");
82 }
83 }
84
90 explicit DelegateResponse(const std::exception_ptr& exception)
91 : mData(nullptr),
92 mDelegateResponseError(exception ? new DelegateResponseError(exception) : nullptr) {
93 if (!mDelegateResponseError) {
94 throw std::invalid_argument("Created an empty DelegateResponse");
95 }
96 }
97
103 std::shared_ptr<T> GetData() const { return mData; }
104
110 std::shared_ptr<mip::DelegateResponseError> GetError() const {
111 return mDelegateResponseError;
112 }
113
115 virtual ~DelegateResponse() {}
116protected:
117 DelegateResponse() {}
120private:
121 std::shared_ptr<T> mData;
122 std::shared_ptr<mip::DelegateResponseError> mDelegateResponseError;
123};
124
125MIP_NAMESPACE_END
126
127#endif // API_MIP_DELEGATE_RESPONSE
Delegate Response Error. Thrown or returned in response to encountering an error in a delegate method...
Definition error.h:315
A file containing the MIP SDK error types.
MIP namespace macros.