/src/libheif/libheif/id_creator.cc
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 | | #include "id_creator.h" |
22 | | |
23 | | Result<uint32_t> IDCreator::get_new_id(Namespace ns) |
24 | 0 | { |
25 | 0 | if (m_unif) { |
26 | 0 | if (m_next_id_global == 0) { |
27 | 0 | return Error(heif_error_Usage_error, |
28 | 0 | heif_suberror_Unspecified, |
29 | 0 | "ID namespace overflow"); |
30 | 0 | } |
31 | 0 | return m_next_id_global++; |
32 | 0 | } |
33 | | |
34 | 0 | uint32_t* counter = nullptr; |
35 | 0 | switch (ns) { |
36 | 0 | case Namespace::item: |
37 | 0 | counter = &m_next_id_item; |
38 | 0 | break; |
39 | 0 | case Namespace::track: |
40 | 0 | counter = &m_next_id_track; |
41 | 0 | break; |
42 | 0 | case Namespace::entity_group: |
43 | 0 | counter = &m_next_id_entity_group; |
44 | 0 | break; |
45 | 0 | } |
46 | | |
47 | 0 | if (*counter == 0) { |
48 | 0 | return Error(heif_error_Usage_error, |
49 | 0 | heif_suberror_Unspecified, |
50 | 0 | "ID namespace overflow"); |
51 | 0 | } |
52 | | |
53 | 0 | return (*counter)++; |
54 | 0 | } |