Mercurial > pidgin
comparison src/stringref.h @ 7786:203a18e56dc6
[gaim-migrate @ 8431]
* Documentation is good. Not that I have any idea if any of my
documentation works, because I haven't checked... I totally made up
@note, but it sure seems reasonable to me.
* A couple of stringref utility functions which seem useful in any
case, like len and cmp.
* I'm going ahead and pushing a stringref creation function which
creates a zero-refcount stringref into CVS... Nothing uses it yet,
but I think that it is useful even in the absence of major stringref
conversion ... because it's garbage collected! If no one refs it
before the next iteration of the mainloop, it will be freed ... if
it is ref'd, of course, it will have to be freed normally by an
unref at some later point.
committer: Tailor Script <tailor@pidgin.im>
author | Ethan Blanton <elb@pidgin.im> |
---|---|
date | Sun, 07 Dec 2003 16:28:34 +0000 |
parents | 4e5c48ea9478 |
children | 21be2d9e8399 |
comparison
equal
deleted
inserted
replaced
7785:d5ee9c6da122 | 7786:203a18e56dc6 |
---|---|
24 | 24 |
25 #ifndef _GAIM_STRINGREF_H_ | 25 #ifndef _GAIM_STRINGREF_H_ |
26 #define _GAIM_STRINGREF_H_ | 26 #define _GAIM_STRINGREF_H_ |
27 | 27 |
28 /** | 28 /** |
29 * The internal representation of a stringref. | |
30 * | |
29 * @note For this structure to be useful, the string contained within | 31 * @note For this structure to be useful, the string contained within |
30 * it must be immutable -- for this reason, do _not_ access it | 32 * it must be immutable -- for this reason, do _not_ access it |
31 * directly! | 33 * directly! |
32 */ | 34 */ |
33 typedef struct _GaimStringref { | 35 typedef struct _GaimStringref { |
34 int ref; | 36 unsigned int ref; /**< The reference count of this string. |
35 char value[0]; | 37 * Note that reference counts are only |
38 * 31 bits, and the high-order bit | |
39 * indicates whether this string is up | |
40 * for GC at the next idle handler... | |
41 * But you aren't going to touch this | |
42 * anyway, right? */ | |
43 char value[0]; /**< The string contained in this ref. | |
44 * Notice that it is simply "hanging | |
45 * off the end" of the ref ... this | |
46 * is to save an allocation. */ | |
36 } GaimStringref; | 47 } GaimStringref; |
37 | 48 |
38 /** | 49 /** |
39 * Creates an immutable reference-counted string object. The newly | 50 * Creates an immutable reference-counted string object. The newly |
40 * created object will have a reference count of 1. | 51 * created object will have a reference count of 1. |
44 * | 55 * |
45 * @return A newly allocated string reference object with a refcount | 56 * @return A newly allocated string reference object with a refcount |
46 * of 1. | 57 * of 1. |
47 */ | 58 */ |
48 GaimStringref *gaim_stringref_new(const char *value); | 59 GaimStringref *gaim_stringref_new(const char *value); |
60 | |
61 /** | |
62 * Creates an immutable reference-counted string object. The newly | |
63 * created object will have a reference count of zero, and if it is | |
64 * not referenced before the next iteration of the mainloop it will | |
65 * be freed at that time. | |
66 * | |
67 * @param value This will be the value of the string; it will be | |
68 * duplicated. | |
69 * | |
70 * @return A newly allocated string reference object with a refcount | |
71 * of zero. | |
72 */ | |
73 GaimStringref *gaim_stringref_new_noref(const char *value); | |
49 | 74 |
50 /** | 75 /** |
51 * Creates an immutable reference-counted string object from a printf | 76 * Creates an immutable reference-counted string object from a printf |
52 * format specification and arguments. The created object will have a | 77 * format specification and arguments. The created object will have a |
53 * reference count of 1. | 78 * reference count of 1. |
93 * | 118 * |
94 * @return The contents of the string reference. | 119 * @return The contents of the string reference. |
95 */ | 120 */ |
96 const char *gaim_stringref_value(const GaimStringref *stringref); | 121 const char *gaim_stringref_value(const GaimStringref *stringref); |
97 | 122 |
123 /** | |
124 * Compare two stringrefs for string equality. This returns the same | |
125 * value as strcmp would, where <0 indicates that s1 is "less than" s2 | |
126 * in the ASCII lexicography, 0 indicates equality, etc. | |
127 * | |
128 * @param s1 The reference string. | |
129 * | |
130 * @param s2 The string to compare against the reference. | |
131 * | |
132 * @return An ordering indication on s1 and s2. | |
133 */ | |
134 int gaim_stringref_cmp(const GaimStringref *s1, const GaimStringref *s2); | |
135 | |
136 /** | |
137 * Find the length of the string inside a stringref. | |
138 * | |
139 * @param stringref The string in whose length we are interested. | |
140 * | |
141 * @return The length of the string in stringref | |
142 */ | |
143 size_t gaim_stringref_len(const GaimStringref *stringref); | |
144 | |
98 #endif /* _GAIM_STRINGREF_H_ */ | 145 #endif /* _GAIM_STRINGREF_H_ */ |