1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef OHOS_ABILITY_BASE_WANT_PARAMS_WRAPPER_H
16 #define OHOS_ABILITY_BASE_WANT_PARAMS_WRAPPER_H
17 #include "base_def.h"
18 #include "base_obj.h"
19 #include "want_params.h"
20 namespace OHOS {
21 namespace AAFwk {
22 class WantParams;
23 INTERFACE(IWantParams, a75b9db6 - 9813 - 4371 - 8848 - d2966ce6ec68)
24 {
Query(IInterface * object)25     inline static IWantParams *Query(IInterface * object)
26     {
27         if (object == nullptr) {
28             return nullptr;
29         }
30         return static_cast<IWantParams *>(object->Query(g_IID_IWantParams));
31     }
32 
33     virtual ErrCode GetValue(WantParams & value) = 0;
34 };
35 class WantParamWrapper final : public Object, public IWantParams {
36 public:
WantParamWrapper(const WantParams & value)37     inline WantParamWrapper(const WantParams &value) : wantParams_(value)
38     {}
39     /**
40      * @brief Constructor for move semantics
41      */
WantParamWrapper(WantParams && value)42     inline WantParamWrapper(WantParams &&value) : wantParams_(std::move(value))
43     {}
44 
~WantParamWrapper()45     inline ~WantParamWrapper()
46     {}
47 
48     IINTERFACE_DECL();
49 
50     ErrCode GetValue(WantParams &value) override;
51 
52     bool Equals(IObject &other) override;
53 
54     std::string ToString() override;
55 
56     static sptr<IWantParams> Box(const WantParams &value);
57     /**
58      * @brief Wrap a wantParam into a WantParamWrapper using move semantics and return the wrapper.
59      *
60      * @param value
61      * @return sptr<IWantParams>
62      */
63     static sptr<IWantParams> Box(WantParams &&value);
64 
65     static WantParams Unbox(IWantParams *object);
66 
67     static bool ValidateStr(const std::string &str);
68 
69     static sptr<IWantParams> Parse(const std::string &str);
70 
71     static WantParams ParseWantParams(const std::string &str);
72 
73     static WantParams ParseWantParamsWithBrackets(const std::string &str);
74 
75     static constexpr char SIGNATURE = 'W';
76 
77 private:
78     WantParams wantParams_;
79 };
80 }  // namespace AAFwk
81 }  // namespace OHOS
82 #endif  // OHOS_ABILITY_BASE_WANT_PARAMS_WRAPPER_H