473,468 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Create 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(library,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(const osg::Object* obj) const { return
dynamic_cast<const 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==(const type_info& rhs) const;
bool operator!=(const 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).name(); }
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::className() and
osg::Object::libraryName(), 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 6270
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
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
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: //...
27
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
1
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...
0
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...
0
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 ...

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.