adding nsISupportsVoid to the nsISupportsPrimitives family. Fixing some suboptimal use of *retval

This commit is contained in:
jband%netscape.com 1999-08-20 03:14:46 +00:00
Родитель 86287cf931
Коммит ebb79eaa0a
4 изменённых файлов: 130 добавлений и 34 удалений

Просмотреть файл

@ -70,6 +70,7 @@ static NS_DEFINE_CID(kSupportsPRInt32CID, NS_SUPPORTS_PRINT32_CID);
static NS_DEFINE_CID(kSupportsPRInt64CID, NS_SUPPORTS_PRINT64_CID);
static NS_DEFINE_CID(kSupportsFloatCID, NS_SUPPORTS_FLOAT_CID);
static NS_DEFINE_CID(kSupportsDoubleCID, NS_SUPPORTS_DOUBLE_CID);
static NS_DEFINE_CID(kSupportsVoidCID, NS_SUPPORTS_VOID_CID);
// io
static NS_DEFINE_CID(kFileSpecCID, NS_FILESPEC_CID);
static NS_DEFINE_CID(kDirectoryIteratorCID, NS_DIRECTORYITERATOR_CID);
@ -99,6 +100,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt32Impl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt64Impl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsFloatImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsDoubleImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsVoidImpl)
////////////////////////////////////////////////////////////////////////////////
// XPCOM initialization
@ -381,6 +383,12 @@ nsresult NS_COM NS_InitXPCOM(nsIServiceManager* *result)
nsSupportsDoubleImplConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsVoidCID,
NS_SUPPORTS_VOID_CLASSNAME,
NS_SUPPORTS_VOID_PROGID,
nsSupportsVoidImplConstructor);
if (NS_FAILED(rv)) return rv;
// Prepopulate registry for performance
// Ignore return value. It is ok if this fails.
nsComponentManagerImpl::gComponentManager->PlatformPrePopulateRegistry();

Просмотреть файл

