acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
registry.h
1//
2// registry.h
3// acme
4//
5// Created by Camilo Sasuke Thomas Borregaard Sørensen on 04/04/26.
6// Copyright © 2026 ca2 Software Development. All rights reserved.
7//
8#pragma once
9
10
11namespace platform
12{
13
14
16
17
18 /* --------------------------------------------------------------------------
19 Types
20 -------------------------------------------------------------------------- */
21
22 enum enum_registry
23 {
24 e_registry_none = 0,
25 e_registry_string = 1,
26 e_registry_dword = 2,
27 e_registry_qword = 3,
28 e_registry_binary = 4
29 };
30
31 /* --------------------------------------------------------------------------
32 Root key strings
33 -------------------------------------------------------------------------- */
34
35#define REGX_HKCU "HKCU"
36#define REGX_HKLM "HKLM"
37#define REGX_HKCR "HKCR"
38#define REGX_HKU "HKU"
39
40
41
42 class CLASS_DECL_ACME registry :
43 virtual public ::particle
44 {
45 public:
46
47 ::file::path m_path;
48
49 static ::pointer < registry > create_from_file(const ::file::path & pathRegistry);
50
51 virtual void open_from_file(const ::file::path & path) = 0;
52 virtual void flush() = 0;
53 virtual void close() = 0;
54 virtual ::pointer < registry_key_interface > open_key(const ::file::path & path) = 0;
55 virtual ::pointer < registry_key_interface > create_key(const ::file::path & path) = 0;
56 virtual void erase_key(const ::file::path & path) = 0;
57
58
59 };
60
61 class CLASS_DECL_ACME registry_key_interface :
62 virtual public ::particle
63 {
64 public:
65
66 ::pointer < registry > m_pregistry;
67 ::file::path m_path;
68
69
70 virtual void close() =0;
71
72
73 virtual ::e_status _set_string(const ::scoped_string &scopedstrName, const ::scoped_string &scopedstr) = 0;
74 virtual ::e_status _set_dword(const ::scoped_string &scopedstrName, ::u32 u) = 0;
75 virtual ::e_status _set_qword(const ::scoped_string &scopedstrName, ::u64 ull) = 0;
76 virtual ::e_status _set_binary(const ::scoped_string &scopedstrName, const ::block &block) = 0;
77
78
79 virtual ::e_status _get_string(const ::scoped_string &scopedstrName, ::string &str) = 0;
80 virtual ::e_status _get_dword(const ::scoped_string &scopedstrName, ::u32 &u) = 0;
81 virtual ::e_status _get_qword(const ::scoped_string &scopedstrName, ::u64 & ull) = 0;
82 virtual ::e_status _get_binary(const ::scoped_string &scopedstrName, ::memory & memory) = 0;
83
84
85 virtual ::e_status _erase_payload(const ::scoped_string &scopedstrName) = 0;
86 virtual ::e_status _has_payload(const ::scoped_string &scopedstrName, bool & bExists) = 0;
87 virtual ::e_status _payload_type(const ::scoped_string &scopedstrName, enum_registry & eregistry) = 0;
88
89
90 inline void set_string(const ::scoped_string &scopedstrName, const ::scoped_string & scopedstr)
91 {
92 auto estatus = _set_string(scopedstrName, scopedstr);
93 if (!estatus)
94 throw ::exception(estatus);
95 }
96
97 inline void set_dword(const ::scoped_string &scopedstrName, ::u32 u)
98 {
99 auto estatus = _set_dword(scopedstrName, u);
100 if (!estatus)
101 throw ::exception(estatus);
102 }
103
104 inline void set_qword(const ::scoped_string &scopedstrName, ::u64 ull)
105 {
106 auto estatus = _set_qword(scopedstrName, ull);
107 if (!estatus)
108 throw ::exception(estatus);
109 }
110
111 /*
112 Gets a binary value.
113
114 Usage pattern:
115 size_t size = 0;
116 RegXGetBinary(key, "Blob", NULL, &size);
117 void *buf = malloc(size);
118 RegXGetBinary(key, "Blob", buf, &size);
119 */
120 inline void set_binary(const ::scoped_string &scopedstrName, const ::block &block)
121 {
122 auto estatus = _set_binary(scopedstrName, block);
123 if (!estatus)
124 throw ::exception(estatus);
125 }
126
127
128 ::string get_string(const ::scoped_string &scopedstrName)
129 {
130 ::string str;
131 auto estatus = _get_string(scopedstrName, str);
132 if (!estatus)
133 throw ::exception(estatus);
134 return ::transfer(str);
135 }
136
137 inline ::u32 get_dword(const ::scoped_string &scopedstrName)
138 {
139 ::u32 u = 0;
140 auto estatus = _get_dword(scopedstrName, u);
141 if (!estatus)
142 throw ::exception(estatus);
143 return u;
144 }
145
146 inline ::u64 get_qword(const ::scoped_string &scopedstrName)
147 {
148 ::u64 ull = 0;
149 auto estatus = _get_qword(scopedstrName, ull);
150 if (!estatus)
151 throw ::exception(estatus);
152 return ull;
153 }
154
155 /*
156 Gets a binary value.
157
158 Usage pattern:
159 size_t size = 0;
160 RegXGetBinary(key, "Blob", NULL, &size);
161 void *buf = malloc(size);
162 RegXGetBinary(key, "Blob", buf, &size);
163 */
164 inline ::memory get_binary(const ::scoped_string &scopedstrName)
165 {
167 auto estatus = _get_binary(scopedstrName, memory);
168 if (!estatus)
169 throw ::exception(estatus);
170 return ::transfer(memory);
171 }
172
173 inline void erase_payload(const ::scoped_string &scopedstrName)
174 {
175 auto estatus = _erase_payload(scopedstrName);
176 if (estatus == error_not_found)
177 {
178
179 }
180 else if (!estatus)
181 throw ::exception(estatus);
182 }
183
184
185 inline bool has_payload(const ::scoped_string &scopedstrName)
186 {
187 bool bExists = false;
188 auto estatus = _has_payload(scopedstrName, bExists);
189 if (!estatus)
190 throw estatus;
191 return bExists;
192 }
193
194 inline enum_registry payload_type(const ::scoped_string &scopedstrName)
195 {
196 enum_registry eregistry = e_registry_none;
197 auto estatus = _payload_type(scopedstrName, eregistry);
198 if (!estatus)
199 throw estatus;
200 return eregistry;
201 }
202
203 };
204
206 {
207 };
208 class CLASS_DECL_ACME registry_key :
209 virtual public registry_key_interface
210 {
211 public:
212
213 ::pointer<registry_key_interface> m_pregistrykey;
214
215 registry_key();
216 registry_key(interface_t);
217 ~registry_key() override;
218
219 void close() override;
220
221 ::e_status _set_string(const ::scoped_string &scopedstrName, const ::scoped_string &scopedstr) override;
222 ::e_status _set_dword(const ::scoped_string &scopedstrName, ::u32 u) override;
223 ::e_status _set_qword(const ::scoped_string &scopedstrName, ::u64 ull) override;
224 ::e_status _set_binary(const ::scoped_string &scopedstrName, const ::block &block) override;
225
226 ::e_status _get_string(const ::scoped_string &scopedstrName, ::string &str) override;
227 ::e_status _get_dword(const ::scoped_string &scopedstrName, ::u32 &u) override;
228 ::e_status _get_qword(const ::scoped_string &scopedstrName, ::u64 &ull) override;
229 ::e_status _get_binary(const ::scoped_string &scopedstrName, ::memory &memory) override;
230
231
232 ::e_status _erase_payload(const ::scoped_string &scopedstrName) override;
233 ::e_status _has_payload(const ::scoped_string &scopedstrName, bool & bExists) override;
234 ::e_status _payload_type(const ::scoped_string &scopedstrName, enum_registry & eregistry) override;
235
236 };
237
238 // /* --------------------------------------------------------------------------
239// Opaque handles
240// -------------------------------------------------------------------------- */
241//
242// struct registry {
243// std::string filename;
244// Document doc;
245// };
246//
247// struct registry_key {
248// registry *owner;
249// std::string path;
250// };
251
252/* --------------------------------------------------------------------------
253 Registry lifecycle
254 -------------------------------------------------------------------------- */
255
256/*
257 Opens or creates a registry database backed by a JSON file.
258
259 Example:
260 registry *reg = NULL;
261 RegXOpen("registry.json", &reg);
262*/
263//::pointer < registry > RegXOpen(const ::file::path & path);
264
265/*
266 Writes the in-memory registry to disk.
267*/
268//::i32 RegXFlush(registry *reg);
269
270/*
271 Flushes and destroys the registry object.
272*/
273//void RegXClose(registry *reg);
274
275/* --------------------------------------------------------------------------
276 Key lifetime
277 -------------------------------------------------------------------------- */
278
279/*
280 Frees a key handle created by RegXOpenKey / RegXCreateKey.
281*/
282//void RegXCloseKey(registry_key *key);
283
284/* --------------------------------------------------------------------------
285 Key operations
286 -------------------------------------------------------------------------- */
287
288/*
289 Opens an existing key.
290
291 Example:
292 registry_key *key = NULL;
293 RegXOpenKey(reg, "HKCU\\Software\\MyApp", &key);
294*/
295//::i32 RegXOpenKey(registry *reg, const_char_pointer pszPath, registry_key **out_key);
296
297/*
298 Creates a key and any missing parents.
299
300 Example:
301 RegXCreateKey(reg, "HKCU\\Software\\MyApp", &key);
302*/
303//::i32 RegXCreateKey(registry *reg, const_char_pointer pszPath, registry_key **out_key);
304
305/*
306 Deletes a key and all descendants.
307*/
308//::i32 RegXDeleteKey(registry *reg, const_char_pointer pszPath);
309
310/* --------------------------------------------------------------------------
311 Value set operations
312 -------------------------------------------------------------------------- */
313
314// ::i32 RegXSetString(registry_key *key, const_char_pointer pszName, const_char_pointer value);
315// ::i32 RegXSetDword (registry_key *key, const_char_pointer pszName, uint32_t value);
316// ::i32 RegXSetBinary(registry_key *key, const_char_pointer pszName, const void *data, size_t size);
317
318/* --------------------------------------------------------------------------
319 Value get operations
320 -------------------------------------------------------------------------- */
321
322/*
323 Gets a string value.
324
325 Usage pattern:
326 size_t len = 0;
327 RegXGetString(key, "UserName", NULL, &len); // query required size
328 char_pointer buf = malloc(len);
329 RegXGetString(key, "UserName", buf, &len);
330*/
331//::i32 RegXGetString(registry_key *key, const_char_pointer pszName, char_pointer buf, size_t *inout_len);
332
333//::i32 RegXGetDword(registry_key *key, const_char_pointer pszName, uint32_t *out_value);
334
335/*
336 Gets a binary value.
337
338 Usage pattern:
339 size_t size = 0;
340 RegXGetBinary(key, "Blob", NULL, &size);
341 void *buf = malloc(size);
342 RegXGetBinary(key, "Blob", buf, &size);
343*/
344//::i32 RegXGetBinary(registry_key *key, const_char_pointer pszName, void *buf, size_t *inout_len);
345
346/* --------------------------------------------------------------------------
347 Value utility
348 -------------------------------------------------------------------------- */
349
350//::i32 RegXDeleteValue(registry_key *key, const_char_pointer pszName);
351//::i32 RegXValueExists(registry_key *key, const_char_pointer pszName);
352//::i32 RegXGetValueType(registry_key *key, const_char_pointer pszName, RegXType *out_type);
353
354/* --------------------------------------------------------------------------
355 Error strings
356 -------------------------------------------------------------------------- */
357
358 //const_char_pointer registry_error(::i32 status);
359
360
361} // namespace platform
362
363
364
Definition e_status.h:30
Definition path.h:52
Definition memory.h:33
Definition registry.h:63
Definition registry.h:44
include "thread/AutoLock.h"
Definition _forward_declaration.h:877
Definition block.h:46
Definition registry.h:206