Wed, 05 Sep 2007 22:32:14 +0000
propagate from branch 'im.pidgin.pidgin' (head 0853a065e5c3fcb5a6bb13fc23bec44ecf510ecd)
to branch 'im.pidgin.soc.2007.xmpp' (head b273d0db2bdd4a80d0fb22d32fe186e1f496933f)
|
19050
78ed2f8cd58d
Some changes from Matthew Goldstein and I to not automatically remove
Mark Doliner <markdoliner@pidgin.im>
parents:
15884
diff
changeset
|
1 | /* TODO: Can we just replace this whole thing with a GCache */ |
|
78ed2f8cd58d
Some changes from Matthew Goldstein and I to not automatically remove
Mark Doliner <markdoliner@pidgin.im>
parents:
15884
diff
changeset
|
2 | |
| 7763 | 3 | /** |
| 4 | * @file stringref.h Reference-counted immutable strings | |
| 5 | * @ingroup core | |
| 6 | * | |
| 15884 | 7 | * purple |
| 7763 | 8 | * |
| 15884 | 9 | * Purple is the legal property of its developers, whose names are too numerous |
| 8046 | 10 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 11 | * source distribution. | |
| 7763 | 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify | |
| 14 | * it under the terms of the GNU General Public License as published by | |
| 15 | * the Free Software Foundation; either version 2 of the License, or | |
| 16 | * (at your option) any later version. | |
| 17 | * | |
| 18 | * This program is distributed in the hope that it will be useful, | |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 21 | * GNU General Public License for more details. | |
| 22 | * | |
| 23 | * You should have received a copy of the GNU General Public License | |
| 24 | * along with this program; if not, write to the Free Software | |
| 25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 26 | * | |
| 27 | */ | |
| 15884 | 28 | #ifndef _PURPLE_STRINGREF_H_ |
| 29 | #define _PURPLE_STRINGREF_H_ | |
| 7763 | 30 | |
|
14988
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14254
diff
changeset
|
31 | #ifdef __cplusplus |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14254
diff
changeset
|
32 | extern "C" { |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14254
diff
changeset
|
33 | #endif |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14254
diff
changeset
|
34 | |
| 15884 | 35 | typedef struct _PurpleStringref PurpleStringref; |
| 7763 | 36 | |
| 37 | /** | |
| 38 | * Creates an immutable reference-counted string object. The newly | |
| 39 | * created object will have a reference count of 1. | |
| 40 | * | |
| 41 | * @param value This will be the value of the string; it will be | |
| 42 | * duplicated. | |
| 43 | * | |
| 7767 | 44 | * @return A newly allocated string reference object with a refcount |
| 45 | * of 1. | |
| 7763 | 46 | */ |
| 15884 | 47 | PurpleStringref *purple_stringref_new(const char *value); |
| 7763 | 48 | |
| 49 | /** | |
| 7786 | 50 | * Creates an immutable reference-counted string object. The newly |
| 51 | * created object will have a reference count of zero, and if it is | |
| 52 | * not referenced before the next iteration of the mainloop it will | |
| 53 | * be freed at that time. | |
| 54 | * | |
| 55 | * @param value This will be the value of the string; it will be | |
| 56 | * duplicated. | |
| 57 | * | |
| 58 | * @return A newly allocated string reference object with a refcount | |
| 59 | * of zero. | |
| 60 | */ | |
| 15884 | 61 | PurpleStringref *purple_stringref_new_noref(const char *value); |
| 7786 | 62 | |
| 63 | /** | |
| 7767 | 64 | * Creates an immutable reference-counted string object from a printf |
| 65 | * format specification and arguments. The created object will have a | |
| 66 | * reference count of 1. | |
| 67 | * | |
| 68 | * @param format A printf-style format specification. | |
| 69 | * | |
| 70 | * @return A newly allocated string reference object with a refcount | |
| 71 | * of 1. | |
| 72 | */ | |
| 15884 | 73 | PurpleStringref *purple_stringref_printf(const char *format, ...); |
| 7767 | 74 | |
| 75 | /** | |
| 7763 | 76 | * Increase the reference count of the given stringref. |
| 77 | * | |
| 78 | * @param stringref String to be referenced. | |
| 79 | * | |
| 80 | * @return A pointer to the referenced string. | |
| 81 | */ | |
| 15884 | 82 | PurpleStringref *purple_stringref_ref(PurpleStringref *stringref); |
| 7763 | 83 | |
| 84 | /** | |
| 85 | * Decrease the reference count of the given stringref. If this | |
| 86 | * reference count reaches zero, the stringref will be freed; thus | |
| 87 | * you MUST NOT use this string after dereferencing it. | |
| 88 | * | |
| 89 | * @param stringref String to be dereferenced. | |
| 90 | */ | |
| 15884 | 91 | void purple_stringref_unref(PurpleStringref *stringref); |
| 7763 | 92 | |
| 93 | /** | |
| 94 | * Retrieve the value of a stringref. | |
| 95 | * | |
| 96 | * @note This value should not be cached or stored in a local variable. | |
| 97 | * While there is nothing inherently incorrect about doing so, it | |
| 98 | * is easy to forget that the cached value is in fact a | |
| 99 | * reference-counted object and accidentally use it after | |
| 100 | * dereferencing. This is more problematic for a reference- | |
| 101 | * counted object than a heap-allocated object, as it may seem to | |
| 102 | * be valid or invalid nondeterministically based on how many | |
| 103 | * other references to it exist. | |
| 104 | * | |
| 105 | * @param stringref String reference from which to retrieve the value. | |
| 106 | * | |
| 107 | * @return The contents of the string reference. | |
| 108 | */ | |
| 15884 | 109 | const char *purple_stringref_value(const PurpleStringref *stringref); |
| 7763 | 110 | |
| 7786 | 111 | /** |
| 112 | * Compare two stringrefs for string equality. This returns the same | |
| 113 | * value as strcmp would, where <0 indicates that s1 is "less than" s2 | |
| 114 | * in the ASCII lexicography, 0 indicates equality, etc. | |
| 115 | * | |
| 116 | * @param s1 The reference string. | |
| 117 | * | |
| 118 | * @param s2 The string to compare against the reference. | |
| 119 | * | |
| 120 | * @return An ordering indication on s1 and s2. | |
| 121 | */ | |
| 15884 | 122 | int purple_stringref_cmp(const PurpleStringref *s1, const PurpleStringref *s2); |
| 7786 | 123 | |
| 124 | /** | |
| 125 | * Find the length of the string inside a stringref. | |
| 126 | * | |
| 127 | * @param stringref The string in whose length we are interested. | |
| 128 | * | |
| 129 | * @return The length of the string in stringref | |
| 130 | */ | |
| 15884 | 131 | size_t purple_stringref_len(const PurpleStringref *stringref); |
| 7786 | 132 | |
|
14988
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14254
diff
changeset
|
133 | #ifdef __cplusplus |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14254
diff
changeset
|
134 | } |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14254
diff
changeset
|
135 | #endif |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14254
diff
changeset
|
136 | |
| 15884 | 137 | #endif /* _PURPLE_STRINGREF_H_ */ |