@ -134,6 +134,14 @@ interface nsISupportsDouble : nsISupports
string toString();
};
[scriptable, uuid(464484f0-568d-11d3-baf8-00805f8a5dd7)]
interface nsISupportsVoid : nsISupports
{
[noscript] void GetData([shared,retval] out voidStar aData);
[noscript] void SetData(in voidStar aData);
string toString();
};
/////////////////////////////////////////////////////////////////////////
%{C++
@ -241,6 +249,11 @@ interface nsISupportsDouble : nsISupports
{ 0xba, 0xea, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
#define NS_SUPPORTS_DOUBLE_PROGID "component://netscape/supports-double"
#define NS_SUPPORTS_DOUBLE_CLASSNAME "Supports double"
// {AF10F3E0-568D-11d3-BAF8-00805F8A5DD7}
#define NS_SUPPORTS_VOID_CID \
{ 0xaf10f3e0, 0x568d, 0x11d3, \
{ 0xba, 0xf8, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
#define NS_SUPPORTS_VOID_PROGID "component://netscape/supports-void"
#define NS_SUPPORTS_VOID_CLASSNAME "Supports void"
%}

Просмотреть файл

@ -69,18 +69,18 @@ NS_IMETHODIMP nsSupportsIDImpl::SetData(nsID *aData)
NS_IMETHODIMP nsSupportsIDImpl::toString(char **_retval)
{
char* result = nsnull;
if(!_retval)
{
NS_ASSERTION(0,"Bad pointer");
return NS_ERROR_NULL_POINTER;
}
*_retval = nsnull;
if(mData)
{
char * str = mData->ToString();
if(str)
{
*_retval = (char*) nsAllocator::Clone(str,
result = (char*) nsAllocator::Clone(str,
(nsCRT::strlen(str)+1)*sizeof(char));
delete [] str;
}
@ -88,9 +88,11 @@ NS_IMETHODIMP nsSupportsIDImpl::toString(char **_retval)
else
{
static const char nullStr[] = "null";
*_retval = (char*) nsAllocator::Clone(nullStr, sizeof(nullStr));
result = (char*) nsAllocator::Clone(nullStr, sizeof(nullStr));
}
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
*_retval = result;
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
@ -237,9 +239,10 @@ NS_IMETHODIMP nsSupportsPRBoolImpl::toString(char **_retval)
return NS_ERROR_NULL_POINTER;
}
const char * str = mData ? "true" : "false";
*_retval = (char*) nsAllocator::Clone(str,
char* result = (char*) nsAllocator::Clone(str,
(nsCRT::strlen(str)+1)*sizeof(char));
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
*_retval = result;
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/***************************************************************************/
@ -283,9 +286,10 @@ NS_IMETHODIMP nsSupportsPRUint8Impl::toString(char **_retval)
PR_snprintf(buf, size, "%u", (PRUint16) mData);
*_retval = (char*) nsAllocator::Clone(buf,
char* result = (char*) nsAllocator::Clone(buf,
(nsCRT::strlen(buf)+1)*sizeof(char));
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
*_retval = result;
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/***************************************************************************/
@ -329,9 +333,10 @@ NS_IMETHODIMP nsSupportsPRUint16Impl::toString(char **_retval)
PR_snprintf(buf, size, "%u", (int) mData);
*_retval = (char*) nsAllocator::Clone(buf,
char* result = (char*) nsAllocator::Clone(buf,
(nsCRT::strlen(buf)+1)*sizeof(char));
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
*_retval = result;
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/***************************************************************************/
@ -375,9 +380,10 @@ NS_IMETHODIMP nsSupportsPRUint32Impl::toString(char **_retval)
PR_snprintf(buf, size, "%lu", mData);
*_retval = (char*) nsAllocator::Clone(buf,
char* result = (char*) nsAllocator::Clone(buf,
(nsCRT::strlen(buf)+1)*sizeof(char));
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
*_retval = result;
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/***************************************************************************/
@ -421,9 +427,10 @@ NS_IMETHODIMP nsSupportsPRUint64Impl::toString(char **_retval)
PR_snprintf(buf, size, "%llu", mData);
*_retval = (char*) nsAllocator::Clone(buf,
char* result = (char*) nsAllocator::Clone(buf,
(nsCRT::strlen(buf)+1)*sizeof(char));
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
*_retval = result;
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/***************************************************************************/
@ -467,9 +474,10 @@ NS_IMETHODIMP nsSupportsPRTimeImpl::toString(char **_retval)
PR_snprintf(buf, size, "%llu", mData);
*_retval = (char*) nsAllocator::Clone(buf,
char* result = (char*) nsAllocator::Clone(buf,
(nsCRT::strlen(buf)+1)*sizeof(char));
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
*_retval = result;
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/***************************************************************************/
@ -503,18 +511,20 @@ NS_IMETHODIMP nsSupportsCharImpl::SetData(char aData)
NS_IMETHODIMP nsSupportsCharImpl::toString(char **_retval)
{
char* result;
if(!_retval)
{
NS_ASSERTION(0,"Bad pointer");
return NS_ERROR_NULL_POINTER;
}
*_retval = (char*) nsAllocator::Alloc(2*sizeof(char));
if(!*_retval)
return NS_ERROR_OUT_OF_MEMORY;
(*_retval)[0] = mData;
(*_retval)[1] = 0;
return NS_OK;
if(nsnull != (result = (char*) nsAllocator::Alloc(2*sizeof(char))))
{
result[0] = mData;
result[1] = '\0';
}
*_retval = result;
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/***************************************************************************/
@ -558,9 +568,10 @@ NS_IMETHODIMP nsSupportsPRInt16Impl::toString(char **_retval)
PR_snprintf(buf, size, "%d", mData);
*_retval = (char*) nsAllocator::Clone(buf,
char* result = (char*) nsAllocator::Clone(buf,
(nsCRT::strlen(buf)+1)*sizeof(char));
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
*_retval = result;
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/***************************************************************************/
@ -604,9 +615,10 @@ NS_IMETHODIMP nsSupportsPRInt32Impl::toString(char **_retval)
PR_snprintf(buf, size, "%ld", mData);
*_retval = (char*) nsAllocator::Clone(buf,
char* result = (char*) nsAllocator::Clone(buf,
(nsCRT::strlen(buf)+1)*sizeof(char));
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
*_retval = result;
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/***************************************************************************/
@ -650,9 +662,10 @@ NS_IMETHODIMP nsSupportsPRInt64Impl::toString(char **_retval)
PR_snprintf(buf, size, "%lld", mData);
*_retval = (char*) nsAllocator::Clone(buf,
char* result = (char*) nsAllocator::Clone(buf,
(nsCRT::strlen(buf)+1)*sizeof(char));
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
*_retval = result;
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/***************************************************************************/
@ -696,9 +709,10 @@ NS_IMETHODIMP nsSupportsFloatImpl::toString(char **_retval)
PR_snprintf(buf, size, "%f", (double) mData);
*_retval = (char*) nsAllocator::Clone(buf,
char* result = (char*) nsAllocator::Clone(buf,
(nsCRT::strlen(buf)+1)*sizeof(char));
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
*_retval = result;
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/***************************************************************************/
@ -742,9 +756,54 @@ NS_IMETHODIMP nsSupportsDoubleImpl::toString(char **_retval)
PR_snprintf(buf, size, "%f", mData);
*_retval = (char*) nsAllocator::Clone(buf,
char* result = (char*) nsAllocator::Clone(buf,
(nsCRT::strlen(buf)+1)*sizeof(char));
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
*_retval = result;
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/***************************************************************************/
NS_IMPL_ISUPPORTS(nsSupportsVoidImpl, NS_GET_IID(nsISupportsVoid))
nsSupportsVoidImpl::nsSupportsVoidImpl()
: mData(nsnull)
{
NS_INIT_ISUPPORTS();
}
nsSupportsVoidImpl::~nsSupportsVoidImpl() {}
NS_IMETHODIMP nsSupportsVoidImpl::GetData(const void * *aData)
{
if(!aData)
{
NS_ASSERTION(0,"Bad pointer");
return NS_ERROR_NULL_POINTER;
}
*aData = mData;
return NS_OK;
}
NS_IMETHODIMP nsSupportsVoidImpl::SetData(void * aData)
{
mData = aData;
return NS_OK;
}
NS_IMETHODIMP nsSupportsVoidImpl::toString(char **_retval)
{
if(!_retval)
{
NS_ASSERTION(0,"Bad pointer");
return NS_ERROR_NULL_POINTER;
}
static const char str[] = "[raw data]";
char* result = (char*) nsAllocator::Clone(str, sizeof(str));
*_retval = result;
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/***************************************************************************/

Просмотреть файл

@ -291,6 +291,22 @@ private:
/***************************************************************************/
class nsSupportsVoidImpl : public nsISupportsVoid
{
public:
NS_DECL_ISUPPORTS
NS_IMETHOD GetData(const void * *aData);
NS_IMETHOD SetData(void * aData);
NS_IMETHOD toString(char **_retval);
nsSupportsVoidImpl();
virtual ~nsSupportsVoidImpl();
private:
void* mData;
};
/***************************************************************************/
#endif /* nsSupportsPrimitives_h__ */