• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 
16 #ifndef NWEB_HAP_VALUE_H
17 #define NWEB_HAP_VALUE_H
18 
19 #include <map>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 namespace OHOS::NWeb {
25 
26 class NWebHapValue {
27 public:
28     enum class Type : unsigned char {
29         NONE = 0,
30         BOOLEAN,
31         INTEGER,
32         DOUBLE,
33         STRING,
34         BINARY,
35         DICTIONARY,
36         LIST,
37         ERROR,
38         STRINGARRAY,
39         BOOLEANARRAY,
40         DOUBLEARRAY,
41         INT64ARRAY
42     };
43 
44     virtual ~NWebHapValue() = default;
45 
46     virtual Type GetType() = 0;
47 
48     virtual void SetType(Type type) = 0;
49 
50     virtual int GetInt() = 0;
51 
52     virtual void SetInt(int value) = 0;
53 
54     virtual bool GetBool() = 0;
55 
56     virtual void SetBool(bool value) = 0;
57 
58     virtual double GetDouble() = 0;
59 
60     virtual void SetDouble(double value) = 0;
61 
62     virtual std::string GetString() = 0;
63 
64     virtual void SetString(const std::string& value) = 0;
65 
66     virtual const char* GetBinary(int& length) = 0;
67 
68     virtual void SetBinary(int length, const char* value) = 0;
69 
70     virtual std::map<std::string, std::shared_ptr<NWebHapValue>> GetDictValue() = 0;
71 
72     virtual std::vector<std::shared_ptr<NWebHapValue>> GetListValue() = 0;
73 
74     virtual std::shared_ptr<NWebHapValue> NewChildValue() = 0;
75 
76     virtual void SaveDictChildValue(const std::string& key) = 0;
77 
78     virtual void SaveListChildValue() = 0;
79 
GetInt64()80     virtual int64_t GetInt64()
81     {
82         return 0;
83     }
84 
SetInt64(int64_t value)85     virtual void SetInt64(int64_t value) {}
86 
GetBinary()87     virtual std::vector<uint8_t> GetBinary()
88     {
89         return std::vector<uint8_t>();
90     }
91 
SetBinary(const std::vector<uint8_t> & value)92     virtual void SetBinary(const std::vector<uint8_t>& value) {}
93 
GetBoolArray()94     virtual std::vector<bool> GetBoolArray()
95     {
96         return std::vector<bool>();
97     }
98 
SetBoolArray(const std::vector<bool> & value)99     virtual void SetBoolArray(const std::vector<bool>& value) {}
100 
GetInt64Array()101     virtual std::vector<int64_t> GetInt64Array()
102     {
103         return std::vector<int64_t>();
104     }
105 
SetInt64Array(const std::vector<int64_t> & value)106     virtual void SetInt64Array(const std::vector<int64_t>& value) {}
107 
GetDoubleArray()108     virtual std::vector<double> GetDoubleArray()
109     {
110         return std::vector<double>();
111     }
112 
SetDoubleArray(const std::vector<double> & value)113     virtual void SetDoubleArray(const std::vector<double>& value) {}
114 
GetStringArray()115     virtual std::vector<std::string> GetStringArray()
116     {
117         return std::vector<std::string>();
118     }
119 
SetStringArray(const std::vector<std::string> & value)120     virtual void SetStringArray(const std::vector<std::string>& value) {}
121 
GetErrMsg()122     virtual std::string GetErrMsg()
123     {
124         return std::string();
125     }
126 
SetErrMsg(const std::string & msg)127     virtual void SetErrMsg(const std::string& msg) {}
128 
GetErrName()129     virtual std::string GetErrName()
130     {
131         return std::string();
132     }
133 
SetErrName(const std::string & name)134     virtual void SetErrName(const std::string& name) {}
135 };
136 
137 } // namespace OHOS::NWeb
138 
139 #endif // NWEB_HAP_VALUE_H