[go: up one dir, main page]

Menu

[r110]: / trunk / core / dbkey.cpp  Maximize  Restore  History

Download this file

127 lines (106 with data), 3.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
///////////////////////////////////////////////////////////////////////////////
//
// File : $Id$
// Subject : IBPP, DBKey class implementation
//
///////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright 2000-2007 T.I.P. Group S.A. and the IBPP Team (www.ibpp.org)
//
// The contents of this file are subject to the IBPP License (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at http://www.ibpp.org or in the 'license.txt'
// file which must have been distributed along with this file.
//
// This software, distributed under the License, is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
///////////////////////////////////////////////////////////////////////////////
//
// COMMENTS
// * Tabulations should be set every four characters when editing this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifdef _MSC_VER
#pragma warning(disable: 4786 4996)
#ifndef _DEBUG
#pragma warning(disable: 4702)
#endif
#endif
#include "_ibpp.h"
#ifdef HAS_HDRSTOP
#pragma hdrstop
#endif
#include <iostream>
#include <sstream>
#include <iomanip>
using namespace ibpp_internals;
// Private implementation
// Public implementation
void IBPP::DBKey::Clear()
{
mDBKey.erase();
mString.erase();
}
void IBPP::DBKey::SetKey(const void* key, int size)
{
if (key == 0)
throw LogicExceptionImpl("IBPP::DBKey::SetKey", _("Null DBKey reference detected."));
if (size <= 0 || ((size >> 3) << 3) != size)
throw LogicExceptionImpl("IBPP::DBKey::SetKey", _("Invalid DBKey size."));
mDBKey.assign((const char*)key, (size_t)size);
mString.erase();
}
void IBPP::DBKey::GetKey(void* key, int size) const
{
if (mDBKey.empty())
throw LogicExceptionImpl("IBPP::DBKey::GetKey", _("DBKey not assigned."));
if (key == 0)
throw LogicExceptionImpl("IBPP::DBKey::GetKey", _("Null DBKey reference detected."));
if (size != (int)mDBKey.size())
throw LogicExceptionImpl("IBPP::DBKey::GetKey", _("Incompatible DBKey size detected."));
mDBKey.copy((char*)key, mDBKey.size());
}
const char* IBPP::DBKey::AsString() const
{
if (mDBKey.empty())
throw LogicExceptionImpl("IBPP::DBKey::GetString", _("DBKey not assigned."));
if (mString.empty())
{
std::ostringstream hexkey;
//lint -e{641} Converting enum to int: expected and valid
{
hexkey.setf(std::ios::hex, std::ios::basefield);
hexkey.setf(std::ios::uppercase);
}
const uint32_t* key = reinterpret_cast<const uint32_t*>(mDBKey.data());
int n = (int)mDBKey.size() / 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.c_str();
}
IBPP::DBKey::DBKey(const DBKey& copied)
{
mDBKey = copied.mDBKey;
mString = copied.mString;
}
IBPP::DBKey& IBPP::DBKey::operator=(const IBPP::DBKey& assigned)
{
if (&assigned != this)
{
mDBKey = assigned.mDBKey;
mString = assigned.mString;
}
return *this;
}
//
// EOF
//