1/*
2 * Copyright (c) 2021-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_WORKER_H
17#define OHOS_RESTOOL_ID_WORKER_H
18
19#include <vector>
20#include "id_defined_parser.h"
21#include "resource_data.h"
22#include "resource_util.h"
23#include "singleton.h"
24
25namespace OHOS {
26namespace Global {
27namespace Restool {
28class IdWorker : public Singleton<IdWorker> {
29public:
30    uint32_t Init(ResourceIdCluster &type, int64_t start = 0x01000000);
31    int64_t GenerateId(ResType resType, const std::string &name);
32    std::vector<ResourceId> GetHeaderId() const;
33    int64_t GetId(ResType resType, const std::string &name) const;
34    int64_t GetSystemId(ResType resType, const std::string &name) const;
35
36private:
37    int64_t GenerateAppId(ResType resType, const std::string &name);
38    int64_t GenerateSysId(ResType resType, const std::string &name);
39    uint64_t GetMaxId(uint64_t startId) const;
40    int64_t GetCurId();
41    uint64_t appId_;
42    uint64_t maxId_;
43    ResourceIdCluster type_;
44    std::map<std::pair<ResType, std::string>, int64_t> ids_;
45    std::map<std::pair<ResType, std::string>, ResourceId> sysDefinedIds_;
46    std::map<std::pair<ResType, std::string>, ResourceId> appDefinedIds_;
47    std::vector<int64_t> delIds_;
48    std::map<std::pair<ResType, std::string>, int64_t> cacheIds_;
49};
50}
51}
52}
53#endif
54