PageRenderTime 8ms CodeModel.GetById 2ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/wrappers/glib/library/data_types/g_quark.e

http://github.com/tybor/Liberty
Specman e | 67 lines | 47 code | 10 blank | 10 comment | 0 complexity | 1a98bdedd23bffbbbc6120032e66f7ac MD5 | raw file
 1indexing
 2	description: "Quarks a 2-way association between a string and a unique integer identifier."
 3	copyright: "(C) 2006 Paolo Redaelli "
 4	license: "LGPL v2 or later"
 5	date: "$Date:$"
 6	revision: "$REvision:$"
 7	
 8expanded class G_QUARK
 9
10insert
11	ANY
12	GQUARK_EXTERNALS
13	
14creation
15	default_create,
16	from_string,
17	try_string
18
19feature
20	quark: NATURAL_32 
21	-- The numeric representation of the quark.
22
23	from_string (a_string: STRING) is
24			-- Retrieve the G_QUARK identifying `a_string'. If the string
25			-- does not currently have an associated G_QUARK, a new
26			-- G_Quark is created, using a copy of the string.
27		require valid_string: a_string /= Void
28		do
29			quark := g_quark_from_string (a_string.to_external)
30		ensure
31			valid: is_valid
32		end
33
34	to_string: FIXED_STRING is
35			-- The string associated with the Current G_QUARK.
36		require
37			is_valid
38		do
39			create Result.from_external (g_quark_to_string (quark))
40		ensure
41			valid_result: Result /= Void
42		end
43
44	try_string (a_string: STRING) is
45			-- Retrieves the G_QUARK associated with the given
46			-- string. `is_valid' will be false if the string has no
47			-- associated G_QUARK. If you want the G_QUARK to be created
48			-- if it doesn't already exist, use from_string
49		require valid_string: a_string /= Void
50		do
51			quark := g_quark_try_string (a_string.to_external)
52		end
53
54	is_valid: BOOLEAN is
55			-- Is Current a valid G_QUARK, linked to a string?
56		do
57			Result := (quark /= 0.to_natural_32)
58		end
59
60	set_quark (a_quark: like quark) is
61		do
62			quark := a_quark
63		ensure
64			quark = a_quark
65		end
66
67end