📄 bdb_cursor.hpp
字号:
/* * =========================================================================== * PRODUCTION $Log: bdb_cursor.hpp,v $ * PRODUCTION Revision 1000.2 2004/06/01 18:36:57 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.10 * PRODUCTION * =========================================================================== */#ifndef BDB___CURSOR_HPP__#define BDB___CURSOR_HPP__/* $Id: bdb_cursor.hpp,v 1000.2 2004/06/01 18:36:57 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Author: Anatoliy Kuznetsov * * File Description: Berkeley DB Cursor. * *//// @file bdb_cursor.hpp/// Berkeley BDB file cursor#include <bdb/bdb_file.hpp>#include <algorithm>BEGIN_NCBI_SCOPE/** @addtogroup BDB_Files * * @{ */class CBDB_FileCursor;class CBDB_FC_Condition;/// File cursor condition handle.////// Used for assigning search conditions to a cursor. ////// <pre>////// Example:/// /// CBDB_FileCursor cursor(bdb_file);/// cursor.From << 10;/// cursor.To << 20;////// </pre>///class NCBI_BDB_EXPORT CBDB_ConditionHandle{public: CBDB_ConditionHandle& operator<< (int val); CBDB_ConditionHandle& operator<< (unsigned int val); CBDB_ConditionHandle& operator<< (float val); CBDB_ConditionHandle& operator<< (double val); CBDB_ConditionHandle& operator<< (const char* val); CBDB_ConditionHandle& operator<< (const string& val);protected: CBDB_ConditionHandle(CBDB_FC_Condition& cond); ~CBDB_ConditionHandle(); CBDB_FC_Condition& m_Condition; friend class CBDB_FileCursor;};/// Berkeley DB file cursor class. ////// BDB btree cursors can retrieve values using FROM-TO range criteria.///class NCBI_BDB_EXPORT CBDB_FileCursor{public: // Cursor search conditions enum ECondition { eNotSet, eFirst, eLast, eEQ, eGT, eGE, eLT, eLE }; enum EFetchDirection { eForward, eBackward, eDefault }; typedef unsigned long TRecordCount; public: CBDB_FileCursor(CBDB_File& dbf); CBDB_FileCursor(CBDB_File& dbf, CBDB_Transaction& trans); ~CBDB_FileCursor(); void SetCondition(ECondition cond_from, ECondition cond_to = eNotSet); void SetFetchDirection(EFetchDirection fdir); EFetchDirection GetFetchDirection() const { return m_FetchDirection; } EFetchDirection GetReverseFetchDirection() const; void ReverseFetchDirection(); EBDB_ErrCode FetchFirst(); EBDB_ErrCode Fetch(EFetchDirection fdir = eDefault); EBDB_ErrCode Update(CBDB_File::EAfterWrite = CBDB_File::eDiscardData); EBDB_ErrCode Delete(CBDB_File::EIgnoreError on_error = CBDB_File::eThrowOnError); // Returns number of records with same key as this cursor refers TRecordCount KeyDupCount() const;protected: /// Test "TO" search criteria. Return "true" if current value satisfies it bool TestTo() const; /// Set m_FirstFetched field to FALSE. void ResetFirstFetched(); /// Return next field's IBDB_FieldConvert interface /// (hidden cast to non-public parent class) IBDB_FieldConvert& GetFieldConvert(CBDB_BufferManager& buf, unsigned int n);protected: /// Reference on the "mother" file CBDB_File& m_Dbf; public: CBDB_ConditionHandle From; CBDB_ConditionHandle To;private: CBDB_FileCursor(const CBDB_FileCursor&); CBDB_FileCursor& operator= (const CBDB_FileCursor&);private: /// Berkeley DB DBC thing DBC* m_DBC; /// From condition proxy-object ECondition m_CondFrom; /// To condition proxy-object ECondition m_CondTo; /// Fetch direction (forward/backward) EFetchDirection m_FetchDirection; /// Flag if FetchFirst is already been done bool m_FirstFetched; friend class CBDB_FC_Condition;};/* @} *//////////////////////////////////////////////////////////////////////////////// IMPLEMENTATION of INLINE functions//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// CBDB_FileCursor:://inline void CBDB_FileCursor::ResetFirstFetched(){ m_FirstFetched = false;}inline IBDB_FieldConvert& CBDB_FileCursor::GetFieldConvert(CBDB_BufferManager& buf, unsigned int n){ return static_cast<IBDB_FieldConvert&> (buf.GetField(n));}inlinevoid CBDB_FileCursor::SetFetchDirection(EFetchDirection fdir){ m_FetchDirection = fdir;}inlineCBDB_FileCursor::EFetchDirection CBDB_FileCursor::GetReverseFetchDirection() const{ if (m_FetchDirection == eForward) return eBackward; return eForward;}inlinevoid CBDB_FileCursor::ReverseFetchDirection(){ if (m_FetchDirection == eForward) m_FetchDirection = eBackward; if (m_FetchDirection == eBackward) m_FetchDirection = eForward;}END_NCBI_SCOPE/* * =========================================================================== * $Log: bdb_cursor.hpp,v $ * Revision 1000.2 2004/06/01 18:36:57 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.10 * * Revision 1.10 2004/05/06 19:18:46 rotmistr * Cursor KeyDupCount added * * Revision 1.9 2004/05/06 18:17:58 rotmistr * Cursor Update/Delete implemented * * Revision 1.8 2003/12/29 13:23:24 kuznets * Added support for transaction protected cursors. * * Revision 1.7 2003/09/26 21:01:05 kuznets * Comments changed to meet doxygen format requirements * * Revision 1.6 2003/07/18 20:09:38 kuznets * Added several FetchDirection manipulation functions. * * Revision 1.5 2003/06/27 18:57:16 dicuccio * Uninlined strerror() adaptor. Changed to use #include<> instead of #include "" * * Revision 1.4 2003/06/10 20:07:27 kuznets * Fixed header files not to repeat information from the README file * * Revision 1.3 2003/06/03 18:50:09 kuznets * Added dll export/import specifications * * Revision 1.2 2003/04/29 16:48:31 kuznets * Fixed minor warnings in Sun Workshop compiler * * Revision 1.1 2003/04/24 16:31:16 kuznets * Initial revision * * =========================================================================== */#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -