1 /*
2 Copyright (C) 2015-2021, Dirk Krause
3 SPDX-License-Identifier: BSD-3-Clause
4 */
5 
6 /*
7 	WARNING: This file was generated by the dkct program (see
8 	http://dktools.sourceforge.net/ for details).
9 	Changes you make here will be lost if dkct is run again!
10 	You should modify the original source and run dkct on it.
11 	Original source: dk4dbitw.ctr
12 */
13 
14 #ifndef DK4DBITW_H_INCLUDED
15 /** Avoid multiple inclusions. */
16 #define DK4DBITW_H_INCLUDED 1
17 
18 
19 /**	@file	dk4dbitw.h	Text (wchar_t) in database.
20 */
21 
22 #ifndef	DK4CONF_H_INCLUDED
23 #if DK4_BUILDING_DKTOOLS4
24 #include "dk4conf.h"
25 #else
26 #include <dktools-4/dk4conf.h>
27 #endif
28 #endif
29 
30 #ifndef DK4DBI_H_INCLUDED
31 #if DK4_BUILDING_DKTOOLS4
32 #include <libdk4dbi/dk4dbi.h>
33 #else
34 #include <dktools-4/dk4dbi.h>
35 #endif
36 #endif
37 
38 #if DK4_HAVE_WCHAR_H
39 #ifndef WCHAR_H_INCLUDED
40 #include <wchar.h>
41 #define	WCHAR_H_INCLUDED 1
42 #endif
43 #endif
44 
45 /**	Function used when traversing a simple database.
46 	@param	obj	Object to modify during traversal.
47 	@param	k	Current key.
48 	@param	v	Current value.
49 */
50 typedef
51 int
52 dk4dbi_wc_traverse_fct_t(
53   void		*obj,
54   const wchar_t	*k,
55   const wchar_t	*v
56 );
57 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 /**	Set text entry.
63 	@param	db	Database to modify.
64 	@param	k	Key text.
65 	@param	v	Value text.
66 	@param	erp	Error report, may be NULL.
67 	@return	1 on success, 0 on error.
68 
69 	Error codes:
70 	- DK4_E_INVALID_ARGUMENTS<br>
71 	  if db, k or vis NULL,
72 	- DK4_E_SYNTAX<br>
73 	  if the database was opened read-only or k or v
74 	  is too long.
75 	- DK4_E_MATH_OVERFLOW<br>
76 	  on numeric overflow in size calculation,
77 	- DK4_E_NOT_SUPPORTED<br>
78 	  if db indicates an unsupported backend,
79 	- DK4_E_NOT_FOUND<br>
80 	  if no record to delete was found,
81 	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
82 	  with mem.elsize and mem.nelem
83 	  set if there is not enough memory available,
84 	- DK4_E_WRITE_FAILED<br>
85 	  if modification of the database failed.
86 */
87 int
88 dk4dbi_wc_set(
89   dk4_dbi_t	*db,
90   const wchar_t	*k,
91   const wchar_t	*v,
92   dk4_er_t	*erp
93 );
94 
95 /**	Retrieve text entry.
96 	@param	db	Database to query.
97 	@param	k	Key text.
98 	@param	vbuf	Result buffer address.
99 	@param	vsz	Pointer to size variable (in: size, out: used),
100 			number of wchar_t.
101 	@param	erp	Error report, may be NULL.
102 	@return	1 on success, 0 on error.
103 
104 	Error codes:
105 	- DK4_E_INVALID_ARGUMENTS<br>
106 	  if db, k or vbufis NULL or vsz is 0,
107 	  or the length of k exceeds the key size limit,
108 	- DK4_E_MATH_OVERFLOW<br>
109 	  on numeric overflow in size calculation,
110 	- DK4_E_NOT_SUPPORTED<br>
111 	  if db indicates an unsupported backend,
112 	- DK4_E_NOT_FOUND<br>
113 	  if no record was found for the key,
114 	- DK4_E_BUFFER_TOO_SMALL<br>
115 	  if the destination buffer is too small.
116 */
117 int
118 dk4dbi_wc_get(
119   dk4_dbi_t	*db,
120   const wchar_t	*k,
121   wchar_t	*vbuf,
122   size_t	 vsz,
123   dk4_er_t	*erp
124 );
125 
126 /**	Delete text entry.
127 	@param	db	Database to modify.
128 	@param	k	Key text.
129 	@param	erp	Error report, may be NULL.
130 	@return	1 on success, 0 on error.
131 
132 	Error codes:
133 	- DK4_E_INVALID_ARGUMENTS<br>
134 	  if db or k is NULL,
135 	- DK4_E_SYNTAX<br>
136 	  if the database is opened read-only or the length of
137 	  k exceeds the key size limit,
138 	- DK4_E_MATH_OVERFLOW<br>
139 	  on numeric overflow in size calculation,
140 	- DK4_E_NOT_SUPPORTED<br>
141 	  if db indicates an unsupported backend,
142 	- DK4_E_WRITE_FAILED<br>
143 	  if modification of the database failed,
144 	- DK4_E_NOT_FOUND<br>
145 	  if no record for the specified key is in the database.
146 */
147 int
148 dk4dbi_wc_del(
149   dk4_dbi_t	*db,
150   const wchar_t	*k,
151   dk4_er_t	*erp
152 );
153 
154 /**	Traverse database, apply function to all text entries.
155 	@param	db	Database to traverse.
156 	@param	obj	Object to modify during traversal.
157 	@param	fct	Function to apply to all text entries.
158 	@return	1 on success, 0 on error (database traversed),
159 	-1 on error (traversal aborted).
160 */
161 int
162 dk4dbi_wc_traverse(
163   dk4_dbi_t			*db,
164   void				*obj,
165   dk4dbi_wc_traverse_fct_t	*fct
166 );
167 
168 #ifdef __cplusplus
169 }
170 #endif
171 
172 
173 #endif
174