/src/libheif/libheif/id_creator.h
Line | Count | Source |
1 | | /* |
2 | | * HEIF codec. |
3 | | * Copyright (c) 2026 Dirk Farin <dirk.farin@gmail.com> |
4 | | * |
5 | | * This file is part of libheif. |
6 | | * |
7 | | * libheif is free software: you can redistribute it and/or modify |
8 | | * it under the terms of the GNU Lesser General Public License as |
9 | | * published by the Free Software Foundation, either version 3 of |
10 | | * the License, or (at your option) any later version. |
11 | | * |
12 | | * libheif is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | * GNU Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General Public License |
18 | | * along with libheif. If not, see <http://www.gnu.org/licenses/>. |
19 | | */ |
20 | | |
21 | | #ifndef LIBHEIF_ID_CREATOR_H |
22 | | #define LIBHEIF_ID_CREATOR_H |
23 | | |
24 | | #include "error.h" |
25 | | #include <cstdint> |
26 | | |
27 | | class IDCreator |
28 | | { |
29 | | public: |
30 | | enum class Namespace { item, track, entity_group }; |
31 | | |
32 | 0 | void set_unif(bool flag) { m_unif = flag; } |
33 | | |
34 | 0 | bool get_unif() const { return m_unif; } |
35 | | |
36 | | // Returns a new unique ID for the given namespace. |
37 | | // In non-unif mode: separate counters per namespace. |
38 | | // In unif mode: single global counter shared across all namespaces. |
39 | | // Returns error on overflow (counter would exceed 0xFFFFFFFF). |
40 | | Result<uint32_t> get_new_id(Namespace ns); |
41 | | |
42 | | private: |
43 | | bool m_unif = false; |
44 | | uint32_t m_next_id_item = 1; |
45 | | uint32_t m_next_id_track = 1; |
46 | | uint32_t m_next_id_entity_group = 1; |
47 | | uint32_t m_next_id_global = 1; // used in unif mode |
48 | | }; |
49 | | |
50 | | #endif |