GnuCash  4.8a-80-g9825132ea+
qof-string-cache.h
Go to the documentation of this file.
1 /********************************************************************\
2  * qof-string-cache.h -- QOF string cache functions *
3  * *
4  * This program is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public License as *
6  * published by the Free Software Foundation; either version 2 of *
7  * the License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License*
15  * along with this program; if not, contact: *
16  * *
17  * Free Software Foundation Voice: +1-617-542-5942 *
18  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
19  * Boston, MA 02110-1301, USA gnu@gnu.org *
20 \********************************************************************/
21 
33 #ifndef QOF_STRING_UTIL_H
34 #define QOF_STRING_UTIL_H
35 
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40 
41 #define QOF_MOD_UTIL "qof.utilities"
42 
74 void qof_string_cache_init(void);
75 
77 void qof_string_cache_destroy(void);
78 
82 void qof_string_cache_remove(const char * key);
83 
87 const char * qof_string_cache_insert(const char * key);
88 
91 const char * qof_string_cache_replace(const char * dst, const char * src);
92 
93 #define CACHE_INSERT(str) qof_string_cache_insert((str))
94 #define CACHE_REMOVE(str) qof_string_cache_remove((str))
95 
96 /* Replace cached string currently in 'dst' with string in 'src'.
97  * Typical usage:
98  * void foo_set_name(Foo *f, const char *str) {
99  * CACHE_REPLACE(f->name, str);
100  * }
101  * It avoids unnecessary ejection by doing INSERT before REMOVE.
102 */
103 #define CACHE_REPLACE(dst, src) do { \
104  const char *tmp = CACHE_INSERT((src)); \
105  CACHE_REMOVE((dst)); \
106  (dst) = tmp; \
107  } while (0)
108 
109 #define QOF_CACHE_NEW(void) qof_string_cache_insert("")
110 
111 #ifdef __cplusplus
112 }
113 #endif
114 
115 #endif /* QOF_STRING_CACHE_H */
116 
const char * qof_string_cache_replace(const char *dst, const char *src)
Same as CACHE_REPLACE below, but safe to call from C++.
void qof_string_cache_destroy(void)
Destroy the qof_string_cache.
const char * qof_string_cache_insert(const char *key)
You can use this function with g_hash_table_insert(), for the key (or value), as long as you use the ...
void qof_string_cache_remove(const char *key)
You can use this function as a destroy notifier for a GHashTable that uses common strings as keys (or...
void qof_string_cache_init(void)
The QOF String Cache: