Not part of seamonkey.

Removed awkward nsXPTParamInfo::GetInterface and friend, and als removed supporting nsXPTParamInfo.cpp file.  Replace by nsIInterfaceInfo::GetInfoForParam and friend.

Made the constructor for nsInterfaceInfo private, with nsInterfaceInfoManager as a friend class.
This commit is contained in:
mccabe%netscape.com 1999-03-12 06:49:01 +00:00
parent d2fbff22ba
commit 25ebe42e73
18 changed files with 190 additions and 268 deletions

View File

@ -26,6 +26,7 @@
// forward declaration of non-XPCOM types
class nsXPTMethodInfo;
class nsXPTConstant;
class nsXPTParamInfo;
// {215DBE04-94A7-11d2-BA58-00805F8A5DD7}
#define NS_IINTERFACEINFO_IID \
@ -50,6 +51,12 @@ public:
// There do *not* make copies ***explicit bending of XPCOM rules***
NS_IMETHOD GetMethodInfo(uint16 index, const nsXPTMethodInfo** info) = 0;
NS_IMETHOD GetConstant(uint16 index, const nsXPTConstant** constant) = 0;
// Get the interface information or iid associated with a param of some
// method in this interface.
NS_IMETHOD GetInfoForParam(nsXPTParamInfo* param, nsIInterfaceInfo** info)
= 0;
NS_IMETHOD GetIIDForParam(nsXPTParamInfo* param, nsIID** iid) = 0;
};
#endif /* nsIInterfaceInfo_h___ */

View File

@ -109,18 +109,6 @@ public:
return type.type.argnum;
}
// This is not inlined, it is more involved!
// If XPTInterfaceDirectoryEntry references remain indexes, then it
// may be necessary to pass in a param here indicating which typelib
// - or at least XPTInterfaceDirectoryEntry - this particular param
// is associated with so that we can find the table this index indexes
// and then find the referenced XPTInterfaceDirectoryEntry so that we can
// find (or build) the appropriate nsIInterfaceInfo. Simple :)
XPTI_EXPORT nsIInterfaceInfo* GetInterface(nsIInterfaceInfo *info) const ;
// a *little* simpler than the above
XPTI_EXPORT const nsIID* GetInterfaceIID(nsIInterfaceInfo *info) const ;
private:
nsXPTParamInfo(); // no implementation
// NO DATA - this a flyweight wrapper

View File

@ -28,7 +28,6 @@ CSRCS = $(NULL)
CPPSRCS = nsInterfaceInfo.cpp \
nsInterfaceInfoManager.cpp \
nsXPTParamInfo.cpp \
$(NULL)
REQUIRES = $(MODULE)

View File

@ -48,14 +48,12 @@ C_OBJS = \
CPPSRCS = nsInterfaceInfoManager.cpp \
nsInterfaceInfo.cpp \
nsXPTParamInfo.cpp \
$(NULL)
CPP_OBJS = \
.\$(OBJDIR)\nsInterfaceInfoManager.obj \
.\$(OBJDIR)\nsInterfaceInfo.obj \
.\$(OBJDIR)\nsXPTParamInfo.obj \
$(NULL)
MODULE = xptinfo

View File

