BoolStuff 0.1
|
00001 /* $Id: c-api.h,v 1.16 2007/08/26 18:45:26 sarrazip Exp $ 00002 c-api.h - C API function prototypes 00003 00004 boolstuff - Disjunctive Normal Form boolean expression library 00005 Copyright (C) 2002-2005 Pierre Sarrazin <http://sarrazip.com/> 00006 00007 This program is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU General Public License 00009 as published by the Free Software Foundation; either version 2 00010 of the License, or (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00020 02111-1307, USA. 00021 */ 00022 00023 #ifndef _H_c_api 00024 #define _H_c_api 00025 00026 /* 00027 NOTES: 00028 00029 This C API wraps the C++ API for BoolExpr<string>. 00030 It thus assumes that the "value" stored in a tree node is a 00031 character string. 00032 00033 For more details on the meaning of the functions defined in this file, 00034 see the equivalent methods in BoolExpr.h (with T == std::string). 00035 */ 00036 00037 #ifdef __cplusplus 00038 extern "C" { 00039 #endif 00040 00041 #include <stdio.h> 00042 00043 00048 typedef void *boolexpr_t; 00049 00051 enum bool_operator_t 00052 { 00053 BOOLSTUFF_VALUE, 00054 BOOLSTUFF_AND, 00055 BOOLSTUFF_OR, 00056 BOOLSTUFF_NOT 00057 }; 00058 00060 enum bool_error_t 00061 { 00062 BOOLSTUFF_OK, 00063 BOOLSTUFF_ERR_GARBAGE_AT_END, 00064 BOOLSTUFF_ERR_RUNAWAY_PARENTHESIS, 00065 BOOLSTUFF_ERR_IDENTIFIER_EXPECTED 00066 }; 00067 00068 00075 boolexpr_t boolstuff_create_value_node(const char *value); 00076 00086 boolexpr_t boolstuff_create_operator_node( 00087 enum bool_operator_t op, 00088 boolexpr_t left, 00089 boolexpr_t right); 00090 00102 boolexpr_t boolstuff_parse( 00103 const char *expr, 00104 size_t *error_index, 00105 enum bool_error_t *error_code); 00106 00111 void boolstuff_destroy_tree(boolexpr_t root); 00112 00118 enum bool_operator_t boolstuff_get_node_type(boolexpr_t node); 00119 00126 const char *boolstuff_get_node_value(boolexpr_t node); 00127 00135 boolexpr_t boolstuff_get_left_subtree(boolexpr_t node); 00136 00143 boolexpr_t boolstuff_get_right_subtree(boolexpr_t node); 00144 00150 void boolstuff_set_node_type(boolexpr_t node, enum bool_operator_t op); 00151 00157 void boolstuff_set_left_subtree(boolexpr_t node, boolexpr_t subtree); 00158 00164 void boolstuff_set_right_subtree(boolexpr_t node, boolexpr_t subtree); 00165 00172 void boolstuff_set_node_value(boolexpr_t node, const char *value); 00173 00179 void boolstuff_print_tree(FILE *out, boolexpr_t root); 00180 00181 /* 00182 Prints a boolean expression tree in a string. 00183 @returns a character pointer that must not be modified and 00184 MUST be submitted to boolstuff_free_string() afterwards 00185 */ 00186 char *boolstuff_print_tree_to_string(boolexpr_t root); 00187 00192 void boolstuff_free_string(char *s); 00193 00199 boolexpr_t boolstuff_clone_tree(boolexpr_t root); 00200 00206 boolexpr_t boolstuff_get_disjunctive_normal_form(boolexpr_t root); 00207 00213 int boolstuff_is_disjunctive_normal_form(boolexpr_t root); 00214 00231 boolexpr_t *boolstuff_get_dnf_term_roots(boolexpr_t root, size_t *num); 00232 00237 void boolstuff_free_node_array(boolexpr_t *array); 00238 00239 /* 00240 Returns the variables that are used in the tree rooted at this node. 00241 00242 The strings in the returned arrays must not be modified. 00243 boolstuff_free_variables_sets() MUST BE CALLED AFTERWARDS on the 00244 returned pointers to free the allocated memory. 00245 00246 @param tree root of the tree of which to get the variables 00247 @param positivesArray pointer to an array of character strings 00248 representing the values of the variables 00249 that are used positively in the tree 00250 (the array is terminated by a NULL pointer) 00251 @param negativesArray pointer to an array of character strings 00252 representing the values of the variables 00253 that are used negatively in the tree 00254 (the array is terminated by a NULL pointer) 00255 */ 00256 void boolstuff_get_tree_variables(boolexpr_t tree, 00257 char ***positivesArray, 00258 char ***negativesArray); 00259 00265 void boolstuff_free_variables_sets( 00266 char **positivesArray, 00267 char **negativesArray); 00268 00269 00270 #ifdef __cplusplus 00271 } 00272 #endif 00273 00274 #endif /* _H_c_api */