📄 xdepot.h
字号:
/************************************************************************************************* * C++ API of Depot, the basic API of QDBM * Copyright (C) 2000-2003 Mikio Hirabayashi * This file is part of QDBM, Quick Database Manager. * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU * Lesser General Public License as published by the Free Software Foundation; either version * 2.1 of the License or any later version. QDBM 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 Lesser General Public License for more * details. * You should have received a copy of the GNU Lesser General Public License along with QDBM; if * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA. *************************************************************************************************/#ifndef _XDEPOT_H /* duplication check */#define _XDEPOT_H#include <xqdbm.h>#include <xadbm.h>extern "C" {#include <depot.h>#include <stdlib.h>}/** * Error container for Depot. */class qdbm::Depot_error : public virtual DBM_error { //---------------------------------------------------------------- // public member functions //----------------------------------------------------------------public: /** * Create an instance. */ Depot_error() throw(); /** * Create an instance. * @param ecode the error code. */ Depot_error(int ecode) throw(); /** * Copy constructor. * @param de a source instance. */ Depot_error(const Depot_error& de) throw(); /** * Release resources of the instance. */ virtual ~Depot_error() throw(); /** * Assignment operator. * @param de a source instance. * @return reference to itself. */ Depot_error& operator =(const Depot_error& de) throw(); /** * Assignment operator. * @param ecode the error code. * @return reference to itself. */ Depot_error& operator =(int ecode) throw(); /** * Equality operator. * @param de a comparing instance. * @return true if the both equal, else, false. */ virtual bool operator ==(const Depot_error& de) const throw(); /** * Inequality operator. * @param de a comparing instance. * @return true if the both do not equal, else, false. */ virtual bool operator !=(const Depot_error& de) const throw(); /** * Equality operator. * @param ecode a comparing error code. * @return true if the both equal, else, false. */ virtual bool operator ==(int ecode) const throw(); /** * Inequality operator. * @param ecode a comparing error code. * @return true if the both do not equal, else, false. */ virtual bool operator !=(int ecode) const throw(); /** * Cast operator into pointer to char. * @return the pointer to the string. */ virtual operator const char*() const throw(); /** * Get the error code. * @return the error code. */ virtual int code() const throw(); /** * Get the error message. * @return the pointer to the string. */ virtual const char* message() const throw(); //---------------------------------------------------------------- // private member variables //----------------------------------------------------------------private: /** The error code. */ int ecode;};/** * C++ API of Depot, the basic API of QDBM. */class qdbm::Depot : public virtual ADBM { //---------------------------------------------------------------- // public static member constants //----------------------------------------------------------------public: static const int ENOERR; ///< error code: no error static const int EFATAL; ///< error code: with fatal error static const int EMODE; ///< error code: invalid mode static const int EBROKEN; ///< error code: broken database file static const int EKEEP; ///< error code: existing record static const int ENOITEM; ///< error code: no item found static const int EALLOC; ///< error code: memory allocation error static const int EMAP; ///< error code: memory mapping error static const int EOPEN; ///< error code: open error static const int ECLOSE; ///< error code: close error static const int ETRUNC; ///< error code: trunc error static const int ESYNC; ///< error code: sync error static const int ESTAT; ///< error code: stat error static const int ESEEK; ///< error code: seek error static const int EREAD; ///< error code: read error static const int EWRITE; ///< error code: write error static const int ELOCK; ///< error code: lock error static const int EUNLINK; ///< error code: unlink error static const int EMKDIR; ///< error code: mkdir error static const int ERMDIR; ///< error code: rmdir error static const int EMISC; ///< error code: miscellaneous error static const int OREADER; ///< open mode: open as a reader static const int OWRITER; ///< open mode: open as a writer static const int OCREAT; ///< open mode: writer creating static const int OTRUNC; ///< open mode: writer truncating static const int ONOLCK; ///< open mode: open without locking static const int DOVER; ///< write mode: overwrite the existing value static const int DKEEP; ///< write mode: keep the existing value static const int DCAT; ///< write mode: concatenate values //---------------------------------------------------------------- // public static member functions //----------------------------------------------------------------public: /** * Get the version information. * @return the string of the version information. */ static const char* version() throw(); /** * Remove a database file. * @param name the name of a database file. * @throw Depot_error if an error occures. */ static void remove(const char* name) throw(Depot_error); //---------------------------------------------------------------- // public member functions //----------------------------------------------------------------public: /** * Get the database handle. * @param name the name of a database file. * @param omode the connection mode: `Depot::OWRITER' as a writer, `Depot::OREADER' as * a reader. If the mode is `Depot::OWRITER', the following may be added by bitwise or: * `Depot::OCREAT', which means it creates a new database if not exist, `Depot::OTRUNC', * which means it creates a new database regardless if one exists. Both of `Depot::OREADER' * and `Depot::OWRITER' can be added to by bitwise or: `Depot::ONOLCK', which means it opens a * database file without file locking. * @param bnum the number of elements of the bucket array. If it is not more than 0, * the default value is specified. The size of a bucket array is determined on creating, * and can not be changed except for by optimization of the database. Suggested size of a * bucket array is about from 0.5 to 4 times of the number of all records to store. * @throw Depot_error if an error occures. * @note While connecting as a writer, an exclusive lock is invoked to the database file. * While connecting as a reader, a shared lock is invoked to the database file. The thread * blocks until the lock is achieved. If `Depot::ONOLCK' is used, the application is * responsible for exclusion control. */ Depot(const char* name, int omode = Depot::OREADER, int bnum = -1) throw(Depot_error); /** * Release the resources. * @note If the database handle is not closed yet, it is closed. */ virtual ~Depot() throw(); /** * Close the database handle. * @throw Depot_error if an error occures. * @note Updating a database is assured to be written when the handle is closed. If a writer * opens a database but does not close it appropriately, the database will be broken. */ virtual void close() throw(Depot_error); /** * Store a record. * @param kbuf the pointer to the region of a key. * @param ksiz the size of the region of the key. If it is negative, the size is assigned * with `std::strlen(kbuf)'. * @param vbuf the pointer to the region of a value. * @param vsiz the size of the region of the value. If it is negative, the size is assigned * with `std::strlen(vbuf)'. * @param dmode behavior when the key overlaps, by the following values: `Depot::DOVER',
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -