/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

  1. indexing
  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. expanded class G_QUARK
  8. insert
  9. ANY
  10. GQUARK_EXTERNALS
  11. creation
  12. default_create,
  13. from_string,
  14. try_string
  15. feature
  16. quark: NATURAL_32
  17. -- The numeric representation of the quark.
  18. from_string (a_string: STRING) is
  19. -- Retrieve the G_QUARK identifying `a_string'. If the string
  20. -- does not currently have an associated G_QUARK, a new
  21. -- G_Quark is created, using a copy of the string.
  22. require valid_string: a_string /= Void
  23. do
  24. quark := g_quark_from_string (a_string.to_external)
  25. ensure
  26. valid: is_valid
  27. end
  28. to_string: FIXED_STRING is
  29. -- The string associated with the Current G_QUARK.
  30. require
  31. is_valid
  32. do
  33. create Result.from_external (g_quark_to_string (quark))
  34. ensure
  35. valid_result: Result /= Void
  36. end
  37. try_string (a_string: STRING) is
  38. -- Retrieves the G_QUARK associated with the given
  39. -- string. `is_valid' will be false if the string has no
  40. -- associated G_QUARK. If you want the G_QUARK to be created
  41. -- if it doesn't already exist, use from_string
  42. require valid_string: a_string /= Void
  43. do
  44. quark := g_quark_try_string (a_string.to_external)
  45. end
  46. is_valid: BOOLEAN is
  47. -- Is Current a valid G_QUARK, linked to a string?
  48. do
  49. Result := (quark /= 0.to_natural_32)
  50. end
  51. set_quark (a_quark: like quark) is
  52. do
  53. quark := a_quark
  54. ensure
  55. quark = a_quark
  56. end
  57. end