• 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 "data_share_predicates_utils.h"
17 
18 namespace OHOS {
19 namespace DataShare {
20 
parseValueType(const CValueType & value)21 SingleValue::Type parseValueType(const CValueType &value)
22 {
23     SingleValue::Type ret;
24     switch (static_cast<int32_t>(value.tag)) {
25         case DataShareValueObjectType::TYPE_INT: {
26             ret = value.integer;
27             break;
28         }
29         case DataShareValueObjectType::TYPE_DOUBLE: {
30             ret = value.dou;
31             break;
32         }
33         case DataShareValueObjectType::TYPE_STRING: {
34             ret = std::string(value.string);
35             break;
36         }
37         case DataShareValueObjectType::TYPE_BOOL: {
38             ret = value.boolean;
39             break;
40         }
41         default:
42             ret = 0;
43             break;
44     }
45     return ret;
46 }
47 
parseValueTypeArray(const CValueType * array,int64_t size)48 MutliValue::Type parseValueTypeArray(const CValueType *array, int64_t size)
49 {
50     MutliValue::Type ret;
51     CValueType value = array[0];
52     switch (static_cast<int32_t>(value.tag)) {
53         case DataShareValueObjectType::TYPE_INT: {
54             std::vector<int> arr(size);
55             for (int64_t i = 0; i < size; ++i) {
56                 arr[i] = array[i].integer;
57             }
58             ret = arr;
59             break;
60         }
61         case DataShareValueObjectType::TYPE_DOUBLE: {
62             std::vector<double> arr(size);
63             for (int64_t i = 0; i < size; ++i) {
64                 arr[i] = array[i].dou;
65             }
66             ret = arr;
67             break;
68         }
69         case DataShareValueObjectType::TYPE_STRING: {
70             std::vector<std::string> arr(size);
71             for (int64_t i = 0; i < size; ++i) {
72                 arr[i] = std::string(array[i].string);
73             }
74             ret = arr;
75             break;
76         }
77         default:
78             break;
79     }
80     return ret;
81 }
82 
83 } // namespace DataShare
84 } // namespace OHOS