src/cx/tree.h

changeset 897
0936916856a2
parent 896
7e09c76390c3
child 898
9b2c12494ccf
equal deleted inserted replaced
896:7e09c76390c3 897:0936916856a2
662 * Tree class type. 662 * Tree class type.
663 */ 663 */
664 typedef struct cx_tree_class_s cx_tree_class; 664 typedef struct cx_tree_class_s cx_tree_class;
665 665
666 /** 666 /**
667 * Base structure that can be used for tree nodes in a #CxTree.
668 */
669 struct cx_tree_node_base_s {
670 /**
671 * Pointer to the parent.
672 */
673 struct cx_tree_node_base_s *parent;
674 /**
675 * Pointer to the first child.
676 */
677 struct cx_tree_node_base_s *children;
678 /**
679 * Pointer to the last child.
680 */
681 struct cx_tree_node_base_s *last_child;
682 /**
683 * Pointer to the previous sibling.
684 */
685 struct cx_tree_node_base_s *prev;
686 /**
687 * Pointer to the next sibling.
688 */
689 struct cx_tree_node_base_s *next;
690 };
691
692 /**
667 * Structure for holding the base data of a tree. 693 * Structure for holding the base data of a tree.
668 */ 694 */
669 struct cx_tree_s { 695 struct cx_tree_s {
670 /** 696 /**
671 * The tree class definition. 697 * The tree class definition.
672 */ 698 */
673 const cx_tree_class *cl; 699 const cx_tree_class *cl;
700
701 /**
702 * Allocator to allocate new nodes.
703 */
704 CxAllocator *allocator;
705
706 /**
707 * A pointer to the root node.
708 *
709 * Will be \c NULL when \c size is 0.
710 */
711 struct cx_tree_node_base_s *root;
674 712
675 /** 713 /**
676 * A function to create new nodes. 714 * A function to create new nodes.
677 * 715 *
716 * Invocations to this function will receive a pointer to this tree
717 * structure as second argument.
718 *
678 * Nodes MAY use #cx_tree_node_base_s as base layout, but do not need to. 719 * Nodes MAY use #cx_tree_node_base_s as base layout, but do not need to.
679 */ 720 */
680 cx_tree_node_create_func node_create; 721 cx_tree_node_create_func node_create;
681
682 /**
683 * The pointer to additional data that is passed to the create function.
684 */
685 void *create_data;
686 722
687 /** 723 /**
688 * An optional simple destructor for the tree nodes. 724 * An optional simple destructor for the tree nodes.
689 */ 725 */
690 cx_destructor_func simple_destructor; 726 cx_destructor_func simple_destructor;
737 773
738 /* 774 /*
739 * Offset in the node struct for the next sibling pointer. 775 * Offset in the node struct for the next sibling pointer.
740 */ 776 */
741 ptrdiff_t loc_next; 777 ptrdiff_t loc_next;
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 }; 778 };
769 779
770 /** 780 /**
771 * Macro to roll out the #cx_tree_node_base_s structure with a custom 781 * Macro to roll out the #cx_tree_node_base_s structure with a custom
772 * node type. 782 * node type.

mercurial