1 /*
2  * Copyright (c) 2023 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 FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_SERIALIZEABLE_OBJECT_H
17 #define FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_SERIALIZEABLE_OBJECT_H
18 
19 #include <list>
20 #include <memory>
21 #include <string>
22 
23 #include "macros.h"
24 
25 namespace OHOS::Ace {
26 class ACE_FORCE_EXPORT SerializeableObject {
27 public:
28     SerializeableObject() = default;
29     virtual ~SerializeableObject() = default;
30 
31     virtual bool Contains(const std::string& key) const = 0;
32 
33     virtual bool GetBool(const std::string& key, bool defaultValue = false) const = 0;
34     virtual int32_t GetInt(const std::string& key, int32_t defaultVal = 0) const = 0;
35     virtual uint32_t GetUInt(const std::string& key, uint32_t defaultVal = 0) const = 0;
36     virtual int64_t GetInt64(const std::string& key, int64_t defaultVal = 0) const = 0;
37     virtual double GetDouble(const std::string& key, double defaultVal = 0.0) const = 0;
38     virtual std::string GetString(const std::string& key, const std::string& defaultVal = "") const = 0;
39 
40     virtual bool Put(const char* key, const char* value) = 0;
41     virtual bool Put(const char* key, size_t value) = 0;
42     virtual bool Put(const char* key, int32_t value) = 0;
43     virtual bool Put(const char* key, int64_t value) = 0;
44     virtual bool Put(const char* key, double value) = 0;
45     virtual bool Put(const char* key, bool value) = 0;
46 
47     virtual std::string ToString() = 0;
48 
FromString(const std::string & str)49     virtual void FromString(const std::string& str) {}
50 
51     static std::unique_ptr<SerializeableObject> CreateNodeObject();
52 };
53 
54 using SerializeableObjectArray = std::list<std::unique_ptr<SerializeableObject>>;
55 } // namespace OHOS::Ace
56 
57 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_SERIALIZEABLE_OBJECT_H
58