home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / include / libpurple / stringref.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-04  |  4.3 KB  |  136 lines

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