/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK *****
* This Original Code has been modified by IBM Corporation.
* Modifications made by IBM described herein are
* Copyright (c) International Business Machines
* Corporation, 2000
*
* Modifications to Mozilla code or documentation
* identified per MPL Section 3.3
*
* Date Modified by Description of modification
* 04/20/2000 IBM Corp. Added PR_CALLBACK for Optlink use in OS2
*/
#include <string.h>
#include "prmem.h"
#include "prlog.h"
#include "nsHashtable.h"
#include "nsReadableUtils.h"
#include "nsIObjectInputStream.h"
#include "nsIObjectOutputStream.h"
#include "nsCRT.h"
{
void* value;
};
//
// Key operations
//
const void* key)
{
return PR_TRUE;
}
{
}
PR_STATIC_CALLBACK(void)
{
// leave it up to the nsHashKey destructor to free the "value"
// sanity's sake
}
};
//
// Enumerator callback
//
struct _HashEnumerateArgs {
void* arg;
};
{
case kHashEnumerateNext:
return PL_DHASH_NEXT;
case kHashEnumerateRemove:
return PL_DHASH_REMOVE;
}
return PL_DHASH_STOP;
}
//
// HashKey
//
{
}
{
NS_NOTREACHED("oops");
return NS_ERROR_NOT_IMPLEMENTED;
}
{
// make sure we detect this later
if (!result)
if (threadSafe) {
mLock = PR_NewLock();
// Cannot create a lock. If running on a multiprocessing system
// we are sure to die.
}
}
}
nsHashtable::~nsHashtable() {
if (mHashtable.ops)
}
{
if (!mHashtable.ops)
return PR_FALSE;
return exists;
}
{
// shouldn't be adding an item during enumeration
if (entry) { // don't return early, or you'll be locked!
// existing entry, need to boot the old value
} else {
// new entry (leave res == null)
}
}
return res;
}
{
return ret;
}
{
// shouldn't be adding an item during enumeration
// need to see if the entry is actually there, in order to get the
// old value for the result
void *res;
if (PL_DHASH_ENTRY_IS_FREE(entry)) {
// value wasn't in the table anyway
} else {
}
return res;
}
// XXX This method was called _hashEnumerateCopy, but it didn't copy the element!
// I don't know how this was supposed to work since the elements are neither copied
// nor refcounted.
{
return PL_DHASH_NEXT;
}
{
return newHashTable;
}
{
if (!mHashtable.ops) return;
}
{
if (thunk) {
}
return PL_DHASH_REMOVE;
}
}
{
if (!mHashtable.ops) return;
if (!destroyFunc) {
} else {
}
}
// nsISerializable helpers
{
if (NS_SUCCEEDED(rv)) {
if (threadSafe) {
mLock = PR_NewLock();
if (!mLock)
}
if (NS_SUCCEEDED(rv)) {
if (NS_SUCCEEDED(rv)) {
if (!status) {
} else {
void *data;
if (NS_SUCCEEDED(rv)) {
} else {
// XXXbe must we clone key? can't we hand off
}
break;
}
}
}
}
}
}
}
struct WriteEntryArgs {
};
{
if (NS_SUCCEEDED(rv))
return PR_TRUE;
}
{
if (!mHashtable.ops)
return NS_ERROR_OUT_OF_MEMORY;
}
////////////////////////////////////////////////////////////////////////////////
{
}
{
return rv;
}
{
}
{
}
////////////////////////////////////////////////////////////////////////////////
// Copy Constructor
// We need to free mStr if the object is passed with mOwnership as OWN. As the
// destructor here is freeing mStr in that case, mStr is NOT getting leaked here.
{
if (mOwnership != NEVER_OWN) {
if (!str) {
// Pray we don't dangle!
} else {
// Use memcpy in case there are embedded NULs.
mOwnership = OWN;
}
}
#ifdef DEBUG
#endif
}
{
#ifdef DEBUG
#endif
}
{
#ifdef DEBUG
#endif
}
{
#ifdef DEBUG
#endif
}
nsCStringKey::~nsCStringKey(void)
{
if (mOwnership == OWN)
}
{
}
{
return PR_FALSE;
}
{
if (mOwnership == NEVER_OWN)
// Since this might hold binary data OR a string, we ensure that the
// clone string is zero terminated, but don't assume that the source
// string was so terminated.
return NULL;
}
{
if (NS_SUCCEEDED(rv))
}
{
}
////////////////////////////////////////////////////////////////////////////////
// Copy Constructor
// We need to free mStr if the object is passed with mOwnership as OWN. As the
// destructor here is freeing mStr in that case, mStr is NOT getting leaked here.
{
if (mOwnership != NEVER_OWN) {
if (!str) {
// Pray we don't dangle!
} else {
// Use memcpy in case there are embedded NULs.
mOwnership = OWN;
}
}
#ifdef DEBUG
#endif
}
{
#ifdef DEBUG
#endif
}
{
#ifdef DEBUG
#endif
}
{
#ifdef DEBUG
#endif
}
nsStringKey::~nsStringKey(void)
{
if (mOwnership == OWN)
}
{
}
{
return PR_FALSE;
}
{
if (mOwnership == NEVER_OWN)
return NULL;
}
{
if (NS_SUCCEEDED(rv))
}
{
}
////////////////////////////////////////////////////////////////////////////////
// nsObjectHashtable: an nsHashtable where the elements are C++ objects to be
// deleted
void* cloneElementClosure,
void* destroyElementClosure,
{
}
{
Reset();
}
{
void* newElement =
if (newElement == nsnull)
return PL_DHASH_STOP;
return PL_DHASH_NEXT;
}
{
if (mLock)
return newHashTable;
}
void
{
}
{
if (value && mDestroyElementFun)
return PR_FALSE;
}
////////////////////////////////////////////////////////////////////////////////
// nsSupportsHashtable: an nsHashtable where the elements are nsISupports*
{
return PR_TRUE;
}
{
}
// Return true if we overwrote something
{
if (value) // pass own the ownership to the caller
else // the caller doesn't care, we do
}
{
if (!data)
return nsnull;
return element;
}
// Return true if we found something (useful for checks)
{
if (value) // caller wants it
else // caller doesn't care, we do
}
{
return PL_DHASH_NEXT;
}
{
return newHashTable;
}
void
{
nsHashtable::Reset();
}
////////////////////////////////////////////////////////////////////////////////