15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Runtime class info and local classes - can it be done?

Niels Ull Jacobsen -- nuj@kruger.dk
Sunday, January 14, 1996

I would like to use the runtime-class system with a local class:

// foo.h
class CFoo : public CObject
{
	DECLARE_DYNAMIC(CFoo, CObject);

	protected:
	class CLocal : public CObject
	{
		DECLARE_DYNAMIC(CLocal, CObject);
		// ...
	}
	// ...
}

// foo.cpp
IMPLEMENT_DYNAMIC(CFoo, CObject);
IMPLEMENT_DYNAMIC(CFoo::CLocal,  CObject);
...

Unsurprisingly, this doesn't work, as the macros apparently weren't
designed for this. But can it be done?

Of course this example is greatly simplified. In fact, I'd like to
have a hierarchy of local classes in there.





--
Niels Ull Jacobsen, Kruger A/S

Everything stated herein is THE OFFICIAL POLICY of the entire Kruger
group and should be taken as legally binding in every respect. Pigs
will grow wings and fly.








Dean McCrory -- deanm@microsoft.com
Tuesday, January 16, 1996

It can be done, but you'll have to invent your own macros to do it.  
Look at the source for the existing macros and I think you'll find what 
makes them break and how a different set of macros can fix the problem.

// Dean
----------
| From: Niels Ull Jacobsen  
| To: MFC Discussion LIst  
| Subject: Runtime class info and local classes - can it be done?
| Date: Sunday, January 14, 1996 11:22AM
|
| X-Received: from xnet1 by red-48-msg with receive; Tue, 16 Jan 1996 
18:50:26 -0800
| X-Received: from imail1 by xnet1 with recvsmtp; Tue, 16 Jan 1996 
18:50:24 -0800
| Received: from tide03.microsoft.com (red-03-int.microsoft.com
| [157.61.218.13]) by imail1.microsoft.com (8.7.1/8.7.1) with
| SMTP id SAA24084; Tue, 16 Jan 1996 18:53:28 -0800 (PST)
| Received: by tide03.microsoft.com; id SAA06194; Tue, 16 Jan 1996 
18:58:27 -0800
| Received: from netcom10.netcom.com(192.100.81.120) by
| tide03.microsoft.com via smap (g3.0.3)
| 	id xma006184; Tue, 16 Jan 96 18:58:25 -0800
| Received: by netcom10.netcom.com (8.6.12/Netcom)
| 	id RAA03808; Tue, 16 Jan 1996 17:48:01 -0800
| Message-Id: <9601141122.AA27257@cad01.kruger.dk>
| Mailer: Elm [revision: 70.85]
| Sender: owner-mfc-l@netcom.com
| Precedence: list
| X-MsXMTID: xnet1960117025024RECVSMTP[01.52.00]00000132-64309
|
| I would like to use the runtime-class system with a local class:
|
| // foo.h
| class CFoo : public CObject
| {
| 	DECLARE_DYNAMIC(CFoo, CObject);
|
| 	protected:
| 	class CLocal : public CObject
| 	{
| 		DECLARE_DYNAMIC(CLocal, CObject);
| 		// ...
| 	}
| 	// ...
| }
|
| // foo.cpp
| IMPLEMENT_DYNAMIC(CFoo, CObject);
| IMPLEMENT_DYNAMIC(CFoo::CLocal,  CObject);
| ...
|
| Unsurprisingly, this doesn't work, as the macros apparently weren't
| designed for this. But can it be done?
|
| Of course this example is greatly simplified. In fact, I'd like to
| have a hierarchy of local classes in there.
|
|
|
|
|
| --
| Niels Ull Jacobsen, Kruger A/S
|
| Everything stated herein is THE OFFICIAL POLICY of the entire Kruger
| group and should be taken as legally binding in every respect. Pigs
| will grow wings and fly.
|
|
|
|
| 





Raymond Fergerson -- rwf@CAMIS.Stanford.EDU
Wednesday, January 17, 1996

