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
23namespace OHOS {
24namespace Global {
25namespace Restool {
26class IResourceCompiler {
27public:
28    IResourceCompiler(ResType type, const std::string &output);
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
37protected:
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
46    // id, resource items
47    std::map<int64_t, std::vector<ResourceItem>> resourceInfos_;
48    // ResType, name, resourceItems
49    std::map<std::pair<ResType, std::string>, std::vector<ResourceItem>> nameInfos_;
50
51private:
52    uint32_t PostCommit();
53};
54}
55}
56}
57#endif