module firebird_dbkey; private import ibase; /* private import firebird_util; private import firebird_database; private import firebird_date; private import firebird_transaction; private import std.c.string; */ private import std.math; class DBKey { private: string mDBKey; // Stores the binary DBKey string mString;// String(temporary) representation of it public: void Clear() { mDBKey.length = 0; mString.length = 0; } int Size() { return cast(int)mDBKey.length; } void SetKey(void *key, int size) { if(key == null) throw new Exception("DBKey::SetKey Null DBKey reference detected."); if(size <= 0 ||((size >> 3) << 3) != size) throw new Exception("DBKey::SetKey Invalid DBKey size."); mDBKey.length = size; mDBKey = cast(string)key[0..size].idup; mString.length = 0; } void GetKey(void* key, int size) { if(mDBKey.length == 0) throw new Exception("DBKey::GetKey DBKey not assigned."); if(key == null) throw new Exception("DBKey::GetKey Null DBKey reference detected."); if(size != cast(int)mDBKey.length) throw new Exception("DBKey::GetKey Incompatible DBKey size detected."); //mDBKey.copy(cast(char*)key, mDBKey.length); key = cast(void*) mDBKey.idup; } string AsString() { if(mDBKey.length == 0) throw new Exception("DBKey::GetString DBKey not assigned."); /* if(mString.length == 0) { string hexkey; hexkey.setf(std::ios::hex, std::ios::basefield); hexkey.setf(std::ios::uppercase); const uint* key = reinterpret_cast(mDBKey.data()); int n = cast(int)mDBKey.length / 8; for(int i = 0; i < n; i++) { if(i != 0) hexkey<< "-"; hexkey<< std::setw(4)<< key[i*2]<< ":"; hexkey<< std::setw(8)<< key[i*2+1]; } mString = hexkey.str(); } */ return mString; } this(ref DBKey copied) { mDBKey = copied.mDBKey; mString = copied.mString; } DBKey opAssign(DBKey *assigned) { mDBKey = assigned.mDBKey; mString = assigned.mString; return this; } this() { } ~this() { } };