Skip to content

Latest commit

 

History

History
741 lines (297 loc) · 12.4 KB

README.md

File metadata and controls

741 lines (297 loc) · 12.4 KB

Maps - Structured Data in CMake

Maps are very versatile and are missing dearly from CMake in my opinion. Maps are references as is standard in many languages. They are signified by having properties which are adressed by keys and can take any value.

Due to the "variable variable" system (ie names of variables are string which can be generated from other variables) it is very easy to implement the map system. Under the hood a value is mapped by calling address_set(${map}.${key}).

Function List

Function Descriptions

is_map

map_append

appends a value to the end of a map entry

map_append_string

map_append_unique

map_delete

map_duplicate

map_get

map_get_special

map_has

map_keys

returns all keys for the specified map

map_new

map_remove

map_remove_item

map_set

set a value in the map

map_set_hidden

map_set_special

map_tryget

tries to get the value map[key] and returns NOTFOUND if it is not found

dfs

iterates a the graph with root nodes in ${ARGN} in depth first order expand must consider cycles

dfs_callback

emits events parsing a list of map type elements expects a callback function that takes the event type string as a first argument follwowing events are called (available context variables are listed as subelements: value

  • list_length (may be 0 or 1 which is good for a null check)
  • content_length (contains the length of the content)
  • node (contains the value) list_begin
  • list_length (number of elements the list contains)
  • content_length (accumulated length of list elements + semicolon separators)
  • node (contains all values of the lsit) list_end
  • list_length(number of elements in list)
  • node (whole list)
  • list_char_length (length of list content)
  • content_length (accumulated length of list elements + semicolon separators) list_element_begin
  • list_length(number of elements in list)
  • node (whole list)
  • list_char_length (length of list content)
  • content_length (accumulated length of list elements + semicolon separators)
  • list_element (contains current list element)
  • list_element_index (contains current index )
    list_element_end
  • list_length(number of elements in list)
  • node (whole list)
  • list_char_length (length of list content)
  • content_length (accumulated length of list elements + semicolon separators)
  • list_element (contains current list element)
  • list_element_index (contains current index ) visited_reference
  • node (contains ref to revisited map) unvisited_reference
  • node (contains ref to unvisited map) map_begin
  • node( contains ref to map)
  • map_keys (contains all keys of map)
  • map_length (contains number of keys of map) map_end
  • node( contains ref to map)
  • map_keys (contains all keys of map)
  • map_length (contains number of keys of map) map_element_begin
  • node( contains ref to map)
  • map_keys (contains all keys of map)
  • map_length (contains number of keys of map)
  • map_element_key (current key)
  • map_element_value (current value)
  • map_element_index (current index) map_element_end
  • node( contains ref to map)
  • map_keys (contains all keys of map)
  • map_length (contains number of keys of map)
  • map_element_key (current key)
  • map_element_value (current value)
  • map_element_index (current index)

list_match

matches the object list

map_all_paths

returns all possible paths for the map (currently crashing on cycles cycles) todo: implement

map_at

map_capture

map_capture_new

map_clear

removes all properties from map

map_copy_shallow

copies the values of the source map into the target map by assignment (shallow copy)

map_count

map_defaults

sets all undefined properties of map to the default value

map_ensure

ensures that the specified vars are a map parsing structured data if necessary

map_extract

map_fill

map_flatten

map_from_keyvaluelist

adds the keyvalues list to the map (if not map specified created one)

map_get_default

map_get_map

map_has_all

returns true if map has all keys specified as varargs

map_has_any

returns true if map has any of the keys specified as varargs

map_invert

returns a copy of map with key values inverted only works correctly for bijective maps

map_isempty

map_keys_append

map_keys_clear

map_keys_remove

map_keys_set

map_keys_sort

map_key_at

map_match

map_matches

returns a function which returns true of all

map_match_properties

returns true if map's properties match all properties of attrs

map_omit

returns a copy of map without the specified keys (argn)

map_omit_regex

returns a map with all properties except those matched by any of the specified regexes

map_overwrite

map_pairs

returns a list key;value;key;value;... only works if key and value are not lists (ie do not contain ;)

test

map_path_get

returns the value at the specified path (path is specified as path fragment list) e.g. map = {a:{b:{c:{d:{e:3}}}}} map_path_get(${map} a b c d e) returns 3 this function is somewhat faster than map_navigate()

map_path_set

todo implement

map_peek_back

map_peek_front

map_pick

returns a copy of map returning only the whitelisted keys

map_pick_regex

returns a map containing all properties whose keys were matched by any of the specified regexes

map_pop_back

map_pop_front

map_promote

map_property_length

map_push_back

map_push_front

map_rename

map_set_default

map_to_keyvaluelist

converts a map to a key value list

map_to_valuelist

map_unpack

map_values

returns all values of the map which are passed as ARNG

mm

map_iterator

map_iterator_break

use this macro inside of a while(true) loop it breaks when the iterator is over e.g. this prints all key values in the map while(true) map_iterator_break(myiterator) message("${myiterator.key} = ${myiterator.value}") endwhile()

map_iterator_next

map_import_properties

map_match_obj

map_clone

map_clone_deep

map_clone_shallow

map_equal

compares two maps and returns true if they are equal order of list values is important order of map keys is not important cycles are respected.

map_equal_obj

map_foreach

executes action (key, value)->void on every key value pair in map exmpl: map = {id:'1',val:'3'} map_foreach("${map}" "(k,v)-> message($k $v)") prints id;1 val;3

map_issubsetof

map_merge

creates a union from all all maps passed as ARGN and combines them in result you can merge two maps by typing map_union(${map1} ${map1} ${map2}) maps are merged in order ( the last one takes precedence)

map_union

creates a union from all all maps passed as ARGN and combines them in the first you can merge two maps by typing map_union(${map1} ${map1} ${map2}) maps are merged in order ( the last one takes precedence)