• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 
16 #include "ohos_nweb/ctocpp/ark_web_rom_value_vector_ctocpp.h"
17 
18 #include "ohos_nweb/bridge/ark_web_rom_value_wrapper.h"
19 #include "ohos_nweb/ctocpp/ark_web_rom_value_ctocpp.h"
20 
21 namespace OHOS::ArkWeb {
22 
ArkWebRomValueMapStructToClass(const ArkWebRomValueMap & struct_value)23 std::map<std::string, std::shared_ptr<OHOS::NWeb::NWebRomValue>> ArkWebRomValueMapStructToClass(
24     const ArkWebRomValueMap& struct_value)
25 {
26     std::map<std::string, std::shared_ptr<OHOS::NWeb::NWebRomValue>> class_value;
27     if (struct_value.size > 0) {
28         for (int count = 0; count < struct_value.size; count++) {
29             std::string key = ArkWebStringStructToClass(struct_value.key[count]);
30             std::shared_ptr<OHOS::NWeb::NWebRomValue> nweb_rom_value =
31                 std::make_shared<ArkWebRomValueWrapper>(ArkWebRomValueCToCpp::Invert(struct_value.value[count]));
32             class_value[key] = nweb_rom_value;
33         }
34     }
35 
36     return class_value;
37 }
38 
ArkWebRomValueMapStructRelease(ArkWebRomValueMap & struct_value)39 ARK_WEB_NO_SANITIZE void ArkWebRomValueMapStructRelease(ArkWebRomValueMap& struct_value)
40 {
41     struct_value.size = 0;
42     SAFE_FREE(struct_value.key, struct_value.ark_web_mem_free_func);
43     SAFE_FREE(struct_value.value, struct_value.ark_web_mem_free_func);
44 }
45 
ArkWebRomValueVectorStructToClass(const ArkWebRomValueVector & struct_value)46 std::vector<std::shared_ptr<OHOS::NWeb::NWebRomValue>> ArkWebRomValueVectorStructToClass(
47     const ArkWebRomValueVector& struct_value)
48 {
49     std::vector<std::shared_ptr<OHOS::NWeb::NWebRomValue>> class_value;
50     if (struct_value.size > 0) {
51         for (int count = 0; count < struct_value.size; count++) {
52             std::shared_ptr<OHOS::NWeb::NWebRomValue> nweb_rom_value =
53                 std::make_shared<ArkWebRomValueWrapper>(ArkWebRomValueCToCpp::Invert(struct_value.value[count]));
54             class_value.push_back(nweb_rom_value);
55         }
56     }
57 
58     return class_value;
59 }
60 
ArkWebRomValueVectorStructRelease(ArkWebRomValueVector & struct_value)61 ARK_WEB_NO_SANITIZE void ArkWebRomValueVectorStructRelease(ArkWebRomValueVector& struct_value)
62 {
63     struct_value.size = 0;
64     SAFE_FREE(struct_value.value, struct_value.ark_web_mem_free_func);
65 }
66 
67 } // namespace OHOS::ArkWeb
68