📄 bdb_types.hpp
字号:
size_t max_len = GetBufferSize(); size_t copy_len = GetDataLength(src_buf); if (copy_len > max_len) { BDB_THROW(eOverflow, "Cannot copy. Data length exceeds max value"); } ::memcpy(dst_ptr, src_buf, copy_len);}inline const string& CBDB_Field::GetName() const{ return m_Name;}inline void CBDB_Field::SetName(const char* name){ _ASSERT(name); m_Name = name;}inline bool CBDB_Field::IsByteSwapped() const { return m_BufferManager->IsByteSwapped(); }/////////////////////////////////////////////////////////////////////////////// CBDB_FieldString:://inline CBDB_FieldString::CBDB_FieldString() : CBDB_FieldStringBase(){ SetBufferSize(256);}inline CBDB_FieldString::operator const char* () const{ const char* str = (const char*) GetBuffer(); _ASSERT(str); return str;}inline const CBDB_FieldString&CBDB_FieldString::operator= (const CBDB_FieldString& str){ if (this == &str) return *this; size_t len = str.GetLength(); if (len > GetBufferSize()) { // TODO: allow partial string assignment? BDB_THROW(eOverflow, "String field overflow."); } Unpack(); ::strcpy((char*)GetBuffer(), (const char*) str); if ( str.IsNull() ) { SetNull(); } else { SetNotNull(); } return *this;}inlinevoid CBDB_FieldString::Set(const char* str, EOverflowAction if_overflow){ if ( !str ) str = kEmptyCStr; size_t new_len = ::strlen(str) + 1; // check overflow if (new_len > GetBufferSize()) { if (if_overflow == eTruncateOnOverflow) { new_len = GetBufferSize(); } else { string message("String field overflow."); // TODO: add info what caused overflow, what length expected BDB_THROW(eOverflow, message); } } Unpack(); ::memcpy(GetBuffer(), str, new_len); SetNotNull();}inlinevoid CBDB_FieldString::SetString(const char* str){ operator=(str);}inline int CBDB_FieldString::Compare(const void* p1, const void* p2, bool /*byte_swapped*/) const{ _ASSERT(p1 && p2); return ::strcmp((const char*) p1, (const char*) p2);}inline void CBDB_FieldString::SetMinVal(){ ((char*) Unpack())[0] = '\0';}inline void CBDB_FieldString::SetMaxVal(){ void* buf = Unpack(); // TODO: find out whether xFF or 0x7F should be used, and how // (because of possible 'signed char' comparison in strcmp()). ::memset(buf, 0x7F, GetBufferSize()); // 0xFF for international ((char*) buf)[GetBufferSize() - 1] = '\0'; SetNotNull();}inline bool CBDB_FieldString::IsEmpty() const{ const char* str = (const char*) GetBuffer(); _ASSERT(str); return !*str;}inline bool CBDB_FieldString::IsBlank() const{ const char* str = (const char*) GetBuffer(); _ASSERT(str); for (; *str; ++str) { if ( !isspace(*str) ) return false; } return true;}inline size_t CBDB_FieldString::GetDataLength(const void* buf) const{ _ASSERT(buf); return ::strlen((const char*) buf) + 1;}inline const CBDB_FieldString& CBDB_FieldString::operator= (const char* str){ Set(str, eThrowOnOverflow); return *this;}inline const CBDB_FieldString& CBDB_FieldString::operator= (const string& str){ return this->operator=(str.c_str());}/////////////////////////////////////////////////////////////////////////////// CBDB_BufferManager:://inline const CBDB_Field& CBDB_BufferManager::GetField(unsigned int n) const{ return *m_Fields[n];}inline CBDB_Field& CBDB_BufferManager::GetField(unsigned int n){ return *m_Fields[n];}inline unsigned int CBDB_BufferManager::FieldCount() const{ return (unsigned int)m_Fields.size();}inline bool CBDB_BufferManager::IsPackable() const{ return m_Packable;}inline bool CBDB_BufferManager::IsNullable() const{ return m_Nullable;}inline void CBDB_BufferManager::SetNullable(){ _ASSERT(m_Buffer == 0); m_Nullable = true;}inline size_t CBDB_BufferManager::ComputeNullSetSize() const{ if ( !IsNullable() ) return 0; return (FieldCount() + 7) / 8;}inline bool CBDB_BufferManager::TestNullBit(unsigned int n) const{ _ASSERT(IsNullable()); const unsigned char* buf = (unsigned char*) m_Buffer; unsigned char mask = (unsigned char) (1 << (n & 7)); const unsigned char* offs = buf + (n >> 3); return ((*offs) & mask) != 0;}inline void CBDB_BufferManager::SetNullBit(unsigned int n, bool value){ _ASSERT(IsNullable()); unsigned char* buf = (unsigned char*) m_Buffer; unsigned char mask = (unsigned char) (1 << (n & 7)); unsigned char* offs = buf + (n >> 3); (void) (value ? (*offs |= mask) : (*offs &= ~mask));}inline void CBDB_BufferManager::SetNull(unsigned int field_idx, bool value){ if ( !IsNullable() ) return; _ASSERT(field_idx < m_Fields.size()); SetNullBit(field_idx, value);}inline void CBDB_BufferManager::SetAllNull(){ _ASSERT(IsNullable()); unsigned char* buf = (unsigned char*) m_Buffer; for (size_t i = 0; i < m_NullSetSize; ++i) { *buf++ = (unsigned char) 0xFF; }}inline bool CBDB_BufferManager::IsNull(unsigned field_idx) const{ if ( !IsNullable() ) return false; _ASSERT(field_idx < m_Fields.size()); return TestNullBit(field_idx);}inline void CBDB_BufferManager::ArrangePtrsUnpacked(){ if ( !m_PackedSize ) return; if ( !IsPackable() ) { m_PackedSize = 0; return; } for (size_t i = 0; i < m_Fields.size(); ++i) { CBDB_Field& df = GetField((unsigned)i); df.SetBuffer(m_Ptrs[i]); } m_PackedSize = 0; // not packed}inline void CBDB_BufferManager::Clear(){ ::memset(m_Buffer, 0, m_BufferSize); ArrangePtrsUnpacked();}inlinevoid CBDB_BufferManager::CopyFieldsFrom(const CBDB_BufferManager& buf_mgr){ unsigned int field_count = min(FieldCount(), buf_mgr.FieldCount()); for (unsigned int i = 0; i < field_count; ++i) { CBDB_Field* fld = m_Fields[i]; fld->CopyFrom(buf_mgr.GetField(i)); }}inlinevoid CBDB_BufferManager::SetMinVal(unsigned int idx_from, unsigned int idx_to){ _ASSERT(idx_to <= FieldCount()); for ( ; idx_from < idx_to; ++idx_from) { CBDB_Field& fld = GetField(idx_from); fld.SetMinVal(); }}inlinevoid CBDB_BufferManager::SetMaxVal(unsigned int idx_from, unsigned int idx_to){ _ASSERT(idx_to <= FieldCount()); for ( ; idx_from < idx_to; ++idx_from) { CBDB_Field& fld = GetField(idx_from); fld.SetMaxVal(); }}inline void CBDB_BufferManager::SetFieldCompareLimit(unsigned int n_fields) { m_CompareLimit = n_fields; }inlineunsigned int CBDB_BufferManager::GetFieldCompareLimit() const { return m_CompareLimit; }// Delete all field objects bound to field buffer. // Should be used with extreme caution. After calling this buf object should// never be used again. All fields bound to the buffer must be dynamically// allocated.inline void DeleteFields(CBDB_BufferManager& buf){ for (unsigned int i = 0; i < buf.FieldCount(); ++i) { CBDB_Field* fld = &buf.GetField(i); delete fld; }}END_NCBI_SCOPE/* * =========================================================================== * $Log: bdb_types.hpp,v $ * Revision 1000.4 2004/06/01 18:37:08 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.36 * * Revision 1.36 2004/05/06 15:42:58 rotmistr * Changed Char type to UChar * * Revision 1.35 2004/05/05 19:18:21 rotmistr * CBDB_FieldChar added * * Revision 1.34 2004/04/26 16:43:59 ucko * Qualify inherited dependent names with this-> where needed by GCC 3.4. * * Revision 1.33 2004/03/08 13:30:14 kuznets * + ToString method * * Revision 1.32 2004/02/12 19:54:00 kuznets * + CBDB_BufferManager::GetFieldIndex() * * Revision 1.31 2004/02/04 17:02:34 kuznets * Commented operator char* for LString type to avoid ambuiguity * * Revision 1.30 2004/02/04 15:08:12 kuznets * + CBDB_FieldLString::operator string() const * * Revision 1.29 2003/12/23 22:31:31 ucko * Fix typo that could lead to stack overruns. * * Revision 1.28 2003/12/22 18:52:43 kuznets * Implemeneted length prefixed string field (CBDB_FieldLString) * * Revision 1.27 2003/12/10 19:13:37 kuznets * Added support of berkeley db transactions * * Revision 1.26 2003/11/06 14:05:08 kuznets * Dismissed auto_ptr from CBDB_BufferManager because of the delete / delete [] * mismatch. Gives errors in some memory profilers (valgrind). * * Revision 1.25 2003/10/28 14:19:19 kuznets * Calling DoubleToString without precision (%g format) for float and double * BDB fields (more accurate results for scientific data) * * Revision 1.24 2003/10/27 14:19:12 kuznets * + methods to convert BDB types to string * * Revision 1.23 2003/10/16 19:25:25 kuznets * Added field comparison limit to the fields manager * * Revision 1.22 2003/09/29 16:25:14 kuznets * Cleaned up warnings for 64-bit mode * * Revision 1.21 2003/09/26 20:45:57 kuznets * Comments cleaned up * * Revision 1.20 2003/09/17 13:30:28 kuznets * Put comparison functions into ncbi namespace. * * Revision 1.19 2003/09/16 15:14:48 kuznets * Added Int2 (short int) field type * * Revision 1.18 2003/09/15 15:49:25 kuznets * Fixed some compilation warnings(SunCC) * * Revision 1.17 2003/09/11 16:34:13 kuznets * Implemented byte-order independence. * * Revision 1.16 2003/08/26 18:50:26 kuznets * Added forward declararion of DB_ENV structure * * Revision 1.15 2003/07/31 16:39:32 dicuccio * Minor corrections: remove EXPORT specifier from pure inline classes; added * virtual dtor to abstract classes * * Revision 1.14 2003/07/25 15:46:47 kuznets * Added support for double field type * * Revision 1.13 2003/07/23 20:21:27 kuznets * Implemented new improved scheme for setting BerkeleyDB comparison function. * When table has non-segmented key the simplest(and fastest) possible function * is assigned (automatically without reloading CBDB_File::SetCmp function). * * Revision 1.12 2003/07/22 16:05:20 kuznets * Resolved operators ambiguity (GCC-MSVC conflict of interests) * * Revision 1.11 2003/07/22 15:48:34 kuznets * Fixed minor compilation issue with GCC * * Revision 1.10 2003/07/16 13:32:04 kuznets * Implemented CBDB_FieldString::SetString (part of IBDB_FieldConvert interface) * * Revision 1.9 2003/07/02 17:53:59 kuznets * Eliminated direct dependency from <db.h> * * Revision 1.8 2003/06/27 18:57:16 dicuccio * Uninlined strerror() adaptor. Changed to use #include<> instead of #include "" * * Revision 1.7 2003/06/10 20:07:27 kuznets * Fixed header files not to repeat information from the README file * * Revision 1.6 2003/06/03 18:50:09 kuznets * Added dll export/import specifications * * Revision 1.5 2003/05/27 16:13:21 kuznets * Destructors of key classes declared virtual to make GCC happy * * Revision 1.4 2003/05/22 19:31:51 kuznets * +CBDB_FieldString::operator= (const string& str) * * Revision 1.3 2003/05/05 20:14:41 kuznets * Added CBDB_BLobFile, CBDB_File changed to support more flexible data record * management. * * 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 /* BDB_TYPES__HPP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -