📄 bdb_types.hpp
字号:
if (sizeof(T) == 4) { CByteSwap::PutFloat((unsigned char*)this->GetBuffer(), val); } else if (sizeof(T) == 8) { CByteSwap::PutDouble((unsigned char*)this->GetBuffer(), val); } else { _ASSERT(0); } } else { ::memcpy(this->GetBuffer(), &val, sizeof(T)); } this->SetNotNull(); } virtual void SetInt (int val) { Set((T) val); } virtual void SetUint (unsigned int val) { Set((T) val); } virtual void SetString (const char* val) { double v = ::atof(val); Set((T) v); } virtual void SetStdString(const string& str) { SetString(str.c_str()); } virtual void SetFloat (float val) { Set((T) val); } virtual void SetDouble(double val) { Set((T) val); } virtual void SetMinVal() { Set(numeric_limits<T>::min()); } virtual void SetMaxVal() { Set(numeric_limits<T>::max()); }};/// Int4 field type///class NCBI_BDB_EXPORT CBDB_FieldInt4 : public CBDB_FieldSimpleInt<Int4>{public: const CBDB_FieldInt4& operator= (Int4 val) { Set(val); return *this; } const CBDB_FieldInt4& operator= (const CBDB_FieldInt4& val) { Set(val); return *this; } virtual CBDB_Field* Construct(size_t /*buf_size*/) const { return new CBDB_FieldInt4(); } Int4 Get() const { Int4 v; if (IsByteSwapped()) { v = CByteSwap::GetInt4((unsigned char*)GetBuffer()); } else { ::memcpy(&v, GetBuffer(), sizeof(Int4)); } return v; } virtual string GetString() const { Int4 v = Get(); return NStr::IntToString(v); } virtual void ToString(string& str) const { Int4 v = Get(); NStr::IntToString(str, v); } operator Int4() const { return Get(); } virtual BDB_CompareFunction GetCompareFunction(bool byte_swapped) const { if (byte_swapped) return BDB_ByteSwap_IntCompare; return BDB_IntCompare; } virtual int Compare(const void* p1, const void* p2, bool byte_swapped) const { if (!byte_swapped) return CBDB_FieldSimpleInt<Int4>::Compare(p1, p2, byte_swapped); Int4 v1, v2; v1 = CByteSwap::GetInt4((unsigned char*)p1); v2 = CByteSwap::GetInt4((unsigned char*)p2); if (v1 < v2) return -1; if (v2 < v1) return 1; return 0; }};/// Int2 field type///class NCBI_BDB_EXPORT CBDB_FieldInt2 : public CBDB_FieldSimpleInt<Int2>{public: const CBDB_FieldInt2& operator= (Int2 val) { Set(val); return *this; } const CBDB_FieldInt2& operator= (const CBDB_FieldInt2& val) { Set(val); return *this; } virtual CBDB_Field* Construct(size_t /*buf_size*/) const { return new CBDB_FieldInt2(); } Int2 Get() const { Int2 v; if (IsByteSwapped()) { v = CByteSwap::GetInt2((unsigned char*)GetBuffer()); } else { ::memcpy(&v, GetBuffer(), sizeof(Int2)); } return v; } virtual string GetString() const { Int4 v = Get(); return NStr::IntToString(v); } virtual void ToString(string& str) const { Int4 v = Get(); NStr::IntToString(str, v); } operator Int2() const { return Get(); } virtual BDB_CompareFunction GetCompareFunction(bool byte_swapped) const { if (byte_swapped) return BDB_ByteSwap_Int2Compare; return BDB_Int2Compare; } virtual int Compare(const void* p1, const void* p2, bool byte_swapped) const { if (!byte_swapped) return CBDB_FieldSimpleInt<Int2>::Compare(p1, p2, byte_swapped); Int2 v1, v2; v1 = CByteSwap::GetInt2((unsigned char*)p1); v2 = CByteSwap::GetInt2((unsigned char*)p2); if (v1 < v2) return -1; if (v2 < v1) return 1; return 0; }};/// Char field type///class CBDB_FieldUChar:public CBDB_FieldSimpleInt<unsigned char>{public: const CBDB_FieldUChar& operator = (unsigned char val) { Set(val); return *this; } const CBDB_FieldUChar& operator = (const CBDB_FieldUChar& val) { Set(val); return *this; } virtual CBDB_Field * Construct(size_t) const { return new CBDB_FieldUChar(); } unsigned char Get() const { return *(const unsigned char*)GetBuffer(); } operator char () const { return Get(); } virtual string GetString() const { return string(1, Get()); } virtual void ToString(string& s) const { s.assign(1, Get()); } virtual BDB_CompareFunction GetCompareFunction(bool) const { return BDB_UCharCompare; } virtual int Compare(const void * p1, const void * p2, bool) const { const unsigned char& c1 = *(const unsigned char *)p1; const unsigned char& c2 = *(const unsigned char *)p2; return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0; }};/// Uint4 field type///class NCBI_BDB_EXPORT CBDB_FieldUint4 : public CBDB_FieldSimpleInt<Uint4>{public: const CBDB_FieldUint4& operator= (Uint4 val) { Set(val); return *this; } const CBDB_FieldUint4& operator= (const CBDB_FieldUint4& val) { Set(val); return *this; } virtual CBDB_Field* Construct(size_t /*buf_size*/) const { return new CBDB_FieldUint4(); } Uint4 Get() const { Uint4 v; if (IsByteSwapped()) { v = (Uint4)CByteSwap::GetInt4((unsigned char*)GetBuffer()); } else { ::memcpy(&v, GetBuffer(), sizeof(Uint4)); } return v; } virtual string GetString() const { Uint4 v = Get(); return NStr::UIntToString(v); } virtual void ToString(string& str) const { Uint4 v = Get(); NStr::UIntToString(str, v); } operator Uint4() const { return Get(); } virtual BDB_CompareFunction GetCompareFunction(bool byte_swapped) const { if (byte_swapped) return BDB_ByteSwap_UintCompare; return BDB_UintCompare; } virtual int Compare(const void* p1, const void* p2, bool byte_swapped) const { if (!byte_swapped) return CBDB_FieldSimpleInt<Uint4>::Compare(p1, p2, byte_swapped); Uint4 v1, v2; v1 = (Uint4)CByteSwap::GetInt4((unsigned char*)p1); v2 = (Uint4)CByteSwap::GetInt4((unsigned char*)p2); if (v1 < v2) return -1; if (v2 < v1) return 1; return 0; }};/// Float field type///class NCBI_BDB_EXPORT CBDB_FieldFloat : public CBDB_FieldSimpleFloat<float>{public: const CBDB_FieldFloat& operator= (float val) { Set(val); return *this; } const CBDB_FieldFloat& operator= (const CBDB_FieldFloat& val) { Set(val); return *this; } virtual CBDB_Field* Construct(size_t /*buf_size*/) const { return new CBDB_FieldFloat(); } float Get() const { float v; if (IsByteSwapped()) { v = CByteSwap::GetFloat((unsigned char*)GetBuffer()); } else { ::memcpy(&v, GetBuffer(), sizeof(float)); } return v; } virtual string GetString() const { double v = Get(); return NStr::DoubleToString(v); } virtual void ToString(string& str) const { double v = Get(); NStr::DoubleToString(str, v); } operator float() const { return Get(); } virtual BDB_CompareFunction GetCompareFunction(bool byte_swapped) const { if (byte_swapped) return BDB_ByteSwap_FloatCompare; return BDB_FloatCompare; } virtual int Compare(const void* p1, const void* p2, bool byte_swapped) const { if (!byte_swapped) return CBDB_FieldSimpleFloat<float>::Compare(p1, p2, byte_swapped); float v1, v2; v1 = CByteSwap::GetFloat((unsigned char*)p1); v2 = CByteSwap::GetFloat((unsigned char*)p2); if (v1 < v2) return -1; if (v2 < v1) return 1; return 0; }};/// Double precision floating point field type///class NCBI_BDB_EXPORT CBDB_FieldDouble : public CBDB_FieldSimpleFloat<double>{public: const CBDB_FieldDouble& operator= (double val) { Set(val); return *this; } const CBDB_FieldDouble& operator= (const CBDB_FieldDouble& val) { Set(val); return *this; } virtual CBDB_Field* Construct(size_t /*buf_size*/) const { return new CBDB_FieldDouble(); } double Get() const { double v; if (IsByteSwapped()) { v = CByteSwap::GetDouble((unsigned char*)GetBuffer()); } else { ::memcpy(&v, GetBuffer(), sizeof(double)); } return v; } virtual string GetString() const { double v = Get(); return NStr::DoubleToString(v); } virtual void ToString(string& str) const { double v = Get(); NStr::DoubleToString(str, v); } operator double() const { return Get(); } virtual BDB_CompareFunction GetCompareFunction(bool byte_swapped) const { if (byte_swapped) return BDB_ByteSwap_DoubleCompare; return BDB_DoubleCompare; } virtual int Compare(const void* p1, const void* p2, bool byte_swapped) const { if (!byte_swapped) return CBDB_FieldSimpleFloat<double>::Compare(p1, p2, byte_swapped); double v1, v2; v1 = CByteSwap::GetDouble((unsigned char*)p1); v2 = CByteSwap::GetDouble((unsigned char*)p2); if (v1 < v2) return -1; if (v2 < v1) return 1; return 0; }};////// String field type///class NCBI_BDB_EXPORT CBDB_FieldStringBase : public CBDB_Field{public:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -