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_FRAMEWORKS_BASE_JSON_NODE_OBJECT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_JSON_NODE_OBJECT_H 18 19 #include "base/json/json_util.h" 20 #include "base/json/uobject.h" 21 22 namespace OHOS::Ace { 23 class ACE_FORCE_EXPORT NodeObject : public JsonValue { 24 public: 25 NodeObject(); 26 ~NodeObject() override = default; 27 28 bool Contains(const std::string& key) const override; 29 30 bool GetBool(const std::string& key, bool defaultValue = false) const override; 31 int32_t GetInt(const std::string& key, int32_t defaultVal = 0) const override; 32 uint32_t GetUInt(const std::string& key, uint32_t defaultVal = 0) const override; 33 int64_t GetInt64(const std::string& key, int64_t defaultVal = 0) const override; 34 double GetDouble(const std::string& key, double defaultVal = 0.0) const override; 35 std::string GetString(const std::string& key, const std::string& defaultVal = "") const override; 36 std::unique_ptr<JsonValue> GetValue(const std::string& key) const override; 37 std::unique_ptr<JsonValue> GetObject(const std::string& key) const override; 38 39 bool Put(const char* key, const char* value) override; 40 bool Put(const char* key, size_t value) override; 41 bool Put(const char* key, int32_t value) override; 42 bool Put(const char* key, int64_t value) override; 43 bool Put(const char* key, double value) override; 44 bool Put(const char* key, bool value) override; 45 bool Put(const char* key, const std::unique_ptr<JsonValue>& value) override; 46 bool Put(const char* key, const std::unique_ptr<NodeObject>& value); 47 48 std::string ToString() override; 49 void FromString(const std::string& buffer) override; 50 51 size_t Hash(); 52 int32_t EstimateBufferSize(); 53 54 static std::unique_ptr<NodeObject> Create(); 55 56 private: 57 std::shared_ptr<UObject> uobject_; 58 }; 59 } // namespace OHOS::Ace 60 61 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_JSON_NODE_OBJECT_H 62