Debian Codegraph @

modules/lsp-audio-pipewire-lib/include/lsp-plug.in/audio/pipewire/dictionary.h

raw
1 /*
2 * Copyright (C) 2026 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2026 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-plugins
6 * Created on: 26 апр. 2026 г.
7 *
8 * lsp-plugins is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-plugins is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef LSP_PLUG_IN_AUDIO_PIPEWIRE_DICTIONARY_H_
23 #define LSP_PLUG_IN_AUDIO_PIPEWIRE_DICTIONARY_H_
24
25 #include <lsp-plug.in/audio/pipewire/version.h>
26
27 #include <lsp-plug.in/common/debug.h>
28 #include <lsp-plug.in/common/variadic.h>
29 #include <lsp-plug.in/common/status.h>
30 #include <lsp-plug.in/common/types.h>
31
32 #include <pw-headers/pipewire/properties.h>
33 #include <pw-headers/spa/utils/dict.h>
34
35 namespace lsp
36 {
37 namespace audio
38 {
39 namespace pipewire
40 {
41 typedef struct dictionary
42 {
43 protected:
44 spa_dict sData;
45 uint32_t nCapacity;
46 mutable char *sToString;
47
48 protected:
49 uint32_t index_of(const char *key) const noexcept;
50 status_t ensure_capacity() noexcept;
51 status_t append(const char *key, const char *value) noexcept;
52 status_t insert_at(size_t index, const char *key, const char *value) noexcept;
53
54 public:
55 dictionary() noexcept;
56 dictionary(const dictionary &) = delete;
57 dictionary(dictionary && src) noexcept;
58 dictionary & operator = (const dictionary &) = delete;
59 dictionary & operator = (dictionary && src) noexcept;
60 ~dictionary() noexcept;
61
62 void construct() noexcept;
63 void destroy() noexcept;
64 void swap(dictionary *dst) noexcept;
65 void swap(dictionary &dst) noexcept;
66
67 public:
68 status_t set(const pw_properties *props) noexcept;
69 status_t set(const spa_dict *props) noexcept;
70 status_t set(const dictionary *props) noexcept;
71
72 status_t put(const char *key, const char *value) noexcept;
73 status_t put(const spa_dict_item *item) noexcept;
74 status_t put(spa_dict_item item) noexcept;
75 status_t put(const pw_properties *props) noexcept;
76 status_t put(const spa_dict *props) noexcept;
77 status_t put(const dictionary *props) noexcept;
78 const char *value(const char *key, const char *dfl = NULL) const noexcept;
79 const spa_dict_item *item(const char *key) const noexcept;
80 const char *key(size_t index) const noexcept;
81 const char *value(size_t index) const noexcept;
82 const spa_dict_item *item(size_t index) const noexcept;
83 bool exists(const char *key) const noexcept;
84 const char *to_string() const noexcept;
85
86 public:
87 inline const spa_dict *dict() const noexcept { return &sData; }
88 inline const spa_dict_item *items() const noexcept { return sData.items; }
89 inline size_t size() const noexcept { return sData.n_items; }
90 inline size_t capacity() const noexcept { return nCapacity; }
91 inline pw_properties *make_properties() const noexcept{ return pw_properties_new_dict(&sData); }
92 inline bool contains(const char *key) const noexcept { return exists(key); }
93 inline bool is_empty() const noexcept { return sData.n_items == 0; }
94 inline void clear() noexcept { destroy(); }
95
96 public:
97 template <typename ... A>
98 inline status_t put(const char *key, const char *value, A && ... args) noexcept
99 {
100 const status_t res = put(key, value);
101 return (res == STATUS_OK) ? put(lsp::forward<A>(args)...) : res;
102 }
103
104 template <typename ... A>
105 inline status_t put(const spa_dict_item *item, A && ... args) noexcept
106 {
107 const status_t res = put(item);
108 return (res == STATUS_OK) ? put(lsp::forward<A>(args)...) : res;
109 }
110
111 template <typename ... A>
112 inline status_t put(spa_dict_item item, A && ... args) noexcept
113 {
114 const status_t res = put(item);
115 return (res == STATUS_OK) ? put(lsp::forward<A>(args)...) : res;
116 }
117
118 template <typename ... A>
119 inline status_t put(const pw_properties *props, A && ... args) noexcept
120 {
121 const status_t res = put(props);
122 return (res == STATUS_OK) ? put(lsp::forward<A>(args)...) : res;
123 }
124
125 template <typename ... A>
126 inline status_t put(const spa_dict *props, A && ... args) noexcept
127 {
128 const status_t res = put(props);
129 return (res == STATUS_OK) ? put(lsp::forward<A>(args)...) : res;
130 }
131
132 template <typename ... A>
133 inline status_t put(const dictionary *props, A && ... args) noexcept
134 {
135 const status_t res = put(props);
136 return (res == STATUS_OK) ? put(lsp::forward<A>(args)...) : res;
137 }
138 } dictionary;
139
140 } /* namespace pipewire */
141 } /* namespace audio */
142 } /* namespace lsp */
143
144
145 #endif /* LSP_PLUG_IN_AUDIO_PIPEWIRE_DICTIONARY_H_ */