@ -178,6 +178,77 @@ nsInterfaceInfo::GetConstant(uint16 index, const nsXPTConstant** constant)
return NS_OK;
}
NS_IMETHODIMP
nsInterfaceInfo::GetInfoForParam(nsXPTParamInfo *param, nsIInterfaceInfo** info)
{
NS_PRECONDITION(param->GetType().TagPart() == nsXPTType::T_INTERFACE,
"not an interface");
nsIInterfaceInfoManager* mgr;
if(NULL == (mgr = nsInterfaceInfoManager::GetInterfaceInfoManager())) {
*info = NULL;
return NS_ERROR_FAILURE;
}
// what typelib did the entry come from?
XPTHeader *which_header = mInterfaceRecord->which_header;
NS_ASSERTION(which_header != NULL, "missing header info assoc'd with II");
// can't use IID, because it could be null for this entry.
char *interface_name;
// offset is 1-based, so subtract 1 to use in interface_directory.
interface_name =
which_header->interface_directory[param->type.type.interface - 1].name;
// does addref. I'll have to do addreff if I find it through a magic
// array walk.
nsresult nsr = mgr->GetInfoForName(interface_name, info);
if (NS_IS_ERROR(nsr)) {
// *info has been set to null by well-behaved GetInfoForName
NS_RELEASE(mgr);
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
nsInterfaceInfo::GetIIDForParam(nsXPTParamInfo* param, nsIID** iid)
{
NS_PRECONDITION(param->GetType().TagPart() == nsXPTType::T_INTERFACE,
"not an interface");
nsIInterfaceInfoManager* mgr;
if(NULL == (mgr = nsInterfaceInfoManager::GetInterfaceInfoManager())) {
*iid = NULL;
return NS_ERROR_FAILURE;
}
// what typelib did the entry come from?
XPTHeader *which_header = mInterfaceRecord->which_header;
NS_ASSERTION(which_header != NULL, "header missing?");
// can't use IID, because it could be null for this entry.
char *interface_name;
// offset is 1-based, so subtract 1 to use in interface_directory.
interface_name =
which_header->interface_directory[param->type.type.interface - 1].name;
nsresult nsr = mgr->GetIIDForName(interface_name, iid);
if (NS_IS_ERROR(nsr)) {
// *iid has been set to NULL by well-behaved GetIIDForName
NS_RELEASE(mgr);
return NS_ERROR_FAILURE;
}
return NS_OK;
}
#ifdef DEBUG
#include <stdio.h>
void

View File

@ -27,6 +27,8 @@
#include "nsInterfaceRecord.h"
#include "nsInterfaceInfoManager.h"
#ifdef DEBUG
#include <stdio.h>
#endif
@ -50,9 +52,11 @@ class nsInterfaceInfo : public nsIInterfaceInfo
NS_IMETHOD GetMethodInfo(uint16 index, const nsXPTMethodInfo** info);
NS_IMETHOD GetConstant(uint16 index, const nsXPTConstant** constant);
// why constructor public?
nsInterfaceInfo(nsInterfaceRecord *record,
nsInterfaceInfo *parent);
// Get the interface information or iid associated with a param of some
// method in this interface.
NS_IMETHOD GetInfoForParam(nsXPTParamInfo* param, nsIInterfaceInfo** info);
NS_IMETHOD GetIIDForParam(nsXPTParamInfo* param, nsIID** iid);
public:
virtual ~nsInterfaceInfo();
@ -61,12 +65,11 @@ public:
#endif
private:
friend nsIInterfaceInfo*
nsXPTParamInfo::GetInterface(nsIInterfaceInfo *info) const;
friend const nsIID*
nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const;
// nsInterfaceInfoManager has access to the constructor.
friend class nsInterfaceInfoManager;
nsInterfaceInfo(nsInterfaceRecord *record, nsInterfaceInfo *parent);
nsInterfaceRecord *getInterfaceRecord() { return mInterfaceRecord; };
nsInterfaceRecord *mInterfaceRecord;
nsInterfaceInfo* mParent;

View File

@ -51,11 +51,6 @@ public:
static nsIAllocator* GetAllocator(nsInterfaceInfoManager* iim = NULL);
private:
friend nsIInterfaceInfo*
nsXPTParamInfo::GetInterface(nsIInterfaceInfo *info) const;
friend const nsIID*
nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const;
void initInterfaceTables();
// mapping between names and records

View File

@ -1,104 +0,0 @@
/* -*- Mode: C++; tab-width: 8; 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* Convienence bits of nsXPTParamInfo that don't fit into xpt_cpp.h
* flyweight wrappers.
*/
#include "nsISupports.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIInterfaceInfo.h"
#include "nsInterfaceInfoManager.h"
#include "xpt_cpp.h"
#include "xptinfo.h"
nsIInterfaceInfo*
nsXPTParamInfo::GetInterface(nsIInterfaceInfo *info) const
{
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,
"not an interface");
nsInterfaceRecord *record =
((nsInterfaceInfo *)info)->getInterfaceRecord();
nsIInterfaceInfoManager* mgr;
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
return NULL;
// what typelib did the entry come from?
XPTHeader *which_header = record->which_header;
NS_ASSERTION(which_header != NULL, "missing header info assoc'd with II");
// can't use IID, because it could be null for this entry.
char *interface_name;
// offset is 1-based, so subtract 1 to use in interface_directory.
interface_name =
which_header->interface_directory[type.type.interface - 1].name;
nsIInterfaceInfo *ii;
nsresult nsr = mgr->GetInfoForName(interface_name, &ii);
if (NS_IS_ERROR(nsr)) {
NS_RELEASE(mgr);
return NULL;
}
return ii;
}
const nsIID*
nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const
{
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,
"not an interface");
nsInterfaceRecord *record =
((nsInterfaceInfo *)info)->getInterfaceRecord();
nsIInterfaceInfoManager* mgr;
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
return NULL;
// what typelib did the entry come from?
XPTHeader *which_header = record->which_header;
NS_ASSERTION(which_header != NULL, "header missing?");
// can't use IID, because it could be null for this entry.
char *interface_name;
// offset is 1-based, so subtract 1 to use in interface_directory.
interface_name =
which_header->interface_directory[type.type.interface - 1].name;
nsIID* iid;
nsresult nsr = mgr->GetIIDForName(interface_name, &iid);
if (NS_IS_ERROR(nsr)) {
NS_RELEASE(mgr);
return NULL;
}
return iid;
}

View File

@ -102,7 +102,9 @@ int main (int argc, char **argv) {
nsXPTParamInfo param2 = mi->GetParam(2);
// should be IID for nsIShutdownListener
const nsIID *nsISL = param2.GetInterfaceIID(info5);
nsIID *nsISL;
info5->GetIIDForParam(&param2, &nsISL);
// const nsIID *nsISL = param2.GetInterfaceIID(info5);
fprintf(stderr, "iid assoc'd with param 2 of method 7 of GetServiceWithListener - %s\n", nsISL->ToString());
// if we look up the name?
char *nsISLname;
@ -112,7 +114,9 @@ int main (int argc, char **argv) {
fprintf(stderr, "\nhow about one defined in a different typelib\n");
nsXPTParamInfo param3 = mi->GetParam(3);
// should be IID for nsIShutdownListener
const nsIID *nsISS = param3.GetInterfaceIID(info5);
nsIID *nsISS;
info5->GetIIDForParam(&param3, &nsISS);
// const nsIID *nsISS = param3.GetInterfaceIID(info5);
fprintf(stderr, "iid assoc'd with param 3 of method 7 of GetServiceWithListener - %s\n", nsISS->ToString());
// if we look up the name?
char *nsISSname;

View File

@ -26,6 +26,7 @@
// forward declaration of non-XPCOM types
class nsXPTMethodInfo;
class nsXPTConstant;
class nsXPTParamInfo;
// {215DBE04-94A7-11d2-BA58-00805F8A5DD7}
#define NS_IINTERFACEINFO_IID \
@ -50,6 +51,12 @@ public:
// There do *not* make copies ***explicit bending of XPCOM rules***
NS_IMETHOD GetMethodInfo(uint16 index, const nsXPTMethodInfo** info) = 0;
NS_IMETHOD GetConstant(uint16 index, const nsXPTConstant** constant) = 0;
// Get the interface information or iid associated with a param of some
// method in this interface.
NS_IMETHOD GetInfoForParam(nsXPTParamInfo* param, nsIInterfaceInfo** info)
= 0;
NS_IMETHOD GetIIDForParam(nsXPTParamInfo* param, nsIID** iid) = 0;
};
#endif /* nsIInterfaceInfo_h___ */

View File

@ -109,18 +109,6 @@ public:
return type.type.argnum;
}
// This is not inlined, it is more involved!
// If XPTInterfaceDirectoryEntry references remain indexes, then it
// may be necessary to pass in a param here indicating which typelib
// - or at least XPTInterfaceDirectoryEntry - this particular param
// is associated with so that we can find the table this index indexes
// and then find the referenced XPTInterfaceDirectoryEntry so that we can
// find (or build) the appropriate nsIInterfaceInfo. Simple :)
XPTI_EXPORT nsIInterfaceInfo* GetInterface(nsIInterfaceInfo *info) const ;
// a *little* simpler than the above
XPTI_EXPORT const nsIID* GetInterfaceIID(nsIInterfaceInfo *info) const ;
private:
nsXPTParamInfo(); // no implementation
// NO DATA - this a flyweight wrapper

View File

