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