1 /* EINA - EFL data type library
2 * Copyright (C) 2002-2008 Carsten Haitzler,
3 * Jorge Luis Zapata Muga,
5 * Gustavo Sverzut Barbieri
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library 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 GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library;
20 * if not, see <http://www.gnu.org/licenses/>.
24 * @page tutorial_ustringshare_page UStringshare Tutorial
34 #include "eina_config.h"
35 #include "eina_private.h"
36 #include "eina_unicode.h"
38 #include "eina_share_common.h"
40 /* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
41 #include "eina_safety_checks.h"
42 #include "eina_ustringshare.h"
48 #define CRITICAL(...) EINA_LOG_DOM_CRIT(_eina_share_ustringshare_log_dom, __VA_ARGS__)
53 #define ERR(...) EINA_LOG_DOM_ERR(_eina_share_ustringshare_log_dom, __VA_ARGS__)
58 #define DBG(...) EINA_LOG_DOM_DBG(_eina_share_ustringshare_log_dom, __VA_ARGS__)
60 static int _eina_share_ustringshare_log_dom = -1;
62 /* The actual share */
63 static Eina_Share *ustringshare_share;
64 static const char EINA_MAGIC_USTRINGSHARE_NODE_STR[] = "Eina UStringshare Node";
66 /*============================================================================*
68 *============================================================================*/
72 * @brief Initialize the share_common module.
74 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
76 * This function sets up the share_common module of Eina. It is called by
82 eina_ustringshare_init(void)
86 if (_eina_share_ustringshare_log_dom < 0)
88 _eina_share_ustringshare_log_dom = eina_log_domain_register
89 ("eina_ustringshare", EINA_LOG_COLOR_DEFAULT);
91 if (_eina_share_ustringshare_log_dom < 0)
93 EINA_LOG_ERR("Could not register log domain: eina_ustringshare");
98 ret = eina_share_common_init(&ustringshare_share,
99 EINA_MAGIC_USTRINGSHARE_NODE,
100 EINA_MAGIC_USTRINGSHARE_NODE_STR);
104 eina_log_domain_unregister(_eina_share_ustringshare_log_dom);
105 _eina_share_ustringshare_log_dom = -1;
113 * @brief Shut down the share_common module.
115 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
117 * This function shuts down the share_common module set up by
118 * eina_share_common_init(). It is called by eina_shutdown().
120 * @see eina_shutdown()
123 eina_ustringshare_shutdown(void)
126 ret = eina_share_common_shutdown(&ustringshare_share);
128 if (_eina_share_ustringshare_log_dom >= 0)
130 eina_log_domain_unregister(_eina_share_ustringshare_log_dom);
131 _eina_share_ustringshare_log_dom = -1;
137 /*============================================================================*
139 *============================================================================*/
142 eina_ustringshare_del(const Eina_Unicode *str)
147 if (!eina_share_common_del(ustringshare_share, (const char *)str))
148 CRITICAL("EEEK trying to del non-shared ustringshare \"%s\"", (const char *)str);
151 EAPI const Eina_Unicode *
152 eina_ustringshare_add_length(const Eina_Unicode *str, unsigned int slen)
154 return (const Eina_Unicode *)eina_share_common_add_length(ustringshare_share,
163 EAPI const Eina_Unicode *
164 eina_ustringshare_add(const Eina_Unicode *str)
166 int slen = (str) ? (int)eina_unicode_strlen(str) : -1;
167 return eina_ustringshare_add_length(str, slen);
170 EAPI const Eina_Unicode *
171 eina_ustringshare_ref(const Eina_Unicode *str)
173 return (const Eina_Unicode *)eina_share_common_ref(ustringshare_share,
178 eina_ustringshare_strlen(const Eina_Unicode *str)
180 int len = eina_share_common_length(ustringshare_share, (const char *)str);
181 len = (len > 0) ? len / (int)sizeof(Eina_Unicode) : -1;
186 eina_ustringshare_dump(void)
188 eina_share_common_dump(ustringshare_share, NULL, 0);