c-api.h File Reference

#include <stdio.h>

Go to the source code of this file.

Typedefs

typedef void * boolexpr_t
 Cookie type for an expression tree node.

Enumerations

enum  bool_operator_t { BOOLSTUFF_VALUE, BOOLSTUFF_AND, BOOLSTUFF_OR, BOOLSTUFF_NOT }
 Possible types of a node. More...
enum  bool_error_t { BOOLSTUFF_OK, BOOLSTUFF_ERR_GARBAGE_AT_END, BOOLSTUFF_ERR_RUNAWAY_PARENTHESIS, BOOLSTUFF_ERR_STRING_EXPECTED }
 Possible error codes returned by the parser. More...

Functions

boolexpr_t boolstuff_create_value_node (const char *value)
 Creates a node that contains a copy of the designated string as its value.
boolexpr_t boolstuff_create_operator_node (enum bool_operator_t op, boolexpr_t left, boolexpr_t right)
 Creates a node that represents a boolean operator.
boolexpr_t boolstuff_parse (const char *expr, size_t *error_index, enum bool_error_t *error_code)
 Parse a textual boolean expression and creates a binary tree.
void boolstuff_destroy_tree (boolexpr_t root)
 Destroys a tree and all its dynamically allocated nodes.
enum bool_operator_t boolstuff_get_node_type (boolexpr_t node)
 Returns of type of the node (value or operator).
const char * boolstuff_get_node_value (boolexpr_t node)
 Returns the value of node that represents a variable.
boolexpr_t boolstuff_get_left_subtree (boolexpr_t node)
 Returns the root of the left-hand subtree of a node.
boolexpr_t boolstuff_get_right_subtree (boolexpr_t node)
 Returns the root of the right-hand subtree of a node.
void boolstuff_set_node_type (boolexpr_t node, enum bool_operator_t op)
 Sets the type of a node.
void boolstuff_set_left_subtree (boolexpr_t node, boolexpr_t subtree)
 Attaches a subtree as a node's left-hand subtree.
void boolstuff_set_right_subtree (boolexpr_t node, boolexpr_t subtree)
 Attaches a subtree as this node's right-hand subtree.
void boolstuff_set_node_value (boolexpr_t node, const char *value)
 Changes the string value of a node.
void boolstuff_print_tree (FILE *out, boolexpr_t root)
 Prints a boolean expression tree in a file.
char * boolstuff_print_tree_to_string (boolexpr_t root)
void boolstuff_free_string (char *s)
 Frees the memory used by a string created by this library.
boolexpr_t boolstuff_clone_tree (boolexpr_t root)
 Creates a complete copy of a binary tree.
boolexpr_t boolstuff_get_disjunctive_normal_form (boolexpr_t root)
 Transforms a tree into the Disjunctive Normal Form.
int boolstuff_is_disjunctive_normal_form (boolexpr_t root)
 Determines if a tree is in Disjunctive Normal Form.
boolexpr_tboolstuff_get_dnf_term_roots (boolexpr_t root, size_t *num)
 Returns the terms of a tree in Disjunctive Normal Form.
void boolstuff_free_node_array (boolexpr_t *array)
 Frees an array returned by boolstuff_get_dnf_term_roots().
void boolstuff_get_tree_variables (boolexpr_t tree, char ***positivesArray, char ***negativesArray)
void boolstuff_free_variables_sets (char **positivesArray, char **negativesArray)
 Frees the arrays created by boolstuff_get_tree_variables().


Typedef Documentation

typedef void* boolexpr_t

Cookie type for an expression tree node.

The NULL value represents the absence of a node.


Enumeration Type Documentation

enum bool_error_t

Possible error codes returned by the parser.

Enumerator:
BOOLSTUFF_OK 
BOOLSTUFF_ERR_GARBAGE_AT_END 
BOOLSTUFF_ERR_RUNAWAY_PARENTHESIS 
BOOLSTUFF_ERR_STRING_EXPECTED 

enum bool_operator_t

Possible types of a node.

Enumerator:
BOOLSTUFF_VALUE 
BOOLSTUFF_AND 
BOOLSTUFF_OR 
BOOLSTUFF_NOT 


Function Documentation

boolexpr_t boolstuff_clone_tree ( boolexpr_t  root  ) 

Creates a complete copy of a binary tree.

Parameters:
root root of the tree to be cloned
Returns:
the root of the cloned tree

boolexpr_t boolstuff_create_operator_node ( enum bool_operator_t  op,
boolexpr_t  left,
boolexpr_t  right 
)

Creates a node that represents a boolean operator.

Parameters:
op type of operator
left left-hand child to attach to the created node (when creating a node of type BOOLSTUFF_NOT, pass NULL for 'left')
right right-hand child to attach to the created node
Returns:
the created node

boolexpr_t boolstuff_create_value_node ( const char *  value  ) 

Creates a node that contains a copy of the designated string as its value.

