📄 xvilla.h
字号:
* cursor becomes unavailable due to updating database. */ virtual void put(const char* kbuf, int ksiz, const char* vbuf, int vsiz, int dmode = Villa::DOVER) throw(Villa_error); /** * Delete 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)'. * @throw Villa_error if an error occures or no record corresponds. * @note When the key of duplicated records is specified, the first record of the same key * is deleted. The cursor becomes unavailable due to updating database. */ virtual void out(const char* kbuf, int ksiz) throw(Villa_error); /** * Retrieve 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 sp the pointer to a variable to which the size of the region of the return value * is assigned. If it is 0, it is not used. * @return the pointer to the region of the value of the corresponding record. * @throw Villa_error if an error occures or no record corresponds. * @note When the key of duplicated records is specified, the value of the first record of * the same key is selected. Because an additional zero code is appended at the end of the * region of the return value, the return value can be treated as a character string. * Because the region of the return value is allocated with the `std::malloc' call, it * should be released with the `std::free' call if it is no longer in use. */ virtual char* get(const char* kbuf, int ksiz, int* sp = 0) throw(Villa_error); /** * Get the number of records corresponding a key. * @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)'. * @return the number of corresponding records. If no record corresponds, 0 is returned. * @throw Villa_error if an error occures. */ virtual int vnum(const char* kbuf, int ksiz) throw(Villa_error); /** * Move the cursor to the first record. * @throw Villa_error if an error occures or there is no record in the database. */ virtual void curfirst() throw(Villa_error); /** * Move the cursor to the last record. * @throw Villa_error if an error occures or there is no record in the database. */ virtual void curlast() throw(Villa_error); /** * Move the cursor to the previous record. * @throw Villa_error if an error occures or there is no previous record. */ virtual void curprev() throw(Villa_error); /** * Move the cursor to the next record. * @throw Villa_error if an error occures or there is no next record. */ virtual void curnext() throw(Villa_error); /** * Move the cursor to positon around 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 jmode detail adjustment: `Villa::JFORWARD', which means that the cursor is set to * the first record of the same key and that the cursor is set to the next substitute if * completely matching record does not exist, `Villa::JBACKWARD', which means that the cursor * is set to the last record of the same key and that the cursor is set to the previous * substitute if completely matching record does not exist. * @throw Villa_error if an error occures or there is no record corresponding the condition. */ virtual void curjump(const char* kbuf, int ksiz, int jmode = Villa::JFORWARD) throw(Villa_error); /** * Get the key of the record where the cursor is. * @param sp the pointer to a variable to which the size of the region of the return value * is assigned. If it is 0, it is not used. * @return the pointer to the region of the key of the corresponding record. * @throw Villa_error if an error occures or no record corresponds to the cursor. * @note Because an additional zero code is appended at the end of the region of the return * value, the return value can be treated as a character string. Because the region of the * return value is allocated with the `std::malloc' call, it should be released with the * `std::free' call if it is no longer in use. */ virtual char* curkey(int* sp = 0) throw(Villa_error); /** * Get the value of the record where the cursor is. * @param sp the pointer to a variable to which the size of the region of the return value * is assigned. If it is 0, it is not used. * @return the pointer to the region of the value of the corresponding record. * @throw Villa_error if an error occures or no record corresponds to the cursor. * @note Because an additional zero code is appended at the end of the region of the return * value, the return value can be treated as a character string. Because the region of the * return value is allocated with the `std::malloc' call, it should be released with the * `std::free' call if it is no longer in use. */ virtual char* curval(int* sp = 0) throw(Villa_error); /** * Set the tuning parameters for performance. * @param lrecmax the max number of records in a leaf node of B+ tree. If it is not more * than 0, the default value is specified. * @param nidxmax the max number of indexes in a non-leaf node of B+ tree. If it is not more * than 0, the default value is specified. * @param lcnum the max number of caching leaf nodes. If it is not more than 0, the default * value is specified. * @param ncnum the max number of caching non-leaf nodes. If it is not more than 0, the * default value is specified. * @throw Villa_error if an error occures. * @note The default setting is equivalent to `settuning(49, 192, 1024, 512)'. Because tuning * paremeters are not saved in a database, you should specify them every opening a database. */ virtual void settuning(int lrecmax, int nidxmax, int lcnum, int ncnum) throw(Villa_error); /** * Synchronize updating contents with the file and the device. * @throw Villa_error if an error occures. * @note This function is useful when another process uses the connected database file. This * function shuold not be used while the transaction is activated. */ virtual void sync() throw(Villa_error); /** * Optimize a database. * @throw Villa_error if an error occures. * @note In an alternating succession of deleting and storing with overwrite or concatenate, * dispensable regions accumulate. This function is useful to do away with them. This * function shuold not be used while the transaction is activated. */ virtual void optimize() throw(Villa_error); /** * Get the name of the database. * @return the pointer to the region of the name of the database. * @throw Villa_error if an error occures. * @note Because the region of the return value is allocated with the `std::malloc' call, * it should be released with the `std::free' call if it is no longer in use. */ virtual char* name() throw(Villa_error); /** * Get the size of the database file. * @return the size of the database file. * @throw Villa_error if an error occures. * @note Because of the I/O buffer, the return value may be less than the real size. */ virtual int fsiz() throw(Villa_error); /** * Get the number of the leaf nodes of B+ tree. * @return the number of the leaf nodes. * @throw Villa_error if an error occures. */ virtual int lnum() throw(Villa_error); /** * Get the number of the non-leaf nodes of B+ tree. * @return the number of the non-leaf nodes. * @throw Villa_error if an error occures. */ virtual int nnum() throw(Villa_error); /** * Get the number of the records stored in a database. * @return the number of the records stored in the database. * @throw Villa_error if an error occures. */ virtual int rnum() throw(Villa_error); /** * Check whether the database handle is a writer or not. * @return true if the handle is a writer, false if not. * @throw Villa_error if an error occures. */ virtual bool writable() throw(Villa_error); /** * Check whether the database has a fatal error or not. * @return true if the database has a fatal error, false if not. * @throw Villa_error if an error occures. */ virtual bool fatalerror() throw(Villa_error); /** * Get the inode number of the database file. * @return the inode number of the database file. * @throw Villa_error if an error occures. */ virtual int inode() throw(Villa_error); /** * Begin the transaction. * @throw Villa_error if an error occures. * @note If a thread is already in the transaction, the other threads block until the prius * is out of the transaction. Only one transaction can be activated with a database handle * at the same time. */ virtual void tranbegin() throw(Villa_error); /** * Commit the transaction. * @throw Villa_error if an error occures. * @note Updating a database in the transaction is fixed when it is committed successfully. * Any other thread except for the one which began the transaction should not call this * function. */ virtual void trancommit() throw(Villa_error); /** * Abort the transaction. * @throw Villa_error if an error occures. * @note Updating a database in the transaction is discarded when it is aborted. The state * of the database is rollbacked to before transaction. Any other thread except for the one * which began the transaction should not call this function. */ virtual void tranabort() throw(Villa_error); /** * Store a record. * @param key reference to a key object. * @param val reference to a value object. * @param replace whether the existing value is to be overwritten or not. * @throw Villa_error if an error occures or replace is cancelled. */ virtual void storerec(const Datum& key, const Datum& val, bool replace = true) throw(Villa_error); /** * Delete a record. * @param key reference to a key object. * @throw Villa_error if an error occures or no record corresponds. */ virtual void deleterec(const Datum& key) throw(Villa_error); /** * Fetch a record. * @param key reference to a key object. * @return a temporary instance of the value of the corresponding record. * @throw Villa_error if an error occures or no record corresponds. */ virtual Datum fetchrec(const Datum& key) throw(Villa_error); /** * Get the first key. * @return a temporary instance of the key of the first record. * @throw Villa_error if an error occures or no record corresponds. */ virtual Datum firstkey() throw(Villa_error); /** * Get the next key. * @return a temporary instance of the key of the next record. * @throw Villa_error if an error occures or no record corresponds. */ virtual Datum nextkey() throw(Villa_error); /** * Check whether a fatal error occured or not. * @return true if the database has a fatal error, false if not. * @throw Villa_error if an error occures. */ virtual bool error() throw(Villa_error); //---------------------------------------------------------------- // private member variables //----------------------------------------------------------------private: VILLA* villa; ///< internal database handle pthread_mutex_t tranmutex; ///< mutex for the transaction //---------------------------------------------------------------- // private member functions //----------------------------------------------------------------private: /** copy constructor: This should not be used. */ Villa(const Villa& villa) throw(Villa_error); /** assignment operator: This should not be used. */ Villa& operator =(const Villa& villa) throw(Villa_error);};#endif /* duplication check *//* END OF FILE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -