#pragma once #ifndef PAWS_DOM_HEADER #define PAWS_DOM_HEADER #include "stretchy_buffer.h" #include "cow.h" typedef struct pdom_attribute_map_t pdom_attribute_map_t; struct pdom_attribute_map_t { usize num_items; struct pdom_attribute_bucket_t { //TODO(Paw): change this to a linked list usize hash; pcow_t key; pcow_t value; } *buckets[32]; }; typedef struct pdom_attribute_iter_t pdom_attribute_iter_t; struct pdom_attribute_iter_t { enum { PDOM_ATTR_ITER_NONE, PDOM_ATTR_ITER_SOME } kind; usize bucket_index; usize index; pcow_t key; pcow_t value; }; typedef struct pdom_node_t pdom_node_t; struct pdom_node_t { enum { PDOM_NODE_TEXT, PDOM_NODE_ELEMENT } kind; pdom_node_t *stretchy children; union { pcow_t text; struct { pcow_t tag_name; pdom_attribute_map_t attr; } element; }; }; pdom_attribute_map_t pdom_attribute_map(void); void pd_attr_free(pdom_attribute_map_t *); void pd_attr_put(pdom_attribute_map_t [static const 1], pcow_t key, pcow_t value); pcow_t pd_attr_get(const pdom_attribute_map_t [static const 1], pcow_t key); pdom_attribute_iter_t pd_attr_iter(const pdom_attribute_map_t [static const 1]); bool pd_attr_iter_next(const pdom_attribute_map_t [static const 1], pdom_attribute_iter_t [static const 1]); pdom_node_t pdom_text_node(pcow_t); pdom_node_t pdom_element_node(pcow_t, pdom_attribute_map_t, pdom_node_t *stretchy children); void pd_node_free(pdom_node_t *); void pdom_debug_print_node(pdom_node_t *); #endif // PAWS_DOM_HEADER