1 ///////////////////////////////////////////////////////////////////////////////
\r
3 // File : $Id: dbkey.cpp,v 1.1 2007/05/05 17:00:42 faust Exp $
\r
4 // Subject : IBPP, DBKey class implementation
\r
6 ///////////////////////////////////////////////////////////////////////////////
\r
8 // (C) Copyright 2000-2006 T.I.P. Group S.A. and the IBPP Team (www.ibpp.org)
\r
10 // The contents of this file are subject to the IBPP License (the "License");
\r
11 // you may not use this file except in compliance with the License. You may
\r
12 // obtain a copy of the License at http://www.ibpp.org or in the 'license.txt'
\r
13 // file which must have been distributed along with this file.
\r
15 // This software, distributed under the License, is distributed on an "AS IS"
\r
16 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
\r
17 // License for the specific language governing rights and limitations
\r
18 // under the License.
\r
20 ///////////////////////////////////////////////////////////////////////////////
\r
23 // * Tabulations should be set every four characters when editing this file.
\r
25 ///////////////////////////////////////////////////////////////////////////////
\r
28 #pragma warning(disable: 4786 4996)
\r
30 #pragma warning(disable: 4702)
\r
44 using namespace ibpp_internals;
\r
46 // Private implementation
\r
48 // Public implementation
\r
50 void IBPP::DBKey::Clear()
\r
56 void IBPP::DBKey::SetKey(const void* key, int size)
\r
59 throw LogicExceptionImpl("IBPP::DBKey::SetKey", _("Null DBKey reference detected."));
\r
60 if (size <= 0 || ((size >> 3) << 3) != size)
\r
61 throw LogicExceptionImpl("IBPP::DBKey::SetKey", _("Invalid DBKey size."));
\r
63 mDBKey.assign((const char*)key, (size_t)size);
\r
67 void IBPP::DBKey::GetKey(void* key, int size) const
\r
70 throw LogicExceptionImpl("IBPP::DBKey::GetKey", _("DBKey not assigned."));
\r
72 throw LogicExceptionImpl("IBPP::DBKey::GetKey", _("Null DBKey reference detected."));
\r
73 if (size != (int)mDBKey.size())
\r
74 throw LogicExceptionImpl("IBPP::DBKey::GetKey", _("Incompatible DBKey size detected."));
\r
76 mDBKey.copy((char*)key, mDBKey.size());
\r
79 const char* IBPP::DBKey::AsString() const
\r
82 throw LogicExceptionImpl("IBPP::DBKey::GetString", _("DBKey not assigned."));
\r
84 if (mString.empty())
\r
86 std::ostringstream hexkey;
\r
87 hexkey.setf(std::ios::hex, std::ios::basefield);
\r
88 hexkey.setf(std::ios::uppercase);
\r
90 const uint32_t* key = reinterpret_cast<const uint32_t*>(mDBKey.data());
\r
91 int n = (int)mDBKey.size() / 8;
\r
92 for (int i = 0; i < n; i++)
\r
94 if (i != 0) hexkey<< "-";
\r
95 hexkey<< std::setw(4)<< key[i*2]<< ":";
\r
96 hexkey<< std::setw(8)<< key[i*2+1];
\r
99 mString = hexkey.str();
\r
102 return mString.c_str();
\r
105 IBPP::DBKey::DBKey(const DBKey& copied)
\r
107 mDBKey = copied.mDBKey;
\r
108 mString = copied.mString;
\r
111 IBPP::DBKey& IBPP::DBKey::operator=(const IBPP::DBKey& assigned)
\r
113 mDBKey = assigned.mDBKey;
\r
114 mString = assigned.mString;
\r