Fri, 31 Jan 2014 18:22:41 +0530
Initial replacements for this branch
|
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 | |
|
32787
7072f190d6ad
Use G_BEGIN/END_DECLS in public libpurple files. This was
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20147
diff
changeset
|
32 | typedef struct _PurpleStringref PurpleStringref; |
|
14988
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14254
diff
changeset
|
33 | |
|
32787
7072f190d6ad
Use G_BEGIN/END_DECLS in public libpurple files. This was
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20147
diff
changeset
|
34 | G_BEGIN_DECLS |
| 7763 | 35 | |
| 36 | /** | |
| 37 | * Creates an immutable reference-counted string object. The newly | |
| 38 | * created object will have a reference count of 1. | |
| 39 | * | |
|
37034
9d6765962b22
Initial replacements for this branch
Ankit Vani <a@nevitus.org>
parents:
37023
diff
changeset
|
40 | * @value: This will be the value of the string; it will be |
| 7763 | 41 | * duplicated. |
| 42 | * | |
|
37034
9d6765962b22
Initial replacements for this branch
Ankit Vani <a@nevitus.org>
parents:
37023
diff
changeset
|
43 | * Returns: A newly allocated string reference object with a refcount |
| 7767 | 44 | * of 1. |
| 7763 | 45 | */ |
| 15884 | 46 | PurpleStringref *purple_stringref_new(const char *value); |
| 7763 | 47 | |
| 48 | /** | |
| 7786 | 49 | * Creates an immutable reference-counted string object. The newly |
| 50 | * created object will have a reference count of zero, and if it is | |
| 51 | * not referenced before the next iteration of the mainloop it will | |
| 52 | * be freed at that time. | |
| 53 | * | |
|
37034
9d6765962b22
Initial replacements for this branch
Ankit Vani <a@nevitus.org>
parents:
37023
diff
changeset
|
54 | * @value: This will be the value of the string; it will be |
| 7786 | 55 | * duplicated. |
| 56 | * | |
|
37034
9d6765962b22
Initial replacements for this branch
Ankit Vani <a@nevitus.org>
parents:
37023
diff
changeset
|
57 | * Returns: A newly allocated string reference object with a refcount |
| 7786 | 58 | * of zero. |
| 59 | */ | |
| 15884 | 60 | PurpleStringref *purple_stringref_new_noref(const char *value); |
| 7786 | 61 | |
| 62 | /** | |
| 7767 | 63 | * Creates an immutable reference-counted string object from a printf |
| 64 | * format specification and arguments. The created object will have a | |
| 65 | * reference count of 1. | |
| 66 | * | |
|
37034
9d6765962b22
Initial replacements for this branch
Ankit Vani <a@nevitus.org>
parents:
37023
diff
changeset
|
67 | * @format: A printf-style format specification. |
| 7767 | 68 | * |
|
37034
9d6765962b22
Initial replacements for this branch
Ankit Vani <a@nevitus.org>
parents:
37023
diff
changeset
|
69 | * Returns: A newly allocated string reference object with a refcount |
| 7767 | 70 | * of 1. |
| 71 | */ | |
| 15884 | 72 | PurpleStringref *purple_stringref_printf(const char *format, ...); |
| 7767 | 73 | |
| 74 | /** | |
| 7763 | 75 | * Increase the reference count of the given stringref. |
| 76 | * | |
|
37034
9d6765962b22
Initial replacements for this branch
Ankit Vani <a@nevitus.org>
parents:
37023
diff
changeset
|
77 | * @stringref: String to be referenced. |
| 7763 | 78 | * |
|
37034
9d6765962b22
Initial replacements for this branch
Ankit Vani <a@nevitus.org>
parents:
37023
diff
changeset
|
79 | * Returns: A pointer to the referenced string. |
| 7763 | 80 | */ |
| 15884 | 81 | PurpleStringref *purple_stringref_ref(PurpleStringref *stringref); |
| 7763 | 82 | |
| 83 | /** | |
| 84 | * Decrease the reference count of the given stringref. If this | |
| 85 | * reference count reaches zero, the stringref will be freed; thus | |
| 86 | * you MUST NOT use this string after dereferencing it. | |
| 87 | * | |
|
37034
9d6765962b22
Initial replacements for this branch
Ankit Vani <a@nevitus.org>
parents:
37023
diff
changeset
|
88 | * @stringref: String to be dereferenced. |
| 7763 | 89 | */ |
| 15884 | 90 | void purple_stringref_unref(PurpleStringref *stringref); |
| 7763 | 91 | |
| 92 | /** | |
| 93 | * Retrieve the value of a stringref. | |
| 94 | * | |
|
37034
9d6765962b22
Initial replacements for this branch
Ankit Vani <a@nevitus.org>
parents:
37023
diff
changeset
|
95 | * Note: This value should not be cached or stored in a local variable. |
| 7763 | 96 | * While there is nothing inherently incorrect about doing so, it |
| 97 | * is easy to forget that the cached value is in fact a | |
| 98 | * reference-counted object and accidentally use it after | |
| 99 | * dereferencing. This is more problematic for a reference- | |
| 100 | * counted object than a heap-allocated object, as it may seem to | |
| 101 | * be valid or invalid nondeterministically based on how many | |
| 102 | * other references to it exist. | |
| 103 | * | |
|
37034
9d6765962b22
Initial replacements for this branch
Ankit Vani <a@nevitus.org>
parents:
37023
diff
changeset
|
104 | * @stringref: String reference from which to retrieve the value. |
| 7763 | 105 | * |
|
37034
9d6765962b22
Initial replacements for this branch
Ankit Vani <a@nevitus.org>
parents:
37023
diff
changeset
|
106 | * Returns: The contents of the string reference. |
| 7763 | 107 | */ |
| 15884 | 108 | const char *purple_stringref_value(const PurpleStringref *stringref); |
| 7763 | 109 | |
| 7786 | 110 | /** |
| 111 | * Compare two stringrefs for string equality. This returns the same | |
| 112 | * value as strcmp would, where <0 indicates that s1 is "less than" s2 | |
| 113 | * in the ASCII lexicography, 0 indicates equality, etc. | |
| 114 | * | |
|
37034
9d6765962b22
Initial replacements for this branch
Ankit Vani <a@nevitus.org>
parents:
37023
diff
changeset
|
115 | * @s1: The reference string. |
| 7786 | 116 | * |
|
37034
9d6765962b22
Initial replacements for this branch
Ankit Vani <a@nevitus.org>
parents:
37023
diff
changeset
|
117 | * @s2: The string to compare against the reference. |
| 7786 | 118 | * |
|
37034
9d6765962b22
Initial replacements for this branch
Ankit Vani <a@nevitus.org>
parents:
37023
diff
changeset
|
119 | * Returns: An ordering indication on s1 and s2. |
| 7786 | 120 | */ |
| 15884 | 121 | int purple_stringref_cmp(const PurpleStringref *s1, const PurpleStringref *s2); |
| 7786 | 122 | |
| 123 | /** | |
| 124 | * Find the length of the string inside a stringref. | |
| 125 | * | |
|
37034
9d6765962b22
Initial replacements for this branch
Ankit Vani <a@nevitus.org>
parents:
37023
diff
changeset
|
126 | * @stringref: The string in whose length we are interested. |
| 7786 | 127 | * |
|
37034
9d6765962b22
Initial replacements for this branch
Ankit Vani <a@nevitus.org>
parents:
37023
diff
changeset
|
128 | * Returns: The length of the string in stringref |
| 7786 | 129 | */ |
| 15884 | 130 | size_t purple_stringref_len(const PurpleStringref *stringref); |
| 7786 | 131 | |
|
32787
7072f190d6ad
Use G_BEGIN/END_DECLS in public libpurple files. This was
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20147
diff
changeset
|
132 | G_END_DECLS |
|
14988
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14254
diff
changeset
|
133 | |
| 15884 | 134 | #endif /* _PURPLE_STRINGREF_H_ */ |