About all my projects
Gnome::Glib::Quark

Gnome::Glib::Quark

Quark - a 2-way association between a string and a unique integer identifier

Description

Quarks are associations between strings and integer identifiers or a GQuark. Given either the string or the GQuark identifier it is possible to retrieve the other.

Quarks are used for example to specify error domains, see also Gnome::Glib::Error.

To create a new quark from a string, use from-string().

To find the string corresponding to a given GQuark, use to-string().

To find the GQuark corresponding to a given string, use try-string().

Synopsis

Declaration

unit class Gnome::Glib::Quark;

Example

use Test;
use Gnome::Glib::Quark:api<1>;

my Gnome::Glib::Quark $quark .= new;
my UInt $q = $quark.try-string('my string'); # 0

$q = $quark.from-string('my 2nd string');
$quark.to-string($q);                        # 'my 2nd string'

new

default, no options

Create a new quark object.

multi method new ( )

from-static-string

Gets the Gnome::Gio::Quark identifying the given (static) string. If the string does not currently have an associated Gnome::Gio::Quark, a new Gnome::Gio::Quark is created, linked to the given string.

Note that this function is identical to from_string() except that if a new Gnome::Gio::Quark is created the string itself is used rather than a copy. This saves memory, but can only be used if the string will continue to exist until the program terminates. It can be used with statically allocated strings in the main program, but not with statically allocated memory in dynamically loaded modules, if you expect to ever unload the module again (e.g. do not use this function in GTK+ theme engines).

This function must not be used before library constructors have finished running. In particular, this means it cannot be used to initialize global variables in C++.

Returns: the Gnome::Gio::Quark identifying the string, or 0 if string is undefined

method from-static-string ( Str $string --> UInt )
  • $string; a string

from-string

Gets the GQuark identifying the given string. If the string does not currently have an associated GQuark, a new GQuark is created, using a copy of the string.

Returns: the GQuark identifying the string, or 0 if $string is undefined

method from-string ( Str $string --> GQuark )
  • Str $string: a string

intern-static-string

Returns a canonical representation for string. Interned strings can be compared for equality by comparing the pointers, instead of using strcmp(). g_intern_static_string() does not copy the string, therefore string must not be freed or modified.

This function must not be used before library constructors have finished running. In particular, this means it cannot be used to initialize global variables in C++.

Returns: a canonical representation for the string

method intern-static-string ( Str $string --> Str )
  • $string; a static string

intern-string

Returns a canonical representation for string. Interned strings can be compared for equality by comparing the pointers, instead of using strcmp().

This function must not be used before library constructors have finished running. In particular, this means it cannot be used to initialize global variables in C++.

Returns: a canonical representation for the string

method intern-string ( Str $string --> Str )
  • $string; a string

to-string

Gets the string associated with the given GQuark.

method to-string ( GQuark $quark --> Str  )

try-string

Gets the GQuark associated with the given string, or 0 if string is undefined or it has no associated GQuark.

If you want the GQuark to be created if it doesn't already exist, use g_quark_from_string() or g_quark_from_static_string().

Returns: the GQuark associated with the string, or 0 if $string is undefined or there is no GQuark associated with it.

method try-string ( Str $string --> GQuark )
  • Str $string: a string