1 /* 2 * Copyright (c) 2021 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_RESOURCE_ACE_RES_KEY_PARSER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_RESOURCE_ACE_RES_KEY_PARSER_H 18 19 #include <functional> 20 #include <string> 21 #include <vector> 22 23 #include "base/resource/ace_res_data_struct.h" 24 #include "base/utils/singleton.h" 25 26 namespace OHOS::Ace { 27 using parse_key_function = std::function<bool(const std::string& , std::vector<KeyParam>&)>; 28 29 class AceResKeyParser final : public Singleton<AceResKeyParser> { 30 DECLARE_SINGLETON(AceResKeyParser); 31 ACE_DISALLOW_MOVE(AceResKeyParser); 32 33 public: 34 bool Parse(const std::string& deviceResConfigTag, std::vector<KeyParam>& keyParams, bool styleRes); 35 bool DeclarativeParse(const std::string& deviceResConfigTag, std::vector<KeyParam>& keyParams); 36 std::string GetMccByValue(uint32_t value) const; 37 std::string GetMncByValue(uint32_t value) const; 38 std::string GetMncShortLenByValue(uint32_t value) const; 39 std::string GetOrientationByType(DeviceOrientation type) const; 40 std::string GetColorModeByType(ColorMode type) const; 41 std::string GetDeviceByType(DeviceType type) const; 42 std::string GetResolutionByType(ResolutionType type) const; 43 std::string GetScreenShapeByType(ScreenShape type) const; 44 std::string GetScreenLongByType(LongScreenType type) const; 45 std::string GetDeclarativeColorModeByType(ColorMode type) const; 46 47 private: 48 bool ParseMatch(const std::vector<std::string>& keys, std::vector<KeyParam>& keyParams, 49 parse_key_function functions[], int32_t funcLen, bool styleRes) const; 50 static bool ParseMcc(const std::string& key, std::vector<KeyParam>& keyParams); 51 static bool ParseMnc(const std::string& key, std::vector<KeyParam>& keyParams); 52 static bool ParseOrientation(const std::string& key, std::vector<KeyParam>& keyParams); 53 static bool ParseColorMode(const std::string& key, std::vector<KeyParam>& keyParams); 54 static bool ParseDeviceType(const std::string& key, std::vector<KeyParam>& keyParams); 55 static bool ParseResolution(const std::string& key, std::vector<KeyParam>& keyParams); 56 static bool ParseDefaults(const std::string& key, std::vector<KeyParam>& keyParams); 57 static bool ParseScreenShape(const std::string& key, std::vector<KeyParam>& keyParams); 58 static bool ParseLongScreen(const std::string& key, std::vector<KeyParam>& keyParams); 59 static bool ParseDeclarativeColorMode(const std::string& key, std::vector<KeyParam>& keyParams); 60 }; 61 62 } // namespace OHOS::Ace 63 64 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_RESOURCE_ACE_RES_KEY_PARSER_H