[Vala] [Genie] static dict

struct rgba
  r : float
  g : float
  b : float
  a : float

class Color : Object
  _map : static dict of string,rgba = new dict of string,rgba
  _map["white"] = {1.0f, 1.0f, 1.0f, 1.0f}
  _map["red"] = {1.0f, 0.0f, 0.0f, 1.0f}
  _map["green"] = {0.0f, 1.0f, 0.0f, 1.0f}
  _map["blue"] = {0.0f, 0.0f, 1.0f, 1.0f}
  _map["black"] = {0.0f, 0.0f, 0.0f, 1.0f}

This code doesn't work.

We need a lookup table for a Color constructor which accepts the color name
as it's argument and sets the color according to the static dict in the
class.  As the dict is part of the class and never changes, it'd be wasteful
to create a copy of the dict in each instance of the class (especially as
there may be a lot of colors in memory at once).

Does anyone know how to implement static lists/dicts/etc in Genie?

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]