473,748 Members | 2,502 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<typeinfo>

I've been working a lot with OpenSceneGraph lately. Overall it is very much
in the spirit of C++. One feature OSG has which is, IMO, an eyesore, is
the presence of a couple of #MACROs to assist in the creation of classes
derived from osg::Object, or osg::Node. The main reason these #MACROS are
useful is because the cpp provides stringification of tokens in the source
file. Here is what the META_Object #MACRO looks like:

http://openscenegraph.org/viewcvs/in...ct?view=markup

/** META_Object macro define the standard clone, isSameKindAs and className
methods.
* Use when subclassing from Object to make it more convenient to define
* the standard pure virtual clone, isSameKindAs and className methods
* which are required for all Object subclasses.*/
#define META_Object(lib rary,name) \
virtual osg::Object* cloneType() const { return new name (); } \
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return
new name (*this,copyop); } \
virtual bool isSameKindAs(co nst osg::Object* obj) const { return
dynamic_cast<co nst name *>(obj)!=NULL; } \
virtual const char* libraryName() const { return #library; }\
virtual const char* className() const { return #name; }
It seems natural that std::type_info should support much of this
functionality. Here's the class declaration:

namespace std {
class type_info {
public:
virtual ~type_info();
bool operator==(cons t type_info& rhs) const;
bool operator!=(cons t type_info& rhs) const;
bool before(const type_info& rhs) const;
const char* name() const;
private:
type_info(const type_info& rhs);
type_info& operator=(const type_info& rhs);
};
Unfortunately, the standard does not specify the format of the ntbs returned
by std::type_info: :name(). GCC on SuSE Linux produces the following output
from the code listed below:

o=N2ti6ObjectE
d=N2ti7DerivedE

#include <iostream>
#include <typeinfo>

namespace ti{
class Object{
public:
const char* name() const { return typeid(*this).n ame(); }
virtual ~Object(){}
};

class Derived: public Object{

};

}

int main(){
ti::Object o;
ti::Derived d;
std::cout << "o=" << o.name() << std::endl;
std::cout << "d=" << d.name() << std::endl;
}

I could read the documentation for GCC and come up with a way to parse that
string to extract the ntbs returned from osg::Object::cl assName() and
osg::Object::li braryName(), but that would not be portable. Of course I
could put the declarations in a header, and conditionally include platfrom
specific implementaitons - assuming all target platforms will provide
parseable return values from std::type_info: :name(). That of course is a
less than ideal solution.

On page 416 of TC++PL(SE), Dr. Stroustrup tells us "the likelyhood is zero
that someone can come up with a single set of information that satisfies
every user". I believe that position may have been taken to a harmful
extreme. It seems to me that specifying a "source form" function that
returns the fully qualified class name in the form it would appear in the
source code would be both useful and reasonable. Does anybody else agree
with this?

I understand that having the ntbs representation of the class name at
runtime does not address the problem of creating osg::Object* cloneType()
const { return new name (); }. That would certainly take a lot more design
change in the C++ library and/or core language. The functionality provided
by the osg::Object class seems rather fundamental. I am sure this kind of
functionality is native to Java, and feel confident it exists in C#. That
doesn't mean it is essential to C++. Obviously, OSG is doing it with
fairly simple CPP #MACROs. But the fact that OSG does have this feature,
and the fact that it is provided externally to the core language suggest to
me that there may be a use for such support in C++. I say this because OSG
is a C++ graphics toolkit. It is not C++ trying to be Java, C#, Pascal, C,
SmallTalk, nor Lisp. This is the only place where (AFAIK) OSG resorts to
#MACROs (other than #include and header guards).

Is there any desire for, or movement for such support in standard C++?
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

Jul 23 '05 #1
2 6291
Hi Mr. Hatton,

Request you to give a single subject *line* summarizing the topic you
have discussed here

......a solution can be soughted out if its a problem definition.

-vs_p...

Jul 23 '05 #2
Achintya wrote:
Hi Mr. Hatton,

Request you to give a single subject *line* summarizing the topic you
have discussed here

.....a solution can be soughted out if its a problem definition.

-vs_p...

How can you support introspection in C++ without resourting to the use of
the CPP?
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
5388
by: Charles L | last post by:
I have read that the inclusion of <fstream.h> makes the inclusion of <iostream.h> unnecessary. Is this correct? Charles L
2
1942
by: Thomas Zangl | last post by:
Hi! First - thanks for your previous replies! After fixing the c'tor everything went fine until ... I added one more class in the hierachie. I have a class hierachie like this: // interface, abstract only class ISession {
27
4347
by: Noah Roberts | last post by:
What steps do people take to make sure that when dealing with C API callback functions that you do the appropriate reinterpret_cast<>? For instance, today I ran into a situation in which the wrong type was the target of a cast. Of course with a reinterpret_cast nothing complains until the UB bites you in the ass. It seems to me that there ought to be a way to deal with these kinds of functions yet still retain some semblance of type...
0
8826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8239
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4597
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.