grefstring.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* grefstring.h: Reference counted strings
  2. *
  3. * Copyright 2018 Emmanuele Bassi
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #pragma once
  19. #include "gmem.h"
  20. #include "gmacros.h"
  21. G_BEGIN_DECLS
  22. GLIB_AVAILABLE_IN_2_58
  23. char * g_ref_string_new (const char *str);
  24. GLIB_AVAILABLE_IN_2_58
  25. char * g_ref_string_new_len (const char *str,
  26. gssize len);
  27. GLIB_AVAILABLE_IN_2_58
  28. char * g_ref_string_new_intern (const char *str);
  29. GLIB_AVAILABLE_IN_2_58
  30. char * g_ref_string_acquire (char *str);
  31. GLIB_AVAILABLE_IN_2_58
  32. void g_ref_string_release (char *str);
  33. GLIB_AVAILABLE_IN_2_58
  34. gsize g_ref_string_length (char *str);
  35. /**
  36. * GRefString:
  37. *
  38. * A typedef for a reference-counted string. A pointer to a #GRefString can be
  39. * treated like a standard `char*` array by all code, but can additionally have
  40. * `g_ref_string_*()` methods called on it. `g_ref_string_*()` methods cannot be
  41. * called on `char*` arrays not allocated using g_ref_string_new().
  42. *
  43. * If using #GRefString with autocleanups, g_autoptr() must be used rather than
  44. * g_autofree(), so that the reference counting metadata is also freed.
  45. *
  46. * Since: 2.58
  47. */
  48. typedef char GRefString;
  49. G_END_DECLS