Parameters:
value string to use as the node value (if NULL, an empty string is used as the node value)
Returns:
the created node

void boolstuff_destroy_tree ( boolexpr_t  root  ) 

Destroys a tree and all its dynamically allocated nodes.

Parameters:
root root of the tree to be destroyed

void boolstuff_free_node_array ( boolexpr_t array  ) 

Frees an array returned by boolstuff_get_dnf_term_roots().

Parameters:
array array to be freed (ignored if NULL)

void boolstuff_free_string ( char *  s  ) 

Frees the memory used by a string created by this library.

Parameters:
s the address of the string to be freed

void boolstuff_free_variables_sets ( char **  positivesArray,
char **  negativesArray 
)

Frees the arrays created by boolstuff_get_tree_variables().

Parameters:
positivesArray array of positive variables values
negativesArray array of negative variables values

boolexpr_t boolstuff_get_disjunctive_normal_form ( boolexpr_t  root  ) 

Transforms a tree into the Disjunctive Normal Form.

Parameters:
root root of the tree to transform
Returns:
the new root of the tree

boolexpr_t* boolstuff_get_dnf_term_roots ( boolexpr_t  root,
size_t *  num 
)

Returns the terms of a tree in Disjunctive Normal Form.

The tree must be in DNF. The nodes of the returned trees must not be modified. boolstuff_free_node_array() MUST be called afterwards on the returned array pointer to free the allocated memory.

Parameters:
root root of the DNF tree of which to return the terms
num pointer to a size_t that receives the number of non-null pointers in the returned array (ignored if NULL)
Returns:
an array of the nodes at the root of the DNF terms (a NULL pointer is stored at the end of this array to mark its end)

boolexpr_t boolstuff_get_left_subtree ( boolexpr_t  node  ) 

Returns the root of the left-hand subtree of a node.

Parameters:
node node of which to return the left-hand subtree
Returns:
the node at the root of the left-hand subtree (will be NULL for nodes of types BOOLSTUFF_VALUE or BOOLSTUFF_NOT)

enum bool_operator_t boolstuff_get_node_type ( boolexpr_t  node  ) 

Returns of type of the node (value or operator).

Parameters:
node node of which to return the type
Returns:
the type of the node

const char* boolstuff_get_node_value ( boolexpr_t  node  ) 

Returns the value of node that represents a variable.

Parameters:
node node that must be of type BOOLSTUFF_VALUE
Returns:
a pointer to internal storage that contains the string value of the node

boolexpr_t boolstuff_get_right_subtree ( boolexpr_t  node  ) 

Returns the root of the right-hand subtree of a node.

Parameters:
node node of which to return the right-hand subtree
Returns:
the node at the root of the right-hand subtree (will be NULL for nodes of types BOOLSTUFF_VALUE)

void boolstuff_get_tree_variables ( boolexpr_t  tree,
char ***  positivesArray,
char ***  negativesArray 
)

int boolstuff_is_disjunctive_normal_form ( boolexpr_t  root  ) 

Determines if a tree is in Disjunctive Normal Form.

Parameters:
root root of the tree to examine
Returns:
1 if the tree is in DNF, 0 otherwise

boolexpr_t boolstuff_parse ( const char *  expr,
size_t *  error_index,
enum bool_error_t error_code 
)

Parse a textual boolean expression and creates a binary tree.

Parameters:
expr boolean expression to parse (must not be NULL)
error_index pointer to a size_t that will receive the index in 'expr' where the error was detected (ignored if NULL)
error_code pointer to an 'enum bool_error_t' that will receive the error code (ignored if NULL)
Returns:
the created tree, or NULL if an error occurred

void boolstuff_print_tree ( FILE *  out,
boolexpr_t  root 
)

Prints a boolean expression tree in a file.

Parameters:
out file in which to write the boolean expression
root root node of the boolean expression tree to write

char* boolstuff_print_tree_to_string ( boolexpr_t  root  ) 

void boolstuff_set_left_subtree ( boolexpr_t  node,
boolexpr_t  subtree 
)

Attaches a subtree as a node's left-hand subtree.

Parameters:
node node that becomes the parent
subtree root of the tree that becomes the left-hand subtree

void boolstuff_set_node_type ( boolexpr_t  node,
enum bool_operator_t  op 
)

Sets the type of a node.

Parameters:
node node whose type is to be set
op new type of this node

void boolstuff_set_node_value ( boolexpr_t  node,
const char *  value 
)

Changes the string value of a node.

Parameters:
node node whose value is to be changed
value string that becomes the node's new value (must not be NULL)

void boolstuff_set_right_subtree ( boolexpr_t  node,
boolexpr_t  subtree 
)

Attaches a subtree as this node's right-hand subtree.

Parameters:
node node that becomes the parent
subtree root of the tree that becomes the right-hand subtree


Generated on Wed May 9 20:04:30 2007 for BoolStuff by  doxygen 1.5.2