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