00001 #ifndef TRAPPER_RW_ALGO_H 00002 #define TRAPPER_RW_ALGO_H 00003 00004 #include "algo.h" 00005 #include "mal.h" 00006 00007 /** \brief Base class for algorithms that reads and writes data 00008 00009 Derive from this class if you want to write an algorithm which 00010 modifies the data in some way. Changes made to the data via the 00011 MAl interface will be automatically reflected in the database, 00012 without the programmer having to worry about the DB. 00013 00014 The MAl and MAl_readonly functionality is provided by the 00015 getMAl() function. 00016 00017 SOP for creating a new RW algorithm (called NewAlgo in this 00018 example): 00019 00020 newalgo.h (#include guards etc omitted): 00021 00022 \code 00023 #include "RW_algo.h" 00024 00025 class NewAlgo : public RWAlgo 00026 { 00027 public: 00028 NewAlgo(TrapperDoc * pDoc_, std::set< db_recno_t >& recnoList, AlgoParam* param) : 00029 RWAlgo(pDoc_, recnoList, param) {} 00030 00031 void start(); 00032 00033 }; 00034 \endcode 00035 00036 That's it. The new algo implements the start() function and has to call RWAlgo's 00037 only constructor. start() can be virtual if a family of algos are being constructed. 00038 00039 NOTA BENE! Important that the constructor gets a reference to the recnolist! 00040 00041 newalgo.cpp: 00042 00043 \code 00044 #include "newalgo.h" 00045 00046 void NewAlgo::start() 00047 { 00048 //implementation of NewAlgo::start(). 00049 } 00050 00051 \endcode 00052 00053 00054 newalgomaker.cpp: 00055 00056 \code 00057 #include "algomaker.h" 00058 #include "newalgo.h" 00059 00060 char newAlgo[]="New Algo";//The text that shows up in the popup 00061 const bool newPopsup = true;//true if it should pop up in context menu 00062 template 00063 const AlgoMakerTP< NewAlgo, newAlgo, newPopsup > AlgoMakerTP< NewAlgo, newAlgo, newPopsup >::registerThis; 00064 \endcode 00065 00066 Add the new files to src.pro and you're done. 00067 */ 00068 class RWAlgo : public Algo 00069 { 00070 public: 00071 RWAlgo(TrapperDoc * pDoc_, std::set< db_recno_t >& recnoList, AlgoParam* param); 00072 ~RWAlgo() { delete mal; } 00073 00074 virtual void start() = 0; 00075 00076 MAl* getMAl() { return mal; } 00077 00078 private: 00079 MAl* mal; 00080 }; 00081 00082 #endif// TRAPPER_RW_ALGO_H