57 | | |
58 | | |
59 | | /*! \brief Case-Based Reasoner class declaration. |
60 | | * |
61 | | * The CBR class is designed to used as either as-is, or as a parent class. All |
62 | | * functions are declared virtual, and internal members are 'protected' rather |
63 | | * than private. If you require functionality in a CBR not specifically provided |
64 | | * by this class, include this header in your source file, create a new class |
65 | | * that derives from CBR, and implement your desired functionality over the |
66 | | * original virtual functions as necessary. |
67 | | */ |
68 | | class CBR |
69 | | { |
70 | | public: |
71 | | /*! \brief Constructors for the CBR class. |
72 | | * |
73 | | * Note that the default constructor |
74 | | * must be defined inline here so that super-calls from child classes |
75 | | * don't fail (i.e. we cannot rely on the compiler-provided constructor. */ |
76 | | CBR(){}; |
77 | | CBR(string _filename, string _tablename, string _cols[], uint32_t _len); |
78 | | CBR(string _filename, string _tablename, string _cols[], \ |
79 | | string _primcols[], uint32_t _len, uint32_t _primlen); |
80 | | |
81 | | /*! \brief Destructors for the CBR class. |
82 | | * |
83 | | * Destructor for the CBR class. Note that this destructor will be |
84 | | * called automatically by any derived classes, and so child classes |
85 | | * should not repeat the freeing actions performed in this function. */ |
86 | | virtual ~CBR(); |
87 | | |
88 | | /*! \brief Open/Create a sqlite database for the CBR. |
89 | | * |
90 | | * This function opens the CROSS database, or if it has not been |
91 | | * created yet, creates it. */ |
92 | | virtual int32_t OpenDatabase(); |
93 | | |
94 | | /*! \brief Execute a sqlite command. |
95 | | * |
96 | | * Construct and execute a sqlite3 command and pass the return code back. */ |
97 | | virtual int32_t ExecuteCommand(); |
98 | | |
99 | | /*! \brief Search the sqlite3 database. |
100 | | * |
101 | | * Execute a sqlite3 search command and store the results in the passed |
102 | | * retvals argument. */ |
103 | | virtual int32_t ExecuteSearchCommand(float *_retvals); |
104 | | |
105 | | /*! \brief Print the CROSS sqlite database. */ |
106 | | virtual void Print(); |
107 | | |
108 | | /*! \brief Search the CBR database. |
109 | | * |
110 | | * Search the CROSS database for specific fields and store the results |
111 | | * in the passed retvals argument. */ |
112 | | virtual int32_t Search(string _names[], int32_t *_ops, float *_vals, \ |
113 | | uint32_t _n, float *_retvals); |
114 | | virtual int32_t SearchSum(string _name, float *_retvals); |
115 | | virtual int32_t SearchRand(string _names[], int32_t *_ops, float *_vals, uint32_t _n, \ |
116 | | float *_retvals); |
117 | | |
118 | | /*! \brief Update an entry in the CBR database. */ |
119 | | virtual int32_t Update(string _where[], string _set[], float *_wherevals, \ |
120 | | float *_setvals, uint32_t _wherelen, uint32_t _setlen); |
121 | | |
122 | | /*! \brief Add a row to the CROSS sqlite3 database. */ |
123 | | virtual int32_t AddRow(string _cols[], float *_vals, uint32_t _len); |
124 | | |
125 | | protected: |
126 | | string filename; |
127 | | string tablename; |
128 | | string command; |
129 | | |
130 | | sqlite3 *db; |
131 | | uint32_t numColumns; |
132 | | }; |