Connecting Tech Pros Worldwide Help | Site Map

[LONG]Simple RTTI

Kleidemos
Guest
 
Posts: n/a
#1: Jul 22 '05
If I implement a simple RTTI system, more simple than C++ RTTI system
for my program and this system is plus or minus:

#define DEF_RTTI_BASE(name) virtual inline const char *Name(){ return
#name; }
#define DEF_RTTI(name) inline const char *Name(){ return #name; }

And(for example)

class CProva
{
public:
CProva(){};
~CProva(){};
DEF_RTTI_BASE(CProva)
};

class CProvaDerived
{
public:
CProvaDerived(){};
~CProvaDerived(){};
DEF_RTTI(CProvaDerived)
};

int main()
{
CProva p;
CProvaDerived d;
std::cout << "Base: " << p.Name()<< "\n";
std::cout << "Derived: " << d.Name()<< "\n";
char cexit = std::cin.get();
return 0;
}

This system is a valid RTTI subsystem that can subsitute the C++ RTTI
and I can use it in my program without the dipendens of the C++ RTTI system?

--
Tnk

Luca "Kleidemos" Francesca

Un computer a un altro quando si incontrano:
"Ciao, come ti boota oggi???"
Rob Williscroft
Guest
 
Posts: n/a
#2: Jul 22 '05

re: [LONG]Simple RTTI


Kleidemos wrote in news:nJnQc.74822$OR2.4252887@news3.tin.it in
comp.lang.c++:
[color=blue]
> If I implement a simple RTTI system, more simple than C++ RTTI system
> for my program and this system is plus or minus:
>[/color]

Before you "re-implement" RTTI what's your problem with the language
features (that are always present BTW) commonly refered to as RTTI ?

IOW: whats your question ? or what (if any) is your problem ?

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Kleidemos
Guest
 
Posts: n/a
#3: Jul 22 '05

re: [LONG]Simple RTTI


Rob Williscroft wrote:[color=blue]
>
> Before you "re-implement" RTTI what's your problem with the language
> features (that are always present BTW) commonly refered to as RTTI ?[/color]
It's, IMHO, more Os dipendent and more complicate and wrong
implementated than how it could be.


--
Tnk

Luca "Kleidemos" Francesca

Un computer a un altro quando si incontrano:
"Ciao, come ti boota oggi???"
John Harrison
Guest
 
Posts: n/a
#4: Jul 22 '05

re: [LONG]Simple RTTI



"Kleidemos" <francesca8810@tin.it> wrote in message
news:nJnQc.74822$OR2.4252887@news3.tin.it...[color=blue]
> If I implement a simple RTTI system, more simple than C++ RTTI system
> for my program and this system is plus or minus:
>
> #define DEF_RTTI_BASE(name) virtual inline const char *Name(){ return
> #name; }
> #define DEF_RTTI(name) inline const char *Name(){ return #name; }
>
> And(for example)
>
> class CProva
> {
> public:
> CProva(){};
> ~CProva(){};
> DEF_RTTI_BASE(CProva)
> };
>
> class CProvaDerived
> {
> public:
> CProvaDerived(){};
> ~CProvaDerived(){};
> DEF_RTTI(CProvaDerived)
> };
>
> int main()
> {
> CProva p;
> CProvaDerived d;
> std::cout << "Base: " << p.Name()<< "\n";
> std::cout << "Derived: " << d.Name()<< "\n";
> char cexit = std::cin.get();
> return 0;
> }
>
> This system is a valid RTTI subsystem that can subsitute the C++ RTTI
> and I can use it in my program without the dipendens of the C++ RTTI[/color]
system?[color=blue]
>[/color]

Why do you have two macros? Using DEF_RTTI_BASE works exactly the same.

class CProvaDerived
{
public:
CProvaDerived(){};
~CProvaDerived(){};
DEF_RTTI_BASE(CProvaDerived)
};

john


Kleidemos
Guest
 
Posts: n/a
#5: Jul 22 '05

re: [LONG]Simple RTTI


John Harrison wrote:
[color=blue]
>
> Why do you have two macros? Using DEF_RTTI_BASE works exactly the same.
>
> class CProvaDerived
> {
> public:
> CProvaDerived(){};
> ~CProvaDerived(){};
> DEF_RTTI_BASE(CProvaDerived)
> };
>
> john
>
>[/color]

Tanks for yout advise ;)


--
Tnk

Luca "Kleidemos" Francesca

Un computer a un altro quando si incontrano:
"Ciao, come ti boota oggi???"
Rob Williscroft
Guest
 
Posts: n/a
#6: Jul 22 '05

re: [LONG]Simple RTTI


Kleidemos wrote in news:TDoQc.75072$OR2.4257914@news3.tin.it in
comp.lang.c++:
[color=blue]
> Rob Williscroft wrote:[color=green]
>>
>> Before you "re-implement" RTTI what's your problem with the language
>> features (that are always present BTW) commonly refered to as RTTI ?[/color]
>
> It's, IMHO, more Os dipendent and more complicate and wrong
> implementated than how it could be.
>
>[/color]

Ok, what dosen't it do that you want ?.

AFAICT you code solved the problem that:

typeid( <object-reference> ).name()

return's an implementation defined "string", but it imposes that *every*
object be polymorphic. In effect its a variation of "everything is an
`Object` (i.e. is-a/derived from)" systems (as in jave/c# etc) that
have been tried and abandoned countless times:

Perhapse you will find:

http://lists.boost.org/MailArchives/boost/msg64112.php

(subject "[boost] typeof")

interesting.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jeff Flinn
Guest
 
Posts: n/a
#7: Jul 22 '05

re: [LONG]Simple RTTI



"Rob Williscroft" <rtw@freenet.co.uk> wrote in message
news:Xns953C85BEF8BA8ukcoREMOVEfreenetrtw@130.133. 1.4...[color=blue]
> Kleidemos wrote in news:TDoQc.75072$OR2.4257914@news3.tin.it in
> comp.lang.c++:
>[color=green]
> > Rob Williscroft wrote:[color=darkred]
> >>
> >> Before you "re-implement" RTTI what's your problem with the language
> >> features (that are always present BTW) commonly refered to as RTTI ?[/color]
> >
> > It's, IMHO, more Os dipendent and more complicate and wrong
> > implementated than how it could be.
> >
> >[/color]
>
> Ok, what dosen't it do that you want ?.
>
> AFAICT you code solved the problem that:
>
> typeid( <object-reference> ).name()
>
> return's an implementation defined "string", but it imposes that *every*
> object be polymorphic. In effect its a variation of "everything is an
> `Object` (i.e. is-a/derived from)" systems (as in jave/c# etc) that
> have been tried and abandoned countless times:[/color]

Microsoft's MFC uncannilly similar implementation demonstrates your point
very well.
[color=blue]
> Perhapse you will find:
>
> http://lists.boost.org/MailArchives/boost/msg64112.php
>
> (subject "[boost] typeof")
>
> interesting.[/color]

What purpose does the OP anticipate using this 'facility' to accomplish?
IIRC, the only uses for RTTI are serialization and multiple dispatch. In
which case boost::serialization should be of interest as well at
www.rrsd.com. Certainly C++ RTTI is sufficient for MultipleDispatch examples
that I've seen to date.

Jeff F


Closed Thread


Similar C / C++ bytes