]> git.stg.codes - stg.git/blobdiff - libs/ibpp/dbkey.cpp
Port to CMake, get rid of os_int.h.
[stg.git] / libs / ibpp / dbkey.cpp
diff --git a/libs/ibpp/dbkey.cpp b/libs/ibpp/dbkey.cpp
new file mode 100644 (file)
index 0000000..080b4d7
--- /dev/null
@@ -0,0 +1,120 @@
+///////////////////////////////////////////////////////////////////////////////\r
+//\r
+//     File    : $Id: dbkey.cpp,v 1.1 2007/05/05 17:00:42 faust Exp $\r
+//     Subject : IBPP, DBKey class implementation\r
+//\r
+///////////////////////////////////////////////////////////////////////////////\r
+//\r
+//     (C) Copyright 2000-2006 T.I.P. Group S.A. and the IBPP Team (www.ibpp.org)\r
+//\r
+//     The contents of this file are subject to the IBPP License (the "License");\r
+//     you may not use this file except in compliance with the License.  You may\r
+//     obtain a copy of the License at http://www.ibpp.org or in the 'license.txt'\r
+//     file which must have been distributed along with this file.\r
+//\r
+//     This software, distributed under the License, is distributed on an "AS IS"\r
+//     basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the\r
+//     License for the specific language governing rights and limitations\r
+//     under the License.\r
+//\r
+///////////////////////////////////////////////////////////////////////////////\r
+//\r
+//     COMMENTS\r
+//     * Tabulations should be set every four characters when editing this file.\r
+//\r
+///////////////////////////////////////////////////////////////////////////////\r
+\r
+#ifdef _MSC_VER\r
+#pragma warning(disable: 4786 4996)\r
+#ifndef _DEBUG\r
+#pragma warning(disable: 4702)\r
+#endif\r
+#endif\r
+\r
+#include "_ibpp.h"\r
+\r
+#ifdef HAS_HDRSTOP\r
+#pragma hdrstop\r
+#endif\r
+\r
+#include <iostream>\r
+#include <sstream>\r
+#include <iomanip>\r
+\r
+using namespace ibpp_internals;\r
+\r
+//     Private implementation\r
+\r
+//     Public implementation\r
+\r
+void IBPP::DBKey::Clear()\r
+{\r
+       mDBKey.erase();\r
+       mString.erase();\r
+}\r
+\r
+void IBPP::DBKey::SetKey(const void* key, int size)\r
+{\r
+       if (key == 0)\r
+               throw LogicExceptionImpl("IBPP::DBKey::SetKey", _("Null DBKey reference detected."));\r
+       if (size <= 0 || ((size >> 3) << 3) != size)\r
+               throw LogicExceptionImpl("IBPP::DBKey::SetKey", _("Invalid DBKey size."));\r
+\r
+       mDBKey.assign((const char*)key, (size_t)size);\r
+       mString.erase();\r
+}\r
+\r
+void IBPP::DBKey::GetKey(void* key, int size) const\r
+{\r
+       if (mDBKey.empty())\r
+               throw LogicExceptionImpl("IBPP::DBKey::GetKey", _("DBKey not assigned."));\r
+       if (key == 0)\r
+               throw LogicExceptionImpl("IBPP::DBKey::GetKey", _("Null DBKey reference detected."));\r
+       if (size != (int)mDBKey.size())\r
+               throw LogicExceptionImpl("IBPP::DBKey::GetKey", _("Incompatible DBKey size detected."));\r
+\r
+       mDBKey.copy((char*)key, mDBKey.size());\r
+}\r
+\r
+const char* IBPP::DBKey::AsString() const\r
+{\r
+       if (mDBKey.empty())\r
+               throw LogicExceptionImpl("IBPP::DBKey::GetString", _("DBKey not assigned."));\r
+\r
+       if (mString.empty())\r
+       {\r
+               std::ostringstream hexkey;\r
+               hexkey.setf(std::ios::hex, std::ios::basefield);\r
+               hexkey.setf(std::ios::uppercase);\r
+\r
+               const uint32_t* key = reinterpret_cast<const uint32_t*>(mDBKey.data());\r
+               int n = (int)mDBKey.size() / 8;\r
+               for (int i = 0; i < n; i++)\r
+               {\r
+                       if (i != 0) hexkey<< "-";\r
+                       hexkey<< std::setw(4)<< key[i*2]<< ":";\r
+                       hexkey<< std::setw(8)<< key[i*2+1];\r
+               }\r
+\r
+               mString = hexkey.str();\r
+       }\r
+\r
+       return mString.c_str();\r
+}\r
+\r
+IBPP::DBKey::DBKey(const DBKey& copied)\r
+{\r
+       mDBKey = copied.mDBKey;\r
+       mString = copied.mString;\r
+}\r
+\r
+IBPP::DBKey& IBPP::DBKey::operator=(const IBPP::DBKey& assigned)\r
+{\r
+       mDBKey = assigned.mDBKey;\r
+       mString = assigned.mString;\r
+       return *this;\r
+}\r
+\r
+//\r
+//     EOF\r
+//\r