Datafile.h

00001 /* 
00002    EyeDB Object Database Management System
00003    Copyright (C) 1994-2008 SYSRA
00004    
00005    EyeDB is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009    
00010    EyeDB is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014    
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA 
00018 */
00019 
00020 /*
00021    Author: Eric Viara <viara@sysra.com>
00022 */
00023 
00024 
00025 #ifndef _EYEDB_DATAFILE_H
00026 #define _EYEDB_DATAFILE_H
00027 
00028 namespace eyedb {
00029 
00035   class Database;
00036   class Dataspace;
00037   class DatafileInfo;
00038 
00042   class Datafile {
00043 
00044   public:
00049     Database *getDatabase() {return db;}
00050 
00055     const Database *getDatabase() const {return db;}
00056 
00061     const char *getName() const {return name;}
00062 
00067     unsigned short getId() const {return id;}
00068 
00073     unsigned short getDspid() const {return dspid;}
00074 
00079     const Dataspace *getDataspace() const {return dataspace;}
00080 
00085     const char *getFile() const {return file;}
00086 
00091     Bool isValid() const {return *file ? True : False;}
00092 
00097     Bool isPhysical() const {
00098       return dtype == eyedbsm::PhysicalOidType ? True : False;
00099     }
00100 
00105     unsigned int getMaxsize() const {return maxsize;}
00106 
00111     eyedbsm::MapType getMaptype() const {return mtype;}
00112 
00117     unsigned int getSlotsize() const {return slotsize;}
00118 
00123     Status remove() const;
00124 
00130     Status resize(unsigned int size) const;
00131 
00137     Status getInfo(DatafileInfo &info) const;
00138 
00144     Status rename(const char *newname) const;
00145 
00150     Status defragment() const;
00151 
00158     Status move(const char *filedir, const char *filename) const;
00159 
00160   private:
00161     Datafile(Database *_db, unsigned short _id, unsigned short _dspid,
00162              const char *_file, const char *_name, int _maxsize,
00163              eyedbsm::MapType _mtype, int _slotsize, DatType _dtype) :
00164       db(_db), id(_id), dspid(_dspid), file(strdup(_file)), name(strdup(_name)),
00165       mtype(_mtype), maxsize(_maxsize), slotsize(_slotsize), dtype(_dtype) 
00166       {
00167         dataspace = 0;
00168       }
00169 
00170     void setDataspace(const Dataspace *_dataspace) {dataspace = _dataspace;}
00171 
00172     Database *db;
00173     unsigned short id, dspid;
00174     const Dataspace *dataspace;
00175     char *file, *name;
00176     eyedbsm::MapType mtype;
00177     unsigned int maxsize, slotsize;
00178     DatType dtype;
00179 
00180     ~Datafile() {
00181       free(file);
00182       free(name);
00183     }
00184 
00185     friend class Database;
00186   };
00187 
00188   std::ostream& operator<<(std::ostream&, const Datafile &);
00189 
00190   class DatafileInfo {
00191 
00192   public:
00193     struct Info {
00194       unsigned int objcnt;
00195       unsigned int slotcnt;
00196       unsigned int busyslotcnt;
00197       unsigned long long totalsize;
00198       unsigned int avgsize;
00199       unsigned int lastbusyslot;
00200       unsigned int lastslot;
00201       unsigned long long busyslotsize;
00202       unsigned long long datfilesize;
00203       unsigned long long datfileblksize;
00204       unsigned long long dmpfilesize;
00205       unsigned long long dmpfileblksize;
00206       unsigned int curslot;
00207       unsigned long long defragmentablesize;
00208       unsigned int slotfragcnt;
00209       double used;
00210     };
00211 
00212     DatafileInfo() {datafile = 0;}
00213     const Datafile *getDatafile() const {return datafile;}
00214     const DatafileInfo::Info & getInfo() const {return info;}
00215 
00216   private:
00217     void set(const Datafile *, DatafileInfo::Info &);
00218     const Datafile *datafile;
00219     Info info;
00220     friend class Datafile;
00221   };
00222 
00223   std::ostream& operator<<(std::ostream&, const DatafileInfo &);
00224 
00229 }
00230 
00231 #endif

Generated on Mon Dec 22 18:15:53 2008 for eyedb by  doxygen 1.5.3