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 #ifndef FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CAPABILITY_PERFERENCE_STORAGE_IMPL_H 16 #define FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CAPABILITY_PERFERENCE_STORAGE_IMPL_H 17 18 #include "base/thread/task_executor.h" 19 #include "preferences.h" 20 #include "preferences_helper.h" 21 #include "base/utils/string_utils.h" 22 #include "core/common/storage/storage_interface.h" 23 #include "core/common/container.h" 24 25 namespace OHOS::Ace { 26 class StorageImpl : public Storage { 27 DECLARE_ACE_TYPE(StorageImpl, Storage); 28 29 public: 30 explicit StorageImpl(int areaMode = -1); 31 ~StorageImpl() override = default; 32 33 void SetString(const std::string& key, const std::string& value) override; 34 std::string GetString(const std::string& key) override; SetDouble(const std::string & key,const double value)35 void SetDouble(const std::string& key, const double value) override 36 {} GetDouble(const std::string & key,double & value)37 bool GetDouble(const std::string& key, double& value) override 38 { 39 return false; 40 } SetBoolean(const std::string & key,const bool value)41 void SetBoolean(const std::string& key, const bool value) override 42 {} GetBoolean(const std::string & key,bool & value)43 bool GetBoolean(const std::string& key, bool& value) override 44 { 45 return false; 46 } 47 void Clear() override; 48 void Delete(const std::string& key) override; 49 50 private: 51 std::shared_ptr<NativePreferences::Preferences> GetPreference(const std::string& fileName); 52 int errCode_ = 0; 53 std::string fileName_; 54 std::unordered_map<std::string, std::shared_ptr<NativePreferences::Preferences>> preferences_; 55 }; 56 57 class StorageProxyImpl : public StorageInterface { 58 RefPtr<Storage> GetStorage(int areaMode = -1) const override; 59 }; 60 } // namespace OHOS::Ace 61 #endif // FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CAPABILITY_PERFERENCE_STORAGE_IMPL_H