1 | // |
---|
2 | // Case-based reasoner |
---|
3 | // |
---|
4 | // |
---|
5 | // TODO REDO THIS FILE |
---|
6 | |
---|
7 | #ifndef CBR_H |
---|
8 | #define CBR_H |
---|
9 | |
---|
10 | #include "sqlite3.h" |
---|
11 | //#define CBR_LEN_FILENAME 64 |
---|
12 | |
---|
13 | #define DATABASENAME "cactus_cbr" |
---|
14 | |
---|
15 | typedef struct cbr_s * cbr; |
---|
16 | |
---|
17 | const char * ops_str[] = { |
---|
18 | "==", "!=", ">", ">=", "<", "<="}; |
---|
19 | |
---|
20 | // create the CBR |
---|
21 | cbr cbr_create(char * _filename, char * _tablename, char * _cols[], unsigned int _len); |
---|
22 | |
---|
23 | // free the CBR |
---|
24 | void cbr_free(cbr _cbr); |
---|
25 | |
---|
26 | // print databse/table |
---|
27 | void cbr_print(cbr _cbr); |
---|
28 | |
---|
29 | #define EQ 0 // equals |
---|
30 | #define NE 1 // not equals |
---|
31 | #define GT 2 // greater than |
---|
32 | #define GE 3 // greater than or equal to |
---|
33 | #define LT 4 // less than |
---|
34 | #define LE 5 // less than or equal to |
---|
35 | int cbr_search(cbr _cbr, char *_names[], int * _ops, float *_vals, unsigned int _n, float *_retvals); |
---|
36 | |
---|
37 | int cbr_add_row(cbr _cbr, char *_cols[], float *_vals, unsigned int _len); |
---|
38 | |
---|
39 | struct cbr_s { |
---|
40 | char filename[64]; |
---|
41 | char tablename[64]; |
---|
42 | char command[2048]; |
---|
43 | sqlite3 *db; |
---|
44 | unsigned int num_columns; |
---|
45 | }; |
---|
46 | |
---|
47 | |
---|
48 | // open a database or create a database if it does not exist |
---|
49 | int OpenDatabase(cbr _cbr); |
---|
50 | |
---|
51 | |
---|
52 | // simple callback function, display result |
---|
53 | int callback(void *notUsed, int argc, char **argv, char **azColName); |
---|
54 | |
---|
55 | |
---|
56 | // execute command |
---|
57 | int ExecuteCommand(cbr _cbr); |
---|
58 | |
---|
59 | |
---|
60 | // execute search command |
---|
61 | int ExecuteSearchCommand(cbr _cbr, float *_retvals); |
---|
62 | |
---|
63 | |
---|
64 | // create database |
---|
65 | cbr cbr_create(char * _filename, char * _tablename, char * _cols[], unsigned int _len); |
---|
66 | |
---|
67 | |
---|
68 | // free space |
---|
69 | void cbr_free(cbr _cbr); |
---|
70 | |
---|
71 | |
---|
72 | // print |
---|
73 | void cbr_print(cbr _cbr); |
---|
74 | |
---|
75 | |
---|
76 | // cbr search |
---|
77 | int cbr_search( |
---|
78 | cbr _cbr, |
---|
79 | char *_names[], |
---|
80 | int * _ops, |
---|
81 | float *_vals, |
---|
82 | unsigned int _n, |
---|
83 | float *_retvals); |
---|
84 | |
---|
85 | |
---|
86 | // update a row |
---|
87 | int cbr_update(cbr _cbr, char *_where[], char*_set[], float *_wherevals, float *_setvals, |
---|
88 | unsigned int _wherelen, unsigned int _setlen); |
---|
89 | |
---|
90 | // cbr add a row |
---|
91 | int cbr_add_row(cbr _cbr, char *_cols[], float *_vals, unsigned int _len); |
---|
92 | |
---|
93 | #endif |
---|