@ -28,7 +28,6 @@ CSRCS = $(NULL)
CPPSRCS = nsInterfaceInfo.cpp \
nsInterfaceInfoManager.cpp \
nsXPTParamInfo.cpp \
$(NULL)
REQUIRES = $(MODULE)

View File

@ -48,14 +48,12 @@ C_OBJS = \
CPPSRCS = nsInterfaceInfoManager.cpp \
nsInterfaceInfo.cpp \
nsXPTParamInfo.cpp \
$(NULL)
CPP_OBJS = \
.\$(OBJDIR)\nsInterfaceInfoManager.obj \
.\$(OBJDIR)\nsInterfaceInfo.obj \
.\$(OBJDIR)\nsXPTParamInfo.obj \
$(NULL)
MODULE = xptinfo

View File

@ -178,6 +178,77 @@ nsInterfaceInfo::GetConstant(uint16 index, const nsXPTConstant** constant)
return NS_OK;
}
NS_IMETHODIMP
nsInterfaceInfo::GetInfoForParam(nsXPTParamInfo *param, nsIInterfaceInfo** info)
{
NS_PRECONDITION(param->GetType().TagPart() == nsXPTType::T_INTERFACE,
"not an interface");
nsIInterfaceInfoManager* mgr;
if(NULL == (mgr = nsInterfaceInfoManager::GetInterfaceInfoManager())) {
*info = NULL;
return NS_ERROR_FAILURE;
}
// what typelib did the entry come from?
XPTHeader *which_header = mInterfaceRecord->which_header;
NS_ASSERTION(which_header != NULL, "missing header info assoc'd with II");
// can't use IID, because it could be null for this entry.
char *interface_name;
// offset is 1-based, so subtract 1 to use in interface_directory.
interface_name =
which_header->interface_directory[param->type.type.interface - 1].name;
// does addref. I'll have to do addreff if I find it through a magic
// array walk.
nsresult nsr = mgr->GetInfoForName(interface_name, info);
if (NS_IS_ERROR(nsr)) {
// *info has been set to null by well-behaved GetInfoForName
NS_RELEASE(mgr);
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
nsInterfaceInfo::GetIIDForParam(nsXPTParamInfo* param, nsIID** iid)
{
NS_PRECONDITION(param->GetType().TagPart() == nsXPTType::T_INTERFACE,
"not an interface");
nsIInterfaceInfoManager* mgr;
if(NULL == (mgr = nsInterfaceInfoManager::GetInterfaceInfoManager())) {
*iid = NULL;
return NS_ERROR_FAILURE;
}
// what typelib did the entry come from?
XPTHeader *which_header = mInterfaceRecord->which_header;
NS_ASSERTION(which_header != NULL, "header missing?");
// can't use IID, because it could be null for this entry.
char *interface_name;
// offset is 1-based, so subtract 1 to use in interface_directory.
interface_name =
which_header->interface_directory[param->type.type.interface - 1].name;
nsresult nsr = mgr->GetIIDForName(interface_name, iid);
if (NS_IS_ERROR(nsr)) {
// *iid has been set to NULL by well-behaved GetIIDForName
NS_RELEASE(mgr);
return NS_ERROR_FAILURE;
}
return NS_OK;
}
#ifdef DEBUG
#include <stdio.h>
void

View File

@ -27,6 +27,8 @@
#include "nsInterfaceRecord.h"
#include "nsInterfaceInfoManager.h"
#ifdef DEBUG
#include <stdio.h>
#endif
@ -50,9 +52,11 @@ class nsInterfaceInfo : public nsIInterfaceInfo
NS_IMETHOD GetMethodInfo(uint16 index, const nsXPTMethodInfo** info);
NS_IMETHOD GetConstant(uint16 index, const nsXPTConstant** constant);
// why constructor public?
nsInterfaceInfo(nsInterfaceRecord *record,
nsInterfaceInfo *parent);
// Get the interface information or iid associated with a param of some
// method in this interface.
NS_IMETHOD GetInfoForParam(nsXPTParamInfo* param, nsIInterfaceInfo** info);
NS_IMETHOD GetIIDForParam(nsXPTParamInfo* param, nsIID** iid);
public:
virtual ~nsInterfaceInfo();
@ -61,12 +65,11 @@ public:
#endif
private:
friend nsIInterfaceInfo*
nsXPTParamInfo::GetInterface(nsIInterfaceInfo *info) const;
friend const nsIID*
nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const;
// nsInterfaceInfoManager has access to the constructor.
friend class nsInterfaceInfoManager;
nsInterfaceInfo(nsInterfaceRecord *record, nsInterfaceInfo *parent);
nsInterfaceRecord *getInterfaceRecord() { return mInterfaceRecord; };
nsInterfaceRecord *mInterfaceRecord;
nsInterfaceInfo* mParent;

View File

@ -51,11 +51,6 @@ public:
static nsIAllocator* GetAllocator(nsInterfaceInfoManager* iim = NULL);
private:
friend nsIInterfaceInfo*
nsXPTParamInfo::GetInterface(nsIInterfaceInfo *info) const;
friend const nsIID*
nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const;
void initInterfaceTables();
// mapping between names and records

View File

@ -1,104 +0,0 @@
/* -*- Mode: C++; tab-width: 8; 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* Convienence bits of nsXPTParamInfo that don't fit into xpt_cpp.h
* flyweight wrappers.
*/
#include "nsISupports.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIInterfaceInfo.h"
#include "nsInterfaceInfoManager.h"
#include "xpt_cpp.h"
#include "xptinfo.h"
nsIInterfaceInfo*
nsXPTParamInfo::GetInterface(nsIInterfaceInfo *info) const
{
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,
"not an interface");
nsInterfaceRecord *record =
((nsInterfaceInfo *)info)->getInterfaceRecord();
nsIInterfaceInfoManager* mgr;
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
return NULL;
// what typelib did the entry come from?
XPTHeader *which_header = record->which_header;
NS_ASSERTION(which_header != NULL, "missing header info assoc'd with II");
// can't use IID, because it could be null for this entry.
char *interface_name;
// offset is 1-based, so subtract 1 to use in interface_directory.
interface_name =
which_header->interface_directory[type.type.interface - 1].name;
nsIInterfaceInfo *ii;
nsresult nsr = mgr->GetInfoForName(interface_name, &ii);
if (NS_IS_ERROR(nsr)) {
NS_RELEASE(mgr);
return NULL;
}
return ii;
}
const nsIID*
nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const
{
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,
"not an interface");
nsInterfaceRecord *record =
((nsInterfaceInfo *)info)->getInterfaceRecord();
nsIInterfaceInfoManager* mgr;
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
return NULL;
// what typelib did the entry come from?
XPTHeader *which_header = record->which_header;
NS_ASSERTION(which_header != NULL, "header missing?");
// can't use IID, because it could be null for this entry.
char *interface_name;
// offset is 1-based, so subtract 1 to use in interface_directory.
interface_name =
which_header->interface_directory[type.type.interface - 1].name;
nsIID* iid;
nsresult nsr = mgr->GetIIDForName(interface_name, &iid);
if (NS_IS_ERROR(nsr)) {
NS_RELEASE(mgr);
return NULL;
}
return iid;
}

View File

@ -102,7 +102,9 @@ int main (int argc, char **argv) {
nsXPTParamInfo param2 = mi->GetParam(2);
// should be IID for nsIShutdownListener
const nsIID *nsISL = param2.GetInterfaceIID(info5);
nsIID *nsISL;
info5->GetIIDForParam(&param2, &nsISL);
// const nsIID *nsISL = param2.GetInterfaceIID(info5);
fprintf(stderr, "iid assoc'd with param 2 of method 7 of GetServiceWithListener - %s\n", nsISL->ToString());
// if we look up the name?
char *nsISLname;
@ -112,7 +114,9 @@ int main (int argc, char **argv) {
fprintf(stderr, "\nhow about one defined in a different typelib\n");
nsXPTParamInfo param3 = mi->GetParam(3);
// should be IID for nsIShutdownListener
const nsIID *nsISS = param3.GetInterfaceIID(info5);
nsIID *nsISS;
info5->GetIIDForParam(&param3, &nsISS);
// const nsIID *nsISS = param3.GetInterfaceIID(info5);
fprintf(stderr, "iid assoc'd with param 3 of method 7 of GetServiceWithListener - %s\n", nsISS->ToString());
// if we look up the name?
char *nsISSname;