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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
// -*- Mode: C++; -*-
// Package : omniORB2
// omniObjKey.h Created on: 30/3/99
// Author : David Riddoch (djr)
//
// Copyright (C) 1996-1999 AT&T Research Cambridge
//
// This file is part of the omniORB library
//
// The omniORB library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA
//
//
// Description:
// Representation of an object key.
//
/*
$Log: omniObjKey.h,v $
Revision 1.1.2.1 1999/09/24 09:51:47 djr
Moved from omniORB2 + some new files.
*/
#ifndef __OMNIOBJKEY_H__
#define __OMNIOBJKEY_H__
#include <string.h>
class MemBufferedStream;
class NetBufferedStream;
// This is just big enough to fit a root poa key.
#define INLINE_BUF_SIZE 14
class omniObjKey {
public:
inline omniObjKey() : pd_key(pd_inline_buf), pd_size(0) {}
inline omniObjKey(const _CORBA_Octet* key, int size)
: pd_key(pd_inline_buf), pd_size(size) {
if( size > INLINE_BUF_SIZE ) pd_key = new _CORBA_Octet[size];
memcpy(pd_key, key, size);
}
// Copies <key>.
inline omniObjKey(_CORBA_Octet* key, int size)
: pd_key(key), pd_size(size) {
if( size <= INLINE_BUF_SIZE ) {
pd_key = pd_inline_buf;
memcpy(pd_key, key, size);
delete[] key;
}
}
// Consumes <key>.
inline omniObjKey(omniObjKey& k, int release)
: pd_size(k.pd_size) {
if( pd_size <= INLINE_BUF_SIZE ) {
pd_key = pd_inline_buf;
}
else if( release ) {
//assert(k.pd_key != k.pd_inline_buf);
pd_key = k.pd_key;
k.pd_key = k.pd_inline_buf;
k.pd_size = 0;
return;
}
else {
pd_key = new _CORBA_Octet[pd_size];
}
memcpy(pd_key, k.pd_key, pd_size);
}
// If <release>, may (or may not) grab the key storage
// (if any) from <k>. ie. On return, <k> may be
// empty.
inline ~omniObjKey() {
if( pd_key != pd_inline_buf ) delete[] pd_key;
}
inline const _CORBA_Octet* key() const { return pd_key; }
inline int size() const { return pd_size; }
inline int is_equal(const _CORBA_Octet* key, int keysize) const {
return keysize == pd_size && !memcmp(key, pd_key, keysize);
}
inline void set_size(int size) {
if( size > pd_size && size > INLINE_BUF_SIZE ) {
if( pd_key != pd_inline_buf ) delete[] pd_key;
pd_key = new _CORBA_Octet[size];
}
pd_size = size;
}
inline _CORBA_Octet* write_key() { return pd_key; }
inline void copy(const _CORBA_Octet* key, int keysize) {
set_size(keysize);
memcpy(pd_key, key, keysize);
}
#if 0
inline void consume(_CORBA_Octet* key, int keysize) {
if( pd_key != pd_inline_buf ) delete[] pd_key;
pd_key = key;
pd_size = keysize;
}
#endif
inline _CORBA_Octet* return_key() {
if( pd_key != pd_inline_buf ) {
_CORBA_Octet* tmp = pd_key;
pd_key = pd_inline_buf;
pd_size = 0;
return tmp;
}
_CORBA_Octet* tmp = new _CORBA_Octet[pd_size];
memcpy(tmp, pd_key, pd_size);
return tmp;
}
private:
_CORBA_Octet pd_inline_buf[INLINE_BUF_SIZE];
_CORBA_Octet* pd_key;
int pd_size;
};
#undef INLINE_BUF_SIZE
#endif // __OMNIOBJREF_H__
|