1 /* 2 * Copyright (c) 2024 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 OHOS_RESTOOL_ID_DEFINED_PARSER_H 17 #define OHOS_RESTOOL_ID_DEFINED_PARSER_H 18 19 #include <string> 20 #include <cJSON.h> 21 #include "cmd_parser.h" 22 23 namespace OHOS { 24 namespace Global { 25 namespace Restool { 26 class IdDefinedParser { 27 public: 28 IdDefinedParser(const PackageParser &packageParser, const ResourceIdCluster &type); 29 virtual ~IdDefinedParser(); GetSysDefinedIds()30 std::map<std::pair<ResType, std::string>, ResourceId> &GetSysDefinedIds() 31 { 32 return sysDefinedIds_; 33 } GetAppDefinedIds()34 std::map<std::pair<ResType, std::string>, ResourceId> &GetAppDefinedIds() 35 { 36 return appDefinedIds_; 37 } 38 uint32_t Init(); 39 private: 40 uint32_t Init(const std::string &filePath, bool isSystem); 41 using ParseFunction = std::function<bool(const cJSON *, ResourceId&)>; 42 void InitParser(); 43 uint32_t IdDefinedToResourceIds(const std::string &filePath, const cJSON *record, 44 bool isSystem, const int64_t strtSysId = 0); 45 bool ParseType(const cJSON *type, ResourceId &resourceId); 46 bool ParseName(const cJSON *name, ResourceId &resourceId); 47 bool ParseOrder(const cJSON *order, ResourceId &resourceId); 48 bool ParseId(const cJSON *id, ResourceId &resourceId); 49 bool PushResourceId(const std::string &filePath, const ResourceId &resourceId, bool isSystem); 50 int64_t GetStartId() const; 51 std::map<std::string, std::vector<std::pair<ResType, std::string>>> checkDefinedIds_; 52 std::map<std::pair<ResType, std::string>, ResourceId> sysDefinedIds_; 53 std::map<std::pair<ResType, std::string>, ResourceId> appDefinedIds_; 54 std::map<int64_t, ResourceId> idDefineds_; 55 std::map<std::string, ParseFunction> handles_; 56 const PackageParser packageParser_; 57 static const int64_t START_SYS_ID; 58 ResourceIdCluster type_; 59 cJSON *root_; 60 }; 61 } 62 } 63 } 64 #endif