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 OHOS_RESTOOL_RESOURCE_COMPILER_H 17 #define OHOS_RESTOOL_RESOURCE_COMPILER_H 18 19 #include <vector> 20 #include "resource_data.h" 21 #include "resource_item.h" 22 23 namespace OHOS { 24 namespace Global { 25 namespace Restool { 26 class IResourceCompiler { 27 public: 28 IResourceCompiler(ResType type, const std::string &output, bool isOverlap = false); 29 virtual ~IResourceCompiler(); 30 uint32_t Compile(const std::vector<DirectoryInfo> &directoryInfos); 31 const std::map<int64_t, std::vector<ResourceItem>> &GetResult() const; 32 uint32_t Compile(const FileInfo &fileInfo); 33 void SetModuleName(const std::string &moduleName); 34 uint32_t CompileForAppend(const FileInfo &fileInfo); 35 const std::map<std::pair<ResType, std::string>, std::vector<ResourceItem>> &GetResourceItems() const; 36 37 protected: 38 virtual uint32_t CompileSingleFile(const FileInfo &fileInfo); 39 virtual uint32_t CompileFiles(const std::vector<FileInfo> &fileInfos); 40 bool MergeResourceItem(const ResourceItem &resourceItem); 41 std::string GetOutputFolder(const DirectoryInfo &directoryInfo) const; 42 ResType type_; 43 std::string output_; 44 std::string moduleName_; 45 bool isOverlap_; 46 47 // id, resource items 48 std::map<int64_t, std::vector<ResourceItem>> resourceInfos_; 49 // ResType, name, resourceItems 50 std::map<std::pair<ResType, std::string>, std::vector<ResourceItem>> nameInfos_; 51 52 private: 53 uint32_t PostCommit(); 54 }; 55 } 56 } 57 } 58 #endif