presage  0.8.7
predictorRegistry.h
Go to the documentation of this file.
00001 
00002 /******************************************************
00003  *  Presage, an extensible predictive text entry system
00004  *  ---------------------------------------------------
00005  *
00006  *  Copyright (C) 2008  Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License along
00019     with this program; if not, write to the Free Software Foundation, Inc.,
00020     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00021                                                                              *
00022                                                                 **********(*)*/
00023 
00024 
00025 #ifndef PRESAGE_PREDICTORREGISTRY
00026 #define PRESAGE_PREDICTORREGISTRY
00027 
00028 #include "dispatcher.h"
00029 #include "../predictors/predictor.h"
00030 
00031 class ContextTracker;
00032 
00046 class PredictorRegistry : public Observer {
00047 public:
00048     PredictorRegistry(Configuration* config);
00049     ~PredictorRegistry();
00050 
00051     virtual void update (const Observable* variable);
00052 
00053     class Iterator {
00054     public:
00055         Iterator(std::vector<Predictor*>&);
00056         ~Iterator();
00057 
00058         bool hasNext() const;
00059         Predictor* next();
00060         
00061     private:
00062         std::vector<Predictor*>::iterator iter_end;
00063         std::vector<Predictor*>::iterator iter_curr;
00064 
00065     };
00066 
00067     Iterator iterator();
00068     void setContextTracker(ContextTracker* ct);
00069 
00070     class PredictorRegistryException : public PresageException {
00071     public:
00072         PredictorRegistryException(presage_error_code_t code, const std::string& desc) throw() : PresageException(code, desc) { }
00073         virtual ~PredictorRegistryException() throw() { }
00074 
00075     private:
00076         PredictorRegistryException() throw() : PresageException(PRESAGE_ERROR, "") { }
00077 
00078     };
00079 
00080     static const char* LOGGER;
00081     static const char* PREDICTORS;
00082 
00083 private:
00084     void setLogger (const std::string& level);
00085     void setPredictors(const std::string& predictor_list);
00086     void addPredictor(const std::string& predictor_name);
00087     void removePredictors();
00088 
00089     Configuration*  config;
00090     ContextTracker* contextTracker;
00091     Logger<char>    logger;
00092 
00093     std::string          predictors_list;
00094     std::vector<Predictor*> predictors;        // active Predictors
00095 
00096     Dispatcher<PredictorRegistry> dispatcher;
00097 };
00098 
00099 #endif // PRESAGE_PREDICTORREGISTRY