/************************************************************************* * * HTCd - Copyright (C) 1998-2006 Henrik Rydberg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef DBH #define DBH #include #include //////////////////////////////////////////////////// // // OK for MT and MP // class dbmap { public: dbmap(); ~dbmap(); filemap::head_t* head() { return file->head(); } const filemap::head_t* head() const { return file->head(); } int remap(); int size() const { return recs.size(); } int empty() const { return recs.empty(); } const sref operator()(int row,int col) const throw(merror_t) { check(); return recs[row].rec->at(col); } const sref at(int row,int col) const throw(merror_t) { check(); return recs[row].rec->at(col); } /////////////////////////////////////////////////////// void Get(int row,spile& list) throw(merror_t); void Set(int row,int col,const sref& s) throw(merror_t); void Set(int row,const spile& list) throw(merror_t); /////////////////////////////////////////////////////// void Rem(int row) throw(merror_t); int Insert(const spile& list,int unique) throw(merror_t); /////////////////////////////////////////////////////// int Tables() const { return head()->tables.get(); } const sref Table(int col) const { check(); return head()->get(col); } /////////////////////////////////////////////////////// void SetTable(int col,const sref& name) throw(merror_t); void RemTable(int col) throw(merror_t); void InsertTable(int col,const sref& name) throw(merror_t); /////////////////////////////////////////////////////// int Index() const { return index; } int FindIndex(const sref& tab) const { return tmap.get(tab); } int Index(const sref& tab) const throw(merror_t) { int p=FindIndex(tab); if(p<0) THROW("db: table ["<Lastmod(); } void Close(); static void Sync(); protected: dbmap(const dbmap& db) {} void operator=(const dbmap& db) {} void check() const { if(fatal!=head()->fatal.get()) THROW("db: fatal state change") } void remap_recs(); void remap_tabs(); static void setup(); static const op_t* CompOperator(const sref& s); static filemap* flist; static mutex_t mutex; static opmap M; private: int wok,minor,major,fatal,index; mstring compname; filemap* file; rimap tmap; indexmap recs; }; void Convert(dbmap& db,const char* path); #endif