src/cx/tree.h

changeset 895
ea1ac0e8225c
parent 894
89cd8dfdc3c2
child 896
7e09c76390c3
equal deleted inserted replaced
894:89cd8dfdc3c2 895:ea1ac0e8225c
672 */ 672 */
673 const cx_tree_class *cl; 673 const cx_tree_class *cl;
674 674
675 /** 675 /**
676 * A function to create new nodes. 676 * A function to create new nodes.
677 *
678 * Nodes MAY use #cx_tree_node_base_s as base layout, but do not need to.
677 */ 679 */
678 cx_tree_node_create_func node_create; 680 cx_tree_node_create_func node_create;
679 681
680 /** 682 /**
681 * The pointer to additional data that is passed to the create function. 683 * The pointer to additional data that is passed to the create function.
709 711
710 /** 712 /**
711 * The number of currently stored elements. 713 * The number of currently stored elements.
712 */ 714 */
713 size_t size; 715 size_t size;
716
717 /*
718 * Offset in the node struct for the parent pointer.
719 */
720 ptrdiff_t loc_parent;
721
722 /*
723 * Offset in the node struct for the children linked list.
724 */
725 ptrdiff_t loc_children;
726
727 /*
728 * Optional offset in the node struct for the pointer to the last child
729 * in the linked list (negative if there is no such pointer).
730 */
731 ptrdiff_t loc_last_child;
732
733 /*
734 * Offset in the node struct for the previous sibling pointer.
735 */
736 ptrdiff_t loc_prev;
737
738 /*
739 * Offset in the node struct for the next sibling pointer.
740 */
741 ptrdiff_t loc_next;
714 }; 742 };
743
744 /**
745 * Base structure that can be used for tree nodes in a #CxTree.
746 */
747 struct cx_tree_node_base_s {
748 /**
749 * Pointer to the parent.
750 */
751 struct cx_tree_node_base_s *parent;
752 /**
753 * Pointer to the first child.
754 */
755 struct cx_tree_node_base_s *children;
756 /**
757 * Pointer to the last child.
758 */
759 struct cx_tree_node_base_s *last_child;
760 /**
761 * Pointer to the previous sibling.
762 */
763 struct cx_tree_node_base_s *prev;
764 /**
765 * Pointer to the next sibling.
766 */
767 struct cx_tree_node_base_s *next;
768 };
769
770 /**
771 * Macro to roll out the #cx_tree_node_base_s structure with a custom
772 * node type.
773 */
774 #define CX_TREE_NODE_BASE(type) \
775 type *parent; \
776 type *children;\
777 type *last_child;\
778 type *prev;\
779 type *next
780
781 /**
782 * Macro for specifying the layout of a base node tree.
783 */
784 #define cx_tree_node_base_layout \
785 offsetof(struct cx_tree_node_base_s, parent),\
786 offsetof(struct cx_tree_node_base_s, children),\
787 offsetof(struct cx_tree_node_base_s, last_child),\
788 offsetof(struct cx_tree_node_base_s, prev), \
789 offsetof(struct cx_tree_node_base_s, next)
715 790
716 /** 791 /**
717 * The class definition for arbitrary trees. 792 * The class definition for arbitrary trees.
718 */ 793 */
719 struct cx_tree_class_s { 794 struct cx_tree_class_s {

mercurial