📄 bdb_map.hpp
字号:
const value_type& operator*() const { this->check_open_cursor(); return this->m_pair; } const value_type* operator->() const { this->check_open_cursor(); return &this->m_pair; } const_iterator& operator++() { this->fetch_next(); return *this; } const_iterator operator++(int) { const_iterator tmp(*this); this->fetch_next(); return tmp; } const_iterator& operator--() { this->fetch_prev(); return *this; } const_iterator operator--(int) { const_iterator tmp(*this); this->fetch_prev(); return tmp; } bool operator==(const const_iterator& it) { return is_equal(it); } bool operator!=(const const_iterator& it) { return !is_equal(it); } };public: db_map_base(CBDB_File::EDuplicateKeys dup_keys) : m_Dbf(dup_keys) {} void open(const char* fname, ios_base::openmode mode=ios_base::in|ios_base::out, unsigned int cache_size=0); void open(const char* fname, CBDB_RawFile::EOpenMode db_mode, unsigned int cache_size=0); const_iterator begin() const; const_iterator end() const; const_iterator find(const K& key) const; size_t size() const; void clear(); void erase(const K& key);protected: mutable File m_Dbf;};/// db_map template, mimics std::map<> using BerkeleyDB as the underlying/// Btree mechanism.////// NOTE: const methods of this template are conditionally thread safe due /// to the use of mutable variables./// If you access to access one instance of db_map from more than one thread,/// external syncronization is required.template<class K, class T> class db_map : public db_map_base<K, T>{public: typedef typename CBDB_TypeMapper<K>::TFieldType db_first_type; typedef typename CBDB_TypeMapper<T>::TFieldType db_second_type; typedef K key_type; typedef T referent_type; typedef std::pair<const K, T> value_type; typedef db_map<K, T> self_type; typedef typename self_type::iterator_base iterator_base_type;public: db_map() : db_map_base<K, T>(CBDB_File::eDuplicatesDisable) {} // // Determines whether an element y exists in the map whose key matches that of x. // If not creates such an element and returns TRUE. Otherwise returns FALSE. bool insert(const value_type& x); referent_type operator[](const K& key);};/// db_multimap template, mimics std::multimap<> using BerkeleyDB as /// the underlying Btree mechanism.////// NOTE: const methods of this template are conditionally thread safe due /// to the use of mutable variables./// If you access to access one instance of db_map from more than one thread,/// external syncronization is required.///template<class K, class T> class db_multimap : public db_map_base<K, T>{public: typedef typename CBDB_TypeMapper<K>::TFieldType db_first_type; typedef typename CBDB_TypeMapper<T>::TFieldType db_second_type; typedef K key_type; typedef T referent_type; typedef std::pair<const K, T> value_type; typedef db_multimap<K, T> self_type; typedef typename self_type::iterator_base iterator_base_type;public: db_multimap() : db_map_base<K, T>(CBDB_File::eDuplicatesEnable) {} void insert(const value_type& x);};/* @} *//////////////////////////////////////////////////////////////////////////////// IMPLEMENTATION of INLINE functions/////////////////////////////////////////////////////////////////////////////inline CBDB_RawFile::EOpenMode iosbase2BDB(ios_base::openmode mode){ CBDB_RawFile::EOpenMode db_mode = CBDB_RawFile::eReadWriteCreate; // Mapping iostream based open mode into BDB open mode // if (mode & ios_base::in) { db_mode = (mode & ios_base::out) ? CBDB_RawFile::eReadWriteCreate : CBDB_RawFile::eReadOnly; } else { if (mode & ios_base::out) { db_mode = CBDB_RawFile::eReadWriteCreate; if (mode & ios_base::trunc) { db_mode = CBDB_RawFile::eCreate; } } } return db_mode;}///////////////////////////////////////////////////////////////////////////////// db_map_base//template<class K, class T>void db_map_base<K, T>::open(const char* fname, ios_base::openmode mode, unsigned int cache_size){ CBDB_RawFile::EOpenMode db_mode = iosbase2BDB(mode); open(fname, db_mode, cache_size);}template<class K, class T>void db_map_base<K, T>::open(const char* fname, CBDB_RawFile::EOpenMode db_mode, unsigned int cache_size){ if (cache_size) m_Dbf.SetCacheSize(cache_size); m_Dbf.Open(fname, db_mode); m_Dbf.SetLegacyStringsCheck(true);}template<class K, class T>typename db_map_base<K, T>::const_iterator db_map_base<K, T>::begin() const{ return const_iterator(&m_Dbf);}template<class K, class T>typename db_map_base<K, T>::const_iterator db_map_base<K, T>::end() const{ const_iterator it(&m_Dbf); return it.go_end();}template<class K, class T>typename db_map_base<K, T>::const_iterator db_map_base<K, T>::find(const K& key) const{ return const_iterator(&m_Dbf, key);}template<class K, class T>size_t db_map_base<K, T>::size() const{ return m_Dbf.CountRecs();}template<class K, class T>void db_map_base<K, T>::clear(){ m_Dbf.Truncate();}template<class K, class T>void db_map_base<K, T>::erase(const K& key){ m_Dbf.key = key; m_Dbf.Delete();}///////////////////////////////////////////////////////////////////////////////// db_map//template<class K, class T>bool db_map<K, T>::insert(const value_type& x){ this->m_Dbf.key = x.first; this->m_Dbf.value = x.second; EBDB_ErrCode ret = this->m_Dbf.Insert(); return (ret == eBDB_Ok);}template<class K, class T>typename db_map<K, T>::referent_type db_map<K, T>::operator[](const K& key){ this->m_Dbf.key = key; EBDB_ErrCode ret = this->m_Dbf.Fetch(); if (ret == eBDB_Ok) { return (T) this->m_Dbf.value; } return (T) this->m_Dbf.value;}///////////////////////////////////////////////////////////////////////////////// db_multimap//template<class K, class T>void db_multimap<K, T>::insert(const value_type& x){ this->m_Dbf.key = x.first; this->m_Dbf.value = x.second; EBDB_ErrCode ret = this->m_Dbf.Insert(); BDB_CHECK(ret, this->m_Dbf.GetFileName().c_str());}END_NCBI_SCOPE/* * =========================================================================== * $Log: bdb_map.hpp,v $ * Revision 1000.2 2004/04/29 15:32:57 gouriano * PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.11 * * Revision 1.11 2004/04/26 16:43:59 ucko * Qualify inherited dependent names with this-> where needed by GCC 3.4. * * Revision 1.10 2004/02/11 17:59:05 kuznets * Set legacy strings checking by default * * Revision 1.9 2004/02/04 17:04:58 kuznets * Make use of LString type in map objects to handle non-ASCIIZ strings * * Revision 1.8 2003/12/16 17:47:09 kuznets * minor code cleanup * * Revision 1.7 2003/09/29 14:30:22 kuznets * Comments doxygenification * * Revision 1.6 2003/07/24 15:43:25 kuznets * Fixed SUN compilation problems * * Revision 1.5 2003/07/23 20:22:50 kuznets * Implemened: clean(), erase() * * Revision 1.4 2003/07/23 18:09:51 kuznets * + "cache size" parameter for bdb_map bdb_multimap * * Revision 1.3 2003/07/22 16:38:00 kuznets * Fixing compilation problems * * Revision 1.2 2003/07/22 15:15:46 kuznets * Work in progress, multiple changes, added db_multimap template. * * Revision 1.1 2003/07/18 20:48:29 kuznets * Initial revision * * * =========================================================================== */#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -