| | 588 | |
| | 589 | /** |
| | 590 | * @defgroup nodes Nodes |
| | 591 | * @{ |
| | 592 | */ |
| | 593 | |
| | 594 | #define YAML_NULL_TAG "tag:yaml.org,2002:null" |
| | 595 | #define YAML_BOOL_TAG "tag:yaml.org,2002:bool" |
| | 596 | #define YAML_STR_TAG "tag:yaml.org,2002:str" |
| | 597 | #define YAML_INT_TAG "tag:yaml.org,2002:int" |
| | 598 | #define YAML_FLOAT_TAG "tag:yaml.org,2002:float" |
| | 599 | #define YAML_TIMESTAMP_TAG "tag:yaml.org,2002:timestamp" |
| | 600 | |
| | 601 | #define YAML_SEQ_TAG "tag:yaml.org,2002:seq" |
| | 602 | #define YAML_MAP_TAG "tag:yaml.org,2002:map" |
| | 603 | |
| | 604 | #define YAML_DEFAULT_SCALAR_TAG YAML_STR_TAG |
| | 605 | #define YAML_DEFAULT_SEQUENCE_TAG YAML_SEQ_TAG |
| | 606 | #define YAML_DEFAULT_MAPPING_STYLE YAML_MAP_TAG |
| | 607 | |
| | 608 | /** Node types. */ |
| | 609 | typedef enum { |
| | 610 | YAML_NO_NODE, |
| | 611 | |
| | 612 | YAML_SCALAR_NODE, |
| | 613 | YAML_SEQUENCE_NODE, |
| | 614 | YAML_MAPPING_NODE |
| | 615 | } yaml_node_type_t; |
| | 616 | |
| | 617 | #if 0 |
| | 618 | |
| | 619 | typedef struct _yaml_node_t yaml_node_item_t; |
| | 620 | |
| | 621 | typedef struct { |
| | 622 | yaml_node_item_t key; |
| | 623 | yaml_node_item_t value; |
| | 624 | } yaml_node_pair_t; |
| | 625 | |
| | 626 | /** The node structure. */ |
| | 627 | typedef struct _yaml_node_t { |
| | 628 | |
| | 629 | /** The node type. */ |
| | 630 | yaml_node_type_t type; |
| | 631 | |
| | 632 | /* The reference counter. */ |
| | 633 | int references; |
| | 634 | |
| | 635 | /** The node data. */ |
| | 636 | union { |
| | 637 | |
| | 638 | /** The scalar parameters (for @c YAML_SCALAR_NODE). */ |
| | 639 | struct { |
| | 640 | /** The tag. */ |
| | 641 | yaml_char_t *tag; |
| | 642 | /** The scalar value. */ |
| | 643 | yaml_char_t *value; |
| | 644 | /** The length of the scalar value. */ |
| | 645 | size_t length; |
| | 646 | /** The scalar style. */ |
| | 647 | yaml_scalar_style_t style; |
| | 648 | } scalar; |
| | 649 | |
| | 650 | /** The sequence parameters (for @c YAML_SEQUENCE_NODE). */ |
| | 651 | struct { |
| | 652 | /** The tag. */ |
| | 653 | yaml_char_t *tag; |
| | 654 | /** The stack of sequence items. */ |
| | 655 | struct { |
| | 656 | /** The beginning of the stack. */ |
| | 657 | struct yaml_node_item_t *start; |
| | 658 | /** The end of the stack. */ |
| | 659 | struct yaml_node_item_t *end; |
| | 660 | /** The top of the stack. */ |
| | 661 | struct yaml_node_item_t *top; |
| | 662 | } items; |
| | 663 | /** The sequence style. */ |
| | 664 | yaml_sequence_style_t style; |
| | 665 | } sequence; |
| | 666 | |
| | 667 | /** The mapping parameters (for @c YAML_MAPPING_NODE). */ |
| | 668 | struct { |
| | 669 | /** The tag. */ |
| | 670 | yaml_char_t *tag; |
| | 671 | /** The stack of mapping pairs. */ |
| | 672 | struct { |
| | 673 | /** The beginning of the stack. */ |
| | 674 | struct yaml_node_pair_t *start; |
| | 675 | /** The end of the stack. */ |
| | 676 | struct yaml_node_pair_t *end; |
| | 677 | /** The top of the stack. */ |
| | 678 | struct yaml_node_pair_t *top; |
| | 679 | } pairs; |
| | 680 | /** The mapping style. */ |
| | 681 | yaml_mapping_style_t style; |
| | 682 | } mapping; |
| | 683 | |
| | 684 | } data; |
| | 685 | |
| | 686 | /** The beginning of the node. */ |
| | 687 | yaml_mark_t start_mark; |
| | 688 | /** The end of the node. */ |
| | 689 | yaml_mark_t end_mark; |
| | 690 | |
| | 691 | } yaml_node_t; |
| | 692 | |
| | 693 | /** |
| | 694 | * Create a SCALAR node. |
| | 695 | * |
| | 696 | * The @a style argument may be ignored by the emitter. |
| | 697 | * |
| | 698 | * @param[out] node An empty node object. |
| | 699 | * @param[in] tag The scalar tag. |
| | 700 | * @param[in] value The scalar value. |
| | 701 | * @param[in] length The length of the scalar value. |
| | 702 | * @param[in] style The scalar style. |
| | 703 | * |
| | 704 | * @returns @c 1 if the function succeeded, @c 0 on error. |
| | 705 | */ |
| | 706 | |
| | 707 | YAML_DECLARE(int) |
| | 708 | yaml_scalar_node_initialize(yaml_node_t *node, |
| | 709 | yaml_char_t *tag, yaml_char_t *value, int length, |
| | 710 | yaml_scalar_style_t style); |
| | 711 | |
| | 712 | /** |
| | 713 | * Create a SEQUENCE node. |
| | 714 | * |
| | 715 | * The @a style argument may be ignored by the emitter. |
| | 716 | * |
| | 717 | * @param[out] node An empty node object. |
| | 718 | * @param[in] tag The sequence tag. |
| | 719 | * @param[in] style The sequence style. |
| | 720 | * |
| | 721 | * @returns @c 1 if the function succeeded, @c 0 on error. |
| | 722 | */ |
| | 723 | |
| | 724 | YAML_DECLARE(int) |
| | 725 | yaml_sequence_node_initialize(yaml_node_t *node, |
| | 726 | yaml_char_t *tag, yaml_sequence_style_t style); |
| | 727 | |
| | 728 | /** |
| | 729 | * Add an item to a SEQUENCE node |
| | 730 | * |
| | 731 | * @param[out] node A sequence node. |
| | 732 | * @param[in] item An item node. |
| | 733 | * |
| | 734 | * @returns @c 1 if the function succeeded, @c 0 on error. |
| | 735 | */ |
| | 736 | |
| | 737 | YAML_DECLARE(int) |
| | 738 | yaml_sequence_node_add_item(yaml_node_t *node, yaml_node_t *item) |
| | 739 | |
| | 740 | /** |
| | 741 | * Create a SCALAR node and add it to a SEQUENCE node. |
| | 742 | * |
| | 743 | * @param[out] node A sequence node. |
| | 744 | * @param[in] tag The scalar tag. |
| | 745 | * @param[in] value The scalar value. |
| | 746 | * @param[in] length The length of the scalar value. |
| | 747 | * @param[in] style The scalar style. |
| | 748 | * |
| | 749 | * @returns @c 1 if the function succeeded, @c 0 on error. |
| | 750 | */ |
| | 751 | |
| | 752 | YAML_DECLARE(int) |
| | 753 | yaml_sequence_node_add_scalar_item(yaml_node_t *node, |
| | 754 | yaml_char_t *tag, yaml_char_t *value, int length, |
| | 755 | yaml_scalar_style_t style); |
| | 756 | |
| | 757 | /** |
| | 758 | * Get the number of subnodes of a SEQUENCE node. |
| | 759 | * |
| | 760 | * @param[in] node A sequence node. |
| | 761 | * |
| | 762 | * @returns the number of subnodes. |
| | 763 | */ |
| | 764 | |
| | 765 | YAML_DECLARE(size_t) |
| | 766 | yaml_sequence_node_get_length(yaml_node_t *node); |
| | 767 | |
| | 768 | /** |
| | 769 | * Get a subnode of a SEQUENCE node. |
| | 770 | * |
| | 771 | * @param[in] node A sequence node. |
| | 772 | * @param[in] index The index of a subnode. |
| | 773 | * @param[out] item A subnode. |
| | 774 | */ |
| | 775 | |
| | 776 | YAML_DECLARE(void) |
| | 777 | yaml_sequence_node_get_item(yaml_node_t *node, size_t index, |
| | 778 | yaml_node_t *item); |
| | 779 | |
| | 780 | /** |
| | 781 | * Create a MAPPING node. |
| | 782 | * |
| | 783 | * The @a style argument may be ignored by the emitter. |
| | 784 | * |
| | 785 | * @param[out] node An empty node object. |
| | 786 | * @param[in] tag The mapping tag. |
| | 787 | * @param[in] style The mapping style. |
| | 788 | * |
| | 789 | * @returns @c 1 if the function succeeded, @c 0 on error. |
| | 790 | */ |
| | 791 | |
| | 792 | YAML_DECLARE(int) |
| | 793 | yaml_mapping_node_initialize(yaml_node_t *node, |
| | 794 | yaml_char_t *tag, yaml_mapping_style_t style); |
| | 795 | |
| | 796 | /** |
| | 797 | * Add a key/value pair of nodes to a MAPPING node. |
| | 798 | * |
| | 799 | * @param[out] node A mapping node. |
| | 800 | * @param[in] key A key node. |
| | 801 | * @param[in] value A value node. |
| | 802 | * |
| | 803 | * @returns @c 1 if the function succeeded, @c 0 on error. |
| | 804 | */ |
| | 805 | |
| | 806 | YAML_DECLARE(int) |
| | 807 | yaml_mapping_node_add_pair(yaml_node_t *node, |
| | 808 | yaml_node_t *key, yaml_node_t *value) |
| | 809 | |
| | 810 | /** |
| | 811 | * Create a scalar key and add the key/value pair to a MAPPING node. |
| | 812 | * |
| | 813 | * @param[out] node A mapping node. |
| | 814 | * @param[in] key_tag The key node tag. |
| | 815 | * @param[in] key_value The key node value. |
| | 816 | * @param[in] key_length The length of the key node value. |
| | 817 | * @param[in] key_style The key node style. |
| | 818 | * @param[in] value A value node. |
| | 819 | * |
| | 820 | * @returns @c 1 if the function succeeded, @c 0 on error. |
| | 821 | */ |
| | 822 | |
| | 823 | YAML_DECLARE(int) |
| | 824 | yaml_sequence_node_add_scalar_key_pair(yaml_node_t *node, |
| | 825 | yaml_char_t *key_tag, yaml_char_t *key_value, int key_length, |
| | 826 | yaml_scalar_style_t key_style, |
| | 827 | yaml_node_t *value); |
| | 828 | |
| | 829 | /** |
| | 830 | * Create a scalar key/value nodes and add the pair to a MAPPING node. |
| | 831 | * |
| | 832 | * @param[out] node A mapping node. |
| | 833 | * @param[in] key_tag The key node tag. |
| | 834 | * @param[in] key_value The key node value. |
| | 835 | * @param[in] key_length The length of the key node value. |
| | 836 | * @param[in] key_style The key node style. |
| | 837 | * @param[in] value_tag The value node tag. |
| | 838 | * @param[in] value_value The value node value. |
| | 839 | * @param[in] value_length The length of the value node value. |
| | 840 | * @param[in] value_style The value node style. |
| | 841 | * |
| | 842 | * @returns @c 1 if the function succeeded, @c 0 on error. |
| | 843 | */ |
| | 844 | |
| | 845 | YAML_DECLARE(int) |
| | 846 | yaml_sequence_node_add_scalar_pair(yaml_node_t *node, |
| | 847 | yaml_char_t *key_tag, yaml_char_t *key_value, int key_length, |
| | 848 | yaml_scalar_style_t key_style, |
| | 849 | yaml_char_t *value_tag, yaml_char_t *value_value, int value_length, |
| | 850 | yaml_scalar_style_t value_style); |
| | 851 | |
| | 852 | /** |
| | 853 | * Get the number of subnode pairs of a MAPPING node. |
| | 854 | * |
| | 855 | * @param[in] node A mapping node. |
| | 856 | * |
| | 857 | * @returns the number of pairs. |
| | 858 | */ |
| | 859 | |
| | 860 | YAML_DECLARE(size_t) |
| | 861 | yaml_mapping_node_get_length(yaml_node_t *node); |
| | 862 | |
| | 863 | /** |
| | 864 | * Get a subnode of a SEQUENCE node. |
| | 865 | * |
| | 866 | * @param[in] node A sequence node. |
| | 867 | * @param[in] index The index of a subnode. |
| | 868 | * @param[out] key The key subnode. |
| | 869 | * @param[out] value The value subnode. |
| | 870 | */ |
| | 871 | |
| | 872 | YAML_DECLARE(void) |
| | 873 | yaml_mapping_node_get_pair(yaml_node_t *node, size_t index, |
| | 874 | yaml_node_t *key, yaml_node_t *value); |
| | 875 | |
| | 876 | /** |
| | 877 | * Delete a node and its subnodes. |
| | 878 | * |
| | 879 | * @param[out] node A node object. |
| | 880 | */ |
| | 881 | |
| | 882 | YAML_DECLARE(void) |
| | 883 | yaml_node_delete(yaml_node_t *node); |
| | 884 | |
| | 885 | #endif |