I also encounted this problem.  To make it clear, what is
described in your post is nested classes, and not local classes.  
Local classes are seldom used.  They are classes declared at 
function scope.

For nested classes, I think that you can write a macro 
(DECLARE_NESTED_DYNAMIC) which
takes three arguments (enclosing class, class, base class) and 
constructs the necessary structure.  This is somewhat similar
to the DECLARE_ABSTRACT_SERIAL macro described in the FAQ.
You will need to write a new macro for every level of nesting,
each taking an additional argument.

When I encountered this problem I started working on 
the DECLARE_NESTED_DYNAMIC macro, but further consideration of
my design led me to remove the nested class.  Thus I can't
give you the result.

	Ray


Niels Ull Jacobsen wrote:
> 
> I would like to use the runtime-class system with a local class:
> 
> // foo.h
> class CFoo : public CObject
> {
>         DECLARE_DYNAMIC(CFoo, CObject);
> 
>         protected:
>         class CLocal : public CObject
>         {
>                 DECLARE_DYNAMIC(CLocal, CObject);
>                 // ...
>         }
>         // ...
> }
> 
> // foo.cpp
> IMPLEMENT_DYNAMIC(CFoo, CObject);
> IMPLEMENT_DYNAMIC(CFoo::CLocal,  CObject);
> ...
> 
> Unsurprisingly, this doesn't work, as the macros apparently weren't
> designed for this. But can it be done?
> 
> Of course this example is greatly simplified. In fact, I'd like to
> have a hierarchy of local classes in there.
> 
> --
> Niels Ull Jacobsen, Kruger A/S
> 
> Everything stated herein is THE OFFICIAL POLICY of the entire Kruger
> group and should be taken as legally binding in every respect. Pigs
> will grow wings and fly.



Ken Freeman -- kfreeman@viewlogic.com
Friday, January 19, 1996

Raymond Fergerson wrote:
> 
> For nested classes, I think that you can write a macro
> (DECLARE_NESTED_DYNAMIC) which
> takes three arguments (enclosing class, class, base class) and
> constructs the necessary structure.  This is somewhat similar
> to the DECLARE_ABSTRACT_SERIAL macro described in the FAQ.

In which FAQ?  I couldn't find it in the MFC FAQ or on MSDN.

Ken



Raymond Fergerson -- rwf@CAMIS.Stanford.EDU
Monday, January 22, 1996

I was refering to the MFC faq at:
	http://www.unx.com/~scot/mfc_faq.html
Below is the relevent section.  Unfortunately I said the
macro was a DECLARE_SERIAL varient instead of an 
IMPLEMENT_SERIAL varient, so that explains why you
may not have been able to find it.  Sorry.  

Back to the original question, you need to construct 
an IMPLEMENT_DYNAMIC_NESTED macro for each nesting level.

	Ray

>From the FAQ:

11.12.  How can I declare an abstract base class to be
        IMPLEMENT_SERIAL?
=======================================================
   You need a special form of IMPLEMENT_SERIAL that looks like this:
   Use the regular DECLARE_SERIAL but use IMPLEMENT_SERIAL_ABC shown
   below instead of IMPLEMENT_SERIAL.

   #define IMPLEMENT_SERIAL_ABC(class_name, base_class_name, wSchema) \
           _IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, \
           NULL) \
           CArchive& AFXAPI operator>>(CArchive& ar, class_name* &pOb) \
           { pOb = (class_name*) ar.ReadObject(RUNTIME_CLASS(class_name)); \
           return ar; }
   -anonymous



Ken Freeman wrote:
> 
> Raymond Fergerson wrote:
> >
> > For nested classes, I think that you can write a macro
> > (DECLARE_NESTED_DYNAMIC) which
> > takes three arguments (enclosing class, class, base class) and
> > constructs the necessary structure.  This is somewhat similar
> > to the DECLARE_ABSTRACT_SERIAL macro described in the FAQ.
> 
> In which FAQ?  I couldn't find it in the MFC FAQ or on MSDN.
> 
> Ken




| Вернуться в корень Архива |