File Removed.

git-svn-id: svn://10.0.0.236/trunk@51554 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
scc%netscape.com
1999-10-22 21:02:15 +00:00
parent bf8979df4c
commit 866732108c
2 changed files with 0 additions and 386 deletions

View File

@@ -1,153 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIVariant_h___
#define nsIVariant_h___
#include "nsISupports.h"
#include "nscore.h"
#include "prtime.h"
enum nsVariantType {
// primitive values
nsVariantType_PRBool,
nsVariantType_PRInt16,
nsVariantType_PRUint16,
nsVariantType_PRInt32,
nsVariantType_PRUint32,
nsVariantType_PRInt64,
nsVariantType_PRUint64,
nsVariantType_float,
nsVariantType_PRFloat64,
nsVariantType_PRTime,
// only pointers after this point -- these will be deleted
// when the variant is deleted
nsVariantType_voidPtr,
nsVariantType_charPtr,
nsVariantType_PRUnicharPtr
};
class nsVariantValue {
public:
nsVariantValue() {}
// nsVariantValue(PRBool value) { mUnion._PRBool = value; }
nsVariantValue(PRInt16 value) { mUnion._PRInt16 = value; }
nsVariantValue(PRUint16 value) { mUnion._PRUint16 = value; }
nsVariantValue(PRInt32 value) { mUnion._PRInt32 = value; }
nsVariantValue(PRUint32 value) { mUnion._PRUint32 = value; }
nsVariantValue(PRInt64 value) { mUnion._PRInt64 = value; }
#if !defined(XP_MAC) && !defined(SUNOS4) && !defined(_SCO_DS) && !(defined(__QNX__) && !defined(__QNXNTO__))
nsVariantValue(PRUint64 value) { mUnion._PRUint64 = value; }
#endif
nsVariantValue(float value) { mUnion._float = value; }
nsVariantValue(PRFloat64 value) { mUnion._PRFloat64 = value; }
// nsVariantValue(PRTime value) { mUnion._PRTime = value; }
nsVariantValue(void* value) { mUnion._voidPtr = value; }
nsVariantValue(char* value) { mUnion._charPtr = value; }
nsVariantValue(PRUnichar* value) { mUnion._PRUnicharPtr = value; }
// operator PRBool() { return mUnion._PRBool; }
operator PRInt16() { return mUnion._PRInt16; }
operator PRUint16() { return mUnion._PRUint16; }
operator PRInt32() { return mUnion._PRInt32; }
operator PRUint32() { return mUnion._PRUint32; }
operator PRInt64() { return mUnion._PRInt64; }
#if !defined(XP_MAC) && !defined(SUNOS4) && !defined(_SCO_DS) && !(defined(__QNX__) && !defined(__QNXNTO__))
operator PRUint64() { return mUnion._PRUint64; }
#endif
operator float() { return mUnion._float; }
operator PRFloat64() { return mUnion._PRFloat64; }
// operator PRTime() { return mUnion._PRTime; }
operator void*() { return mUnion._voidPtr; }
operator const char*() { return mUnion._charPtr; }
operator const PRUnichar*() { return mUnion._PRUnicharPtr; }
friend class nsVariant;
protected:
union nsVariantValueUnion {
PRBool _PRBool;
PRInt16 _PRInt16;
PRUint16 _PRUint16;
PRInt32 _PRInt32;
PRUint32 _PRUint32;
PRInt64 _PRInt64;
PRUint64 _PRUint64;
float _float;
PRFloat64 _PRFloat64;
PRTime _PRTime;
void* _voidPtr;
char* _charPtr;
PRUnichar* _PRUnicharPtr;
};
nsVariantValueUnion mUnion;
};
#define NS_IVARIANT_IID \
{ /* 3b5799d0-dc28-11d2-9311-00e09805570f */ \
0x3b5799d0, \
0xdc28, \
0x11d2, \
{0x93, 0x11, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
}
class nsIVariant : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IVARIANT_IID; return iid; }
/**
* Gets the type and value of a Variant.
* When the value is a pointer type, the pointer points into the variant's
* internal storage. It is the caller's responsibility to copy.
*/
NS_IMETHOD GetValue(nsVariantType *type, nsVariantValue *value) = 0;
/**
* Gets the value of a Variant.
* @return NS_ERROR_FAILURE if the value is not of the expected type.
* When the value is a pointer type, the pointer points into the variant's
* internal storage. It is the caller's responsibility to copy.
*/
NS_IMETHOD GetValue(nsVariantType expectedType, nsVariantValue *value) = 0;
/**
* Sets the type and value of a Variant.
* When the value is a pointer type, the variant takes ownership of the
* pointer. When the variant is released, the pointer will be deleted.
*/
NS_IMETHOD SetValue(nsVariantType type, nsVariantValue& value) = 0;
/**
* Determines whether two variants have the same internal type and value.
* @return NS_OK if they are equal
* @return NS_COMFALSE if not, or if the other parameter is not an nsIVariant
*/
NS_IMETHOD Equals(nsISupports* other) = 0;
#ifdef NS_DEBUG
NS_IMETHOD GetDescription(char* *result) = 0;
#endif
};
extern NS_COM nsresult
NS_NewIVariant(nsVariantType initialType, nsVariantValue& initialValue,
nsIVariant* *result);
#endif // nsIVariant_h___

View File

@@ -1,233 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsIVariant.h"
#include "nsCRT.h"
#ifdef NS_DEBUG
#include "prprf.h"
#endif
class nsVariant : public nsIVariant {
public:
NS_DECL_ISUPPORTS
// nsIVariant methods:
NS_IMETHOD GetValue(nsVariantType *type, nsVariantValue *value);
NS_IMETHOD GetValue(nsVariantType expectedType, nsVariantValue *value);
NS_IMETHOD SetValue(nsVariantType type, nsVariantValue& value);
NS_IMETHOD Equals(nsISupports* other);
#ifdef NS_DEBUG
NS_IMETHOD GetDescription(char* *result);
#endif
// nsVariant methods:
nsVariant(nsVariantType type, nsVariantValue& value);
virtual ~nsVariant();
protected:
nsVariantType mType;
nsVariantValue mValue;
};
NS_IMPL_ISUPPORTS1(nsVariant, nsIVariant)
nsVariant::nsVariant(nsVariantType type, nsVariantValue& value)
: mType(type), mValue(value)
{
NS_INIT_REFCNT();
}
nsVariant::~nsVariant()
{
switch (mType) {
case nsVariantType_voidPtr:
/* XXX: Per comments from Warren, commenting this out.
This code isn't done (or used), and is a violation
of ANSI C++ to boot. -- Bruce */
/* delete (void *)mValue; */
break;
case nsVariantType_charPtr:
nsCRT::free(mValue.mUnion._charPtr);
break;
case nsVariantType_PRUnicharPtr:
nsCRT::free(mValue.mUnion._PRUnicharPtr);
break;
default:
break;
}
}
NS_IMETHODIMP
nsVariant::GetValue(nsVariantType *type, nsVariantValue *value)
{
NS_PRECONDITION(type && value, "no place to put the result");
*type = mType;
*value = mValue;
return NS_OK;
}
NS_IMETHODIMP
nsVariant::GetValue(nsVariantType expectedType, nsVariantValue *value)
{
NS_PRECONDITION(value, "no place to put the result");
if (mType != expectedType)
return NS_ERROR_FAILURE;
*value = mValue;
return NS_OK;
}
NS_IMETHODIMP
nsVariant::SetValue(nsVariantType type, nsVariantValue& value)
{
mType = type;
mValue = value;
return NS_OK;
}
NS_IMETHODIMP
nsVariant::Equals(nsISupports* other)
{
nsIVariant* otherVariant;
nsresult rv = other->QueryInterface(nsIVariant::GetIID(), (void**)&otherVariant);
if (NS_FAILED(rv)) return NS_COMFALSE;
nsVariantType otherType;
nsVariantValue otherValue;
rv = otherVariant->GetValue(&otherType, &otherValue);
if (NS_FAILED(rv)) return rv;
if (mType != otherType)
return NS_COMFALSE;
PRBool eq = PR_FALSE;
// this is gross, but I think it's the only way to compare unions:
switch (mType) {
case nsVariantType_PRBool:
eq = (PRBool)mValue == (PRBool)otherValue;
break;
case nsVariantType_PRInt16:
eq = (PRInt16)mValue == (PRInt16)otherValue;
break;
case nsVariantType_PRUint16:
eq = (PRUint16)mValue == (PRUint16)otherValue;
break;
case nsVariantType_PRInt32:
eq = (PRInt32)mValue == (PRInt32)otherValue;
break;
case nsVariantType_PRUint32:
eq = (PRUint32)mValue == (PRUint32)otherValue;
break;
case nsVariantType_PRInt64:
eq = LL_EQ((PRInt64)mValue, (PRInt64)otherValue);
break;
case nsVariantType_PRUint64:
eq = LL_EQ((PRUint64)mValue, (PRUint64)otherValue);
break;
case nsVariantType_float:
eq = (float)mValue == (float)otherValue;
break;
case nsVariantType_PRFloat64:
eq = (PRFloat64)mValue == (PRFloat64)otherValue;
break;
case nsVariantType_PRTime:
eq = LL_EQ((PRTime)mValue, (PRTime)otherValue);
break;
case nsVariantType_voidPtr:
eq = (void*)mValue == (void*)otherValue;
break;
case nsVariantType_charPtr:
// I hope this shouldn't be comparing pointers:
eq = nsCRT::strcmp((const char*)mValue, (const char*)otherValue) == 0;
break;
case nsVariantType_PRUnicharPtr:
// I hope this shouldn't be comparing pointers:
eq = nsCRT::strcmp((const PRUnichar*)mValue, (const PRUnichar*)otherValue) == 0;
break;
default:
NS_ERROR("unknown variant type");
}
return eq ? NS_OK : NS_COMFALSE;
}
#ifdef NS_DEBUG
NS_IMETHODIMP
nsVariant::GetDescription(char* *result)
{
char* desc;
switch (mType) {
case nsVariantType_PRBool:
desc = nsCRT::strdup((PRBool)mValue ? "true" : "false");
break;
case nsVariantType_PRInt16:
desc = PR_smprintf("%d", (PRInt16)mValue);
break;
case nsVariantType_PRUint16:
desc = PR_smprintf("%u", (PRUint16)mValue);
break;
case nsVariantType_PRInt32:
desc = PR_smprintf("%l", (PRInt32)mValue);
break;
case nsVariantType_PRUint32:
desc = PR_smprintf("%u", (PRUint32)mValue);
break;
case nsVariantType_PRInt64:
desc = PR_smprintf("%ll", (PRInt64)mValue);
break;
case nsVariantType_PRUint64:
desc = PR_smprintf("%ll", (PRUint64)mValue);
break;
case nsVariantType_float:
desc = PR_smprintf("%g", (float)mValue);
break;
case nsVariantType_PRFloat64:
desc = PR_smprintf("%lg", (PRFloat64)mValue);
break;
case nsVariantType_PRTime:
desc = PR_smprintf("%l", (PRTime)mValue);
break;
case nsVariantType_voidPtr:
desc = PR_smprintf("0x%x", (void*)mValue);
break;
case nsVariantType_charPtr:
desc = PR_smprintf("'%s'", (const char*)mValue);
break;
case nsVariantType_PRUnicharPtr:
desc = PR_smprintf("\"%s\"", (const PRUnichar*)mValue);
break;
default:
desc = PR_smprintf("<Variant 0x%x>", this);
}
*result = desc;
return NS_OK;
}
#endif
////////////////////////////////////////////////////////////////////////////////
NS_COM nsresult
NS_NewIVariant(nsVariantType initialType, nsVariantValue& initialValue,
nsIVariant* *result)
{
nsVariant* v = new nsVariant(initialType, initialValue);
if (v == NULL)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(v);
*result = v;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////