summaryrefslogtreecommitdiff
path: root/src/lib/eina_binbuf_template_c.x
blob: 7e0c539f9aa46fb6bf7b09a156e4bd102a11d174 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */

/* This file should be included from files implementing binbuf.
 * The including file should define the following macros:
 * _STRBUF_DATA_TYPE
 * _STRBUF_CSIZE
 * _STRBUF_STRUCT_NAME
 * _STRBUF_MAGIC
 * _STRBUF_MAGIC_STR
 * _FUNC_EXPAND
 * See how it's done in eina_ustrbuf.c and eina_strbuf.c. This just makes things
 * a lot easier since those are essentially the same just with different sizes.
 */

/*============================================================================*
 *                                 Global                                     *
 *============================================================================*/

/**
 * @internal
 * @brief Initialize the strbuf module.
 *
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * This function sets up the strbuf module of Eina. It is called by
 * eina_init().
 *
 * @see eina_init()
 */
Eina_Bool
_FUNC_EXPAND(init)(void)
{
   eina_magic_string_static_set(_STRBUF_MAGIC, _STRBUF_MAGIC_STR);
   return eina_strbuf_common_init();
}

/**
 * @internal
 * @brief Shut down the strbuf module.
 *
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * This function shuts down the strbuf module set up by
 * eina_ustrbuf_init(). It is called by eina_shutdown().
 *
 * @see eina_shutdown()
 */
Eina_Bool
_FUNC_EXPAND(shutdown)(void)
{
   return eina_strbuf_common_shutdown();
}

/*============================================================================*
 *                                   API                                      *
 *============================================================================*/

EAPI _STRBUF_STRUCT_NAME *
_FUNC_EXPAND(new)(void)
{
   _STRBUF_STRUCT_NAME *buf = eina_strbuf_common_new(_STRBUF_CSIZE);
   EINA_MAGIC_SET(buf, _STRBUF_MAGIC);
   return buf;
}

EAPI _STRBUF_STRUCT_NAME *
_FUNC_EXPAND(manage_new_length)(_STRBUF_DATA_TYPE *str, size_t length)
{
   _STRBUF_STRUCT_NAME *buf =
      eina_strbuf_common_manage_new(_STRBUF_CSIZE, (void *) str, length);
   EINA_MAGIC_SET(buf, _STRBUF_MAGIC);
   return buf;
}

EAPI void
_FUNC_EXPAND(free)(_STRBUF_STRUCT_NAME *buf)
{
   EINA_MAGIC_CHECK_STRBUF(buf);
   EINA_MAGIC_SET(buf, EINA_MAGIC_NONE);
   eina_strbuf_common_free(buf);
}

EAPI void
_FUNC_EXPAND(reset)(_STRBUF_STRUCT_NAME *buf)
{
   EINA_MAGIC_CHECK_STRBUF(buf);
   eina_strbuf_common_reset(_STRBUF_CSIZE, buf);
}

EAPI Eina_Bool
_FUNC_EXPAND(append_length)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str, size_t length)
{
   EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
   return eina_strbuf_common_append_length(_STRBUF_CSIZE, buf, (const void *) str, length);
}

EAPI Eina_Bool
_FUNC_EXPAND(insert_length)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str, size_t length, size_t pos)
{
   EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
   return eina_strbuf_common_insert_length(_STRBUF_CSIZE, buf, (const void *) str, length, pos);
}

EAPI Eina_Bool
_FUNC_EXPAND(append_char)(_STRBUF_STRUCT_NAME *buf, _STRBUF_DATA_TYPE c)
{
   EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
   return eina_strbuf_common_append_char(_STRBUF_CSIZE, buf, (const void *) &c);
}

EAPI Eina_Bool
_FUNC_EXPAND(insert_char)(_STRBUF_STRUCT_NAME *buf, _STRBUF_DATA_TYPE c, size_t pos)
{
   EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
   return eina_strbuf_common_insert_char(_STRBUF_CSIZE, buf, (const void *) &c, pos);
}

EAPI Eina_Bool
_FUNC_EXPAND(remove)(_STRBUF_STRUCT_NAME *buf, size_t start, size_t end)
{
   EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
   return eina_strbuf_common_remove(_STRBUF_CSIZE, buf, start, end);
}

EAPI const _STRBUF_DATA_TYPE *
_FUNC_EXPAND(string_get)(const _STRBUF_STRUCT_NAME *buf)
{
   EINA_MAGIC_CHECK_STRBUF(buf, NULL);
   return (const _STRBUF_DATA_TYPE *) eina_strbuf_common_string_get(buf);
}

EAPI _STRBUF_DATA_TYPE *
_FUNC_EXPAND(string_steal)(_STRBUF_STRUCT_NAME *buf)
{
   EINA_MAGIC_CHECK_STRBUF(buf, NULL);
   return (_STRBUF_DATA_TYPE *) eina_strbuf_common_string_steal(_STRBUF_CSIZE, buf);
}

EAPI void
_FUNC_EXPAND(string_free)(_STRBUF_STRUCT_NAME *buf)
{
   EINA_MAGIC_CHECK_STRBUF(buf);
   eina_strbuf_common_string_free(_STRBUF_CSIZE, buf);
}

EAPI size_t
_FUNC_EXPAND(length_get)(const _STRBUF_STRUCT_NAME *buf)
{
   EINA_MAGIC_CHECK_STRBUF(buf, 0);
   return eina_strbuf_common_length_get(buf);
}