greenhouse
a creative coding toolkit for spatial interfaces

Dictionary

An associative list of key/value pairs. More commonly called a map.

A Dictionary can contain Greenhouse objects, g-speak objects or basic data types.

  • Dictionary ()
  • Put ()
  • Get ()
  • KeyFromVal ()
  • IndexForKey ()
  • Count ()
  • KeyIsPresent ()
  • DictionaryFromIngest ()
  • AsStr ()

Example

#define WORKER
#include "Greenhouse.h"

void Setup ()
{ Dictionary <Str, Image *> d;
  Image *one = new Image ("images/1.jpg");
  d . Put ("one", one);
  d . Put ("two",   new Image ("images/2.jpg"));
  d . Put ("three", new Image ("images/3.jpg"));

  Image *two = d . Get ("two");
  INFORM ("key for two is: " + d . KeyFromVal (two));

  if (d . KeyIsPresent ("three"))
    { int64 ind = d . IndexForKey ("three");
      INFORM ("image three is located at index: " + ToStr (ind));
    }

  Protein p = Protein (Slaw::List ("descrip1", "descrip2"),
                       Slaw::Map ("a_map",
                                  Slaw::Map ("one", 1,
                                             "two", 2,
                                             "three", 3)));
  Dictionary <Str, int64> m;
  m = DictionaryFromIngest <Str,int64> (p, "a_map");

  INFORM (m . AsStr ());  // {'one': 1, 'two': 2, 'three': 3}
  INFORM ("How many things? " + ToStr (m . Count ()));  //  3
}