473,699 Members | 2,838 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 6286
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
5385
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
1938
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
4335
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
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8612
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
9171
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
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5869
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
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2008
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.