Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
symap.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2024 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3/*
4 * This file incorporates work covered by the following copyright and
5 * permission notice:
6 *
7 Copyright 2011-2014 David Robillard <http://drobilla.net>
8
9 Permission to use, copy, modify, and/or distribute this software for any
10 purpose with or without fee is hereby granted, provided that the above
11 copyright notice and this permission notice appear in all copies.
12
13 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20
21 SPDX-License-Identifier: ISC
22*/
23
32
33#ifndef SYMAP_H
34#define SYMAP_H
35
36#include <cstdint>
37#include <utility>
38
39#define ZSYMAP (ZRYTHM->symap)
40
45class Symap
46{
47public:
48 Symap () = default;
49 Symap (const Symap &other) { *this = other; }
50 Symap &operator= (const Symap &other)
51 {
52 Symap tmp (other);
53 swap (*this, tmp);
54 return *this;
55 }
56 Symap (Symap &&other) { *this = std::move (other); }
57 Symap &operator= (Symap &&other)
58 {
59 Symap tmp (std::move (other));
60 swap (*this, tmp);
61 return *this;
62 }
63 ~Symap ();
64
65 friend void swap (Symap &first, Symap &second) // nothrow
66 {
67 using std::swap;
68
69 swap (first.index, second.index);
70 swap (first.size, second.size);
71 swap (first.symbols, second.symbols);
72 }
73
77 uint32_t try_map (const char * sym);
78
84 uint32_t map (const char * sym);
85
91 const char * unmap (uint32_t id);
92
93private:
94 uint32_t search (const char * sym, bool * exact) const;
95
100 char ** symbols = nullptr;
101
105 uint32_t * index = nullptr;
106
110 uint32_t size = 0;
111};
112
113#endif /* SYMAP_H */
const char * unmap(uint32_t id)
Unmap a symbol ID back to a symbol, or NULL if no such ID exists.
uint32_t try_map(const char *sym)
Map a string to a symbol ID if it is already mapped, otherwise return 0.
uint32_t map(const char *sym)
Map a string to a symbol ID.