annotate src/stringref.h @ 7944:a99f0aebc7ce

[gaim-migrate @ 8615] assorted jabber tweaks committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sun, 28 Dec 2003 04:27:27 +0000
parents 21be2d9e8399
children fa6395637e2c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7763
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
1 /**
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
2 * @file stringref.h Reference-counted immutable strings
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
3 * @ingroup core
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
4 *
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
5 * gaim
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
6 *
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
7 * Copyright (C) 2003 Ethan Blanton <elb@elitists.net>
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
8 *
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
12 * (at your option) any later version.
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
13 *
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
17 * GNU General Public License for more details.
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
18 *
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
22 *
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
23 */
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
24
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
25 #ifndef _GAIM_STRINGREF_H_
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
26 #define _GAIM_STRINGREF_H_
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
27
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
28 /**
7786
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
29 * The internal representation of a stringref.
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
30 *
7763
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
31 * @note For this structure to be useful, the string contained within
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
32 * it must be immutable -- for this reason, do _not_ access it
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
33 * directly!
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
34 */
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
35 typedef struct _GaimStringref {
7791
21be2d9e8399 [gaim-migrate @ 8437]
Nathan Walp <nwalp@pidgin.im>
parents: 7786
diff changeset
36 guint32 ref; /**< The reference count of this string.
21be2d9e8399 [gaim-migrate @ 8437]
Nathan Walp <nwalp@pidgin.im>
parents: 7786
diff changeset
37 * Note that reference counts are only
21be2d9e8399 [gaim-migrate @ 8437]
Nathan Walp <nwalp@pidgin.im>
parents: 7786
diff changeset
38 * 31 bits, and the high-order bit
21be2d9e8399 [gaim-migrate @ 8437]
Nathan Walp <nwalp@pidgin.im>
parents: 7786
diff changeset
39 * indicates whether this string is up
21be2d9e8399 [gaim-migrate @ 8437]
Nathan Walp <nwalp@pidgin.im>
parents: 7786
diff changeset
40 * for GC at the next idle handler...
21be2d9e8399 [gaim-migrate @ 8437]
Nathan Walp <nwalp@pidgin.im>
parents: 7786
diff changeset
41 * But you aren't going to touch this
21be2d9e8399 [gaim-migrate @ 8437]
Nathan Walp <nwalp@pidgin.im>
parents: 7786
diff changeset
42 * anyway, right? */
21be2d9e8399 [gaim-migrate @ 8437]
Nathan Walp <nwalp@pidgin.im>
parents: 7786
diff changeset
43 char value[0]; /**< The string contained in this ref.
21be2d9e8399 [gaim-migrate @ 8437]
Nathan Walp <nwalp@pidgin.im>
parents: 7786
diff changeset
44 * Notice that it is simply "hanging
21be2d9e8399 [gaim-migrate @ 8437]
Nathan Walp <nwalp@pidgin.im>
parents: 7786
diff changeset
45 * off the end" of the ref ... this
21be2d9e8399 [gaim-migrate @ 8437]
Nathan Walp <nwalp@pidgin.im>
parents: 7786
diff changeset
46 * is to save an allocation. */
7763
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
47 } GaimStringref;
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
48
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
49 /**
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
50 * Creates an immutable reference-counted string object. The newly
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
51 * created object will have a reference count of 1.
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
52 *
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
53 * @param value This will be the value of the string; it will be
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
54 * duplicated.
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
55 *
7767
1f4005fcd872 [gaim-migrate @ 8412]
Ethan Blanton <elb@pidgin.im>
parents: 7763
diff changeset
56 * @return A newly allocated string reference object with a refcount
1f4005fcd872 [gaim-migrate @ 8412]
Ethan Blanton <elb@pidgin.im>
parents: 7763
diff changeset
57 * of 1.
7763
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
58 */
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
59 GaimStringref *gaim_stringref_new(const char *value);
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
60
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
61 /**
7786
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
62 * Creates an immutable reference-counted string object. The newly
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
63 * created object will have a reference count of zero, and if it is
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
64 * not referenced before the next iteration of the mainloop it will
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
65 * be freed at that time.
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
66 *
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
67 * @param value This will be the value of the string; it will be
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
68 * duplicated.
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
69 *
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
70 * @return A newly allocated string reference object with a refcount
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
71 * of zero.
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
72 */
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
73 GaimStringref *gaim_stringref_new_noref(const char *value);
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
74
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
75 /**
7767
1f4005fcd872 [gaim-migrate @ 8412]
Ethan Blanton <elb@pidgin.im>
parents: 7763
diff changeset
76 * Creates an immutable reference-counted string object from a printf
1f4005fcd872 [gaim-migrate @ 8412]
Ethan Blanton <elb@pidgin.im>
parents: 7763
diff changeset
77 * format specification and arguments. The created object will have a
1f4005fcd872 [gaim-migrate @ 8412]
Ethan Blanton <elb@pidgin.im>
parents: 7763
diff changeset
78 * reference count of 1.
1f4005fcd872 [gaim-migrate @ 8412]
Ethan Blanton <elb@pidgin.im>
parents: 7763
diff changeset
79 *
1f4005fcd872 [gaim-migrate @ 8412]
Ethan Blanton <elb@pidgin.im>
parents: 7763
diff changeset
80 * @param format A printf-style format specification.
1f4005fcd872 [gaim-migrate @ 8412]
Ethan Blanton <elb@pidgin.im>
parents: 7763
diff changeset
81 *
1f4005fcd872 [gaim-migrate @ 8412]
Ethan Blanton <elb@pidgin.im>
parents: 7763
diff changeset
82 * @return A newly allocated string reference object with a refcount
1f4005fcd872 [gaim-migrate @ 8412]
Ethan Blanton <elb@pidgin.im>
parents: 7763
diff changeset
83 * of 1.
1f4005fcd872 [gaim-migrate @ 8412]
Ethan Blanton <elb@pidgin.im>
parents: 7763
diff changeset
84 */
1f4005fcd872 [gaim-migrate @ 8412]
Ethan Blanton <elb@pidgin.im>
parents: 7763
diff changeset
85 GaimStringref *gaim_stringref_printf(const char *format, ...);
1f4005fcd872 [gaim-migrate @ 8412]
Ethan Blanton <elb@pidgin.im>
parents: 7763
diff changeset
86
1f4005fcd872 [gaim-migrate @ 8412]
Ethan Blanton <elb@pidgin.im>
parents: 7763
diff changeset
87 /**
7763
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
88 * Increase the reference count of the given stringref.
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
89 *
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
90 * @param stringref String to be referenced.
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
91 *
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
92 * @return A pointer to the referenced string.
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
93 */
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
94 GaimStringref *gaim_stringref_ref(GaimStringref *stringref);
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
95
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
96 /**
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
97 * Decrease the reference count of the given stringref. If this
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
98 * reference count reaches zero, the stringref will be freed; thus
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
99 * you MUST NOT use this string after dereferencing it.
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
100 *
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
101 * @param stringref String to be dereferenced.
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
102 */
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
103 void gaim_stringref_unref(GaimStringref *stringref);
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
104
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
105 /**
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
106 * Retrieve the value of a stringref.
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
107 *
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
108 * @note This value should not be cached or stored in a local variable.
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
109 * While there is nothing inherently incorrect about doing so, it
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
110 * is easy to forget that the cached value is in fact a
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
111 * reference-counted object and accidentally use it after
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
112 * dereferencing. This is more problematic for a reference-
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
113 * counted object than a heap-allocated object, as it may seem to
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
114 * be valid or invalid nondeterministically based on how many
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
115 * other references to it exist.
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
116 *
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
117 * @param stringref String reference from which to retrieve the value.
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
118 *
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
119 * @return The contents of the string reference.
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
120 */
7768
4e5c48ea9478 [gaim-migrate @ 8413]
Ethan Blanton <elb@pidgin.im>
parents: 7767
diff changeset
121 const char *gaim_stringref_value(const GaimStringref *stringref);
7763
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
122
7786
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
123 /**
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
124 * Compare two stringrefs for string equality. This returns the same
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
125 * value as strcmp would, where <0 indicates that s1 is "less than" s2
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
126 * in the ASCII lexicography, 0 indicates equality, etc.
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
127 *
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
128 * @param s1 The reference string.
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
129 *
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
130 * @param s2 The string to compare against the reference.
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
131 *
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
132 * @return An ordering indication on s1 and s2.
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
133 */
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
134 int gaim_stringref_cmp(const GaimStringref *s1, const GaimStringref *s2);
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
135
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
136 /**
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
137 * Find the length of the string inside a stringref.
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
138 *
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
139 * @param stringref The string in whose length we are interested.
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
140 *
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
141 * @return The length of the string in stringref
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
142 */
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
143 size_t gaim_stringref_len(const GaimStringref *stringref);
203a18e56dc6 [gaim-migrate @ 8431]
Ethan Blanton <elb@pidgin.im>
parents: 7768
diff changeset
144
7763
dc79649b829d [gaim-migrate @ 8408]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
145 #endif /* _GAIM_STRINGREF_H_ */