Show
Ignore:
Timestamp:
03/04/10 12:21:26 (14 years ago)
Author:
bhilburn
Message:

Moved the implementation for the CBR into its own file, now compiling it
into a static archive for linking into other CEs.

Files:
1 copied

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/src/cognitive_engines/CBR.cpp

    r518 r544  
    1515*/ 
    1616 
    17 /*! This header contains the declaration and a full implementation of  
    18  * the CBR class - the default CROSS case-based reasoner, which can be used as a 
    19  * backend for cognitive engines. 
    20  */ 
    21  
    22  
    23  
    24 #ifndef CBR_H 
    25 #define CBR_H 
    26  
    27 #include <cstdlib> 
    28 #include <cstring> 
    29 #include <cstdio> 
    30 #include <stdint.h> 
    31 #include <string> 
    32  
    33 #include <sqlite3.h> 
    34  
    35 #include "vtcross/common.h" 
    36 #include "vtcross/debug.h" 
    37 #include "vtcross/error.h" 
     17/*! This file contains the default implementation of the CBR class, defined in 
     18 * the cbr.h include file.  This implementation is compiled into a static 
     19 * library which can be used as as backend for any cognitive engine. */ 
     20 
     21 
     22#include "vtcross/cbr.h" 
     23 
    3824 
    3925using namespace std; 
    40  
    41  
    42 #define DATABASENAME "cross_cbr" 
    4326 
    4427 
     
    5538    return 0; 
    5639} 
    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 }; 
    13340 
    13441 
     
    411318} 
    412319 
    413 #endif