cbf_tree.h

Go to the documentation of this file.
00001 
00002 #ifndef CBF_TREE_H
00003 #define CBF_TREE_H
00004 
00005 #ifdef __cplusplus
00006 
00007 extern "C" {
00008 
00009 #endif
00010 
00011 #include "cbf_context.h"
00012 
00013 
00014   /* Node types */
00015 
00016 typedef enum
00017 {
00018   CBF_UNDEFINED,        /* Undefined */
00019   CBF_LINK,             /* Link      */
00020   CBF_ROOT,             /* Root      */
00021   CBF_DATABLOCK,        /* Datablock */
00022   CBF_CATEGORY,         /* Category  */
00023   CBF_COLUMN            /* Column    */
00024 }
00025 CBF_NODETYPE;
00026 
00027 
00028   /* Node structure */
00029 
00030 typedef struct cbf_node_struct
00031 {
00032   CBF_NODETYPE type;
00033 
00034   cbf_context *context;
00035 
00036   const char *name;
00037 
00038   struct cbf_node_struct *parent;
00039 
00040   struct cbf_node_struct *link;
00041 
00042   unsigned int children;
00043 
00044   size_t child_size;
00045 
00046   struct cbf_node_struct **child;
00047 }
00048 cbf_node;
00049 
00050 
00051   /* Prototypes */
00052 
00053   /* These function will not trace a link */
00054 
00055   /* Free a node */
00056 
00057 int cbf_free_node (cbf_node *node);
00058 
00059 
00060   /* Set the number of children */
00061 
00062 int cbf_set_children (cbf_node *node, unsigned int children);
00063 
00064 
00065   /* Change a link */
00066 
00067 int cbf_set_link (cbf_node *link, cbf_node *node);
00068 
00069 
00070   /* Add a child link */
00071 
00072 int cbf_add_link (cbf_node *link, cbf_node *child);
00073 
00074 
00075   /* Set a link successively to each child link */
00076 
00077 int cbf_shift_link (cbf_node *link);
00078 
00079 
00080   /* These function will trace a link */
00081 
00082   /* Trace a link */
00083 
00084 cbf_node *cbf_get_link (const cbf_node *node);
00085 
00086 
00087   /* Find a child node */
00088 
00089 int cbf_find_child (cbf_node **child, const cbf_node *node, 
00090                     const char *name);
00091 
00092 
00093   /* Find a child node, accepting the last match  */
00094 
00095 int cbf_find_last_child (cbf_node **child, const cbf_node *node, 
00096                          const char *name);
00097 
00098 
00099   /* Find a parent node */
00100 
00101 int cbf_find_parent (cbf_node **parent, const cbf_node *node, 
00102                      CBF_NODETYPE type);
00103 
00104 
00105   /* Count the number of children */
00106 
00107 int cbf_count_children (unsigned int *children, const cbf_node *node);
00108 
00109 
00110   /* Get the index of a child */
00111 
00112 int cbf_child_index (unsigned int *index, const cbf_node *node);
00113 
00114 
00115   /* Get the specified child */
00116 
00117 int cbf_get_child (cbf_node **child, const cbf_node *node, 
00118                    unsigned int index);
00119 
00120 
00121   /* Add a child to a node */
00122 
00123 int cbf_add_child (cbf_node *node, cbf_node *child);
00124 
00125 
00126   /* Add a child to a node with duplicates allowed */
00127 
00128 int cbf_add_new_child (cbf_node *node, cbf_node *child);
00129 
00130 
00131   /* Get the name of a node */
00132 
00133 int cbf_get_name (const char **name, cbf_node *node);
00134 
00135 
00136   /* All of the following functions assume that the string arguments
00137      have been created using cbf_copy_string and that no pointers to
00138      the strings are retained by the calling functions */
00139 
00140   /* Name a node */
00141 
00142 int cbf_name_node (cbf_node *node, const char *name);
00143 
00144 
00145   /* Name a node allowing for duplicates  */
00146 
00147 int cbf_name_new_node (cbf_node *node, const char *name);
00148 
00149 
00150   /* Make a new node */
00151 
00152 int cbf_make_node (cbf_node **node, CBF_NODETYPE type, 
00153                    cbf_context *context, const char *name);
00154 
00155 
00156   /* Make a new node allowing for duplicates */
00157 
00158 int cbf_make_new_node (cbf_node **node, CBF_NODETYPE type, 
00159                        cbf_context *context, const char *name);
00160 
00161 
00162   /* Make a new child node */
00163 
00164 int cbf_make_child (cbf_node **child, cbf_node *node, 
00165                     CBF_NODETYPE type, const char *name);
00166 
00167 
00168   /* Make a new child node, with duplicates allowed */
00169 
00170 int cbf_make_new_child (cbf_node **child, cbf_node *node,
00171                         CBF_NODETYPE type, const char *name);
00172 
00173 
00174   /* Get the value of a row */
00175 
00176 int cbf_get_columnrow (const char **value, const cbf_node *column, 
00177                        unsigned int row);
00178 
00179 
00180   /* Set the value of a row */
00181 
00182 int cbf_set_columnrow (cbf_node *column, unsigned int row, 
00183                        const char *value, int free);
00184 
00185 
00186   /* Insert a value in a column */
00187 
00188 int cbf_insert_columnrow (cbf_node *column, unsigned int row, 
00189                           const char *value);
00190 
00191 
00192   /* Delete a value from a column */
00193 
00194 int cbf_delete_columnrow (cbf_node *column, unsigned int row);
00195 
00196 
00197   /* Add a value to a column */
00198 
00199 int cbf_add_columnrow (cbf_node *column, const char *value);
00200 
00201 
00202 #ifdef __cplusplus
00203 
00204 }
00205 
00206 #endif
00207 
00208 #endif /* CBF_TREE_H */
00209