ionflux.org | Impressum

BufferedTable.hpp

Go to the documentation of this file.
00001 #ifndef IONFLUX_TOOLS_BUFFEREDTABLE
00002 #define IONFLUX_TOOLS_BUFFEREDTABLE
00003 /* ==========================================================================
00004  * Ionflux Tools
00005  * Copyright (c) 2005 Joern P. Meier
00006  * mail@ionflux.org
00007  * --------------------------------------------------------------------------
00008  * BufferedTable.hpp                 Buffered database table.
00009  * ==========================================================================
00010  * 
00011  * This file is part of Ionflux Tools.
00012  * 
00013  * Ionflux Tools is free software; you can redistribute it and/or modify it
00014  * under the terms of the GNU General Public License as published by the 
00015  * Free Software Foundation; either version 2 of the License, or (at your 
00016  * option) any later version.
00017  * 
00018  * Ionflux Tools is distributed in the hope that it will be useful, but 
00019  * WITHOUT ANY WARRANTY; without even the implied warranty of 
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00021  * General Public License for more details.
00022  * 
00023  * You should have received a copy of the GNU General Public License along 
00024  * with Ionflux Tools; if not, write to the Free Software Foundation, Inc.,
00025  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00026  * 
00027  * ========================================================================== */
00028 
00029 #include <string>
00030 #include <iostream>
00031 #include <sstream>
00032 #include <vector>
00033 #include "ionflux/Reporter.hpp"
00034 #include "ionflux/MySQLDatabase.hpp"
00035 #include "ionflux/Node.hpp"
00036 #include "ionflux/Template.hpp"
00037 #include "ionflux/ObjectPool.hpp"
00038 
00039 namespace Ionflux
00040 {
00041 
00042 namespace Tools
00043 {
00044 
00061 class BufferedTable
00062 : public Ionflux::Tools::ManagedObject
00063 {
00064     private:
00065         
00066     protected:
00068         Ionflux::Tools::Reporter log;
00070         Ionflux::Tools::ObjectPool pool;
00072         Ionflux::Tools::Database* database;
00074         Ionflux::Tools::Node* prevBlock;
00076         Ionflux::Tools::Node* currentBlock;
00078         Ionflux::Tools::Node* nextBlock;
00080         int currentOffset;
00082         std::map<std::string, unsigned int> offsetIndex;
00084         std::vector<std::string> keyIndex;
00086         unsigned int blockSize;
00088         std::string origin;
00090         std::string table;
00092         std::string keyField;
00094         std::vector<std::string> fields;
00096         int currentIndex;
00098         std::string createTemplate;
00100         std::string createTemplateFile;
00102         Ionflux::Tools::Node config;
00103         
00112         virtual void cycleForward();
00113         
00122         virtual void cycleBackward();
00123         
00128         virtual void updateIndices();
00129         
00145         virtual void initBlock(Ionflux::Tools::Node* target, 
00146             const std::string& fromKey, bool invert = false);
00147         
00164         virtual int getBlockStartOffset(const std::string& key);
00165         
00166     public:
00168         static const unsigned int DEFAULT_BLOCK_SIZE;
00169         
00174         BufferedTable();
00175         
00182         BufferedTable(unsigned int initBlockSize);
00183         
00190         BufferedTable(Ionflux::Tools::Database* initDatabase);
00191         
00199         BufferedTable(Ionflux::Tools::Database* initDatabase, unsigned int 
00200         initBlockSize);
00201         
00213         BufferedTable(Ionflux::Tools::Database* initDatabase, unsigned int 
00214         initBlockSize, const std::string& initTable, const std::string& 
00215         initKeyField, const std::vector<std::string>& initFields);
00216         
00229         BufferedTable(Ionflux::Tools::Database* initDatabase, unsigned int 
00230         initBlockSize, const std::string& initTable, const std::string& 
00231         initKeyField, const std::vector<std::string>& initFields, const 
00232         std::string& initOrigin);
00233         
00238         virtual ~BufferedTable();
00239         
00247         virtual void setConfig(Ionflux::Tools::Node& newConfig);
00248         
00256         virtual void setDatabase(Ionflux::Tools::Database* newDatabase);
00257         
00265         virtual Ionflux::Tools::Database* getDatabase();
00266         
00275         virtual bool validateTable();
00276         
00286         virtual Ionflux::Tools::Node* getRecord(int recIndex);
00287         
00297         virtual Ionflux::Tools::Node* operator[](int recIndex);
00298         
00305         virtual Ionflux::Tools::Node* getCurrentRecord();
00306         
00315         virtual Ionflux::Tools::Node* getNextRecord();
00316         
00325         virtual Ionflux::Tools::Node* getPrevRecord();
00326         
00336         virtual int getTableOffset(const std::string& key);
00337         
00351         virtual std::string getKey(const std::string& key, int recOffset);
00352         
00365         virtual std::string getKey(int recIndex);
00366         
00379         virtual std::string fetchKey(unsigned int offset);
00380         
00387         virtual unsigned int getNumRecs();
00388         
00397         virtual unsigned int getFieldIndex(const std::string& fieldName);
00398         
00407         virtual void refresh();
00408         
00418         virtual void clearBlocks();
00419         
00424         virtual void clear();
00425         
00432         virtual Ionflux::Tools::Reporter& getLog();
00433         
00441         virtual void setOrigin(unsigned int offset);
00442         
00451         virtual void setCurrentRecord(const std::string& newKey);
00452         
00459         virtual void setBlockSize(unsigned int newBlockSize);
00460         
00468         virtual void setOrigin(const std::string& newOrigin);
00469         
00476         virtual void setTable(const std::string& newTable);
00477         
00485         virtual void setKeyField(const std::string& newKeyField);
00486         
00494         virtual void setFields(const std::vector<std::string>& newFields);
00495         
00502         virtual void setCurrentIndex(int newCurrentIndex);
00503         
00510         virtual void setCreateTemplate(const std::string& newCreateTemplate);
00511         
00518         virtual void setCreateTemplateFile(const std::string& 
00519         newCreateTemplateFile);
00520         
00525         virtual unsigned int getBlockSize() const;
00526         
00531         virtual std::string getOrigin() const;
00532         
00537         virtual std::string getTable() const;
00538         
00544         virtual std::string getKeyField() const;
00545         
00551         virtual std::vector<std::string> getFields() const;
00552         
00557         virtual int getCurrentIndex() const;
00558         
00563         virtual std::string getCreateTemplate() const;
00564         
00569         virtual std::string getCreateTemplateFile() const;
00570         
00571 };
00572 
00573 }
00574 
00575 }
00576 
00580 #endif

Generated on Tue Mar 14 20:58:29 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6