473,473 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to call a function by a string of name & How to get the name of aclass?

---------------------------This is my
task:--------------------------------------
There are hundred of similar classes and a large file(in processing)
with thousand of instances of these classes. I should export these
instances into a XML file (I use Tiny XML), however not total
instances, but these which belong to the selected classes and the
selected attributes(member variable and value). In advance, I will
have a configuration file (also XML format), to define which classes
and which attributes we need, that is a user-defined file.
The problem are:

1, How do I get the name of a class? Just like by Java the
method .getclass() or instanceof ?

2, Is it possible to have such as an iterator to traverse through
all the variables/functions, to only call the functions and to get
the values of variables we need by name?

Thank you very much for your reply, indeed.
Jul 3 '08 #1
3 1394
Sam
cutecutemouse writes:
1, How do I get the name of a class? Just like by Java the
method .getclass() or instanceof ?

2, Is it possible to have such as an iterator to traverse through
all the variables/functions, to only call the functions and to get
the values of variables we need by name?

Thank you very much for your reply, indeed.
No, there is no equivalent of Java-like reflection classes in the standard
C++ language. The only thing that's available in the standard C++ language
is a facility for retrieve an "implementation-defined" name of the object's
class, which may not necessary be the human-readable class name.

Having said that, your C++ compiler may or may not have its own
compiler-specific facilities for run-time type information that provides
more information than the C++ language standard requires. Check your
compiler's documentation for more information.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAkhtXh4ACgkQx9p3GYHlUOI+sgCffGkGm9Mttj gyy+UM4LlXSjGv
C4IAn0dz+SoTOg5pBHxMRwojL5HoB140
=flFV
-----END PGP SIGNATURE-----

Jul 3 '08 #2
cutecutemouse <pl******@hotmail.comwrites:
---------------------------This is my
task:--------------------------------------
There are hundred of similar classes and a large file(in processing)
with thousand of instances of these classes. I should export these
instances into a XML file (I use Tiny XML), however not total
instances, but these which belong to the selected classes and the
selected attributes(member variable and value). In advance, I will
have a configuration file (also XML format), to define which classes
and which attributes we need, that is a user-defined file.
The problem are:

1, How do I get the name of a class? Just like by Java the
method .getclass() or instanceof ?
Using RTTI:

template <class Classstd::string getClass(Class* object){
return unmangle(typeid(*object).name());
}

You will have to implement the unmangle function for your compiler...

2, Is it possible to have such as an iterator to traverse through
all the variables/functions, to only call the functions and to get
the values of variables we need by name?
You'll get no help from C++, but it's possible.

Here are two ways:

- use the source (parse it, or use the UML model if you design your
program from an UML CASE tool), and generate from it the meta
objects needed to do it.

- compile your program with a lot of debugging information (-ggdb3
-gdwarf-2 etc), and then use these debugging information to do
introspection at run-time, like any debugger would do it.

Here is also a third way to solve your problem, since you know before
hand what class and what member you need to access (from your xml
configuration files), you can use them to generate the C++ code that
will do the job.

--
__Pascal Bourguignon__
Jul 4 '08 #3
I've found a third-party Reflection API "Reflex" for it. Thank you!

On 4 Jul., 01:17, Sam <s...@email-scan.comwrote:
cutecutemouse writes:
1, How do I get the name of a class? Just like by Java the
method .getclass() or instanceof ?
2, Is it possible to have such as an iterator to traverse through
all the variables/functions, to only call the functions and to get
the values of variables we need by name?
Thank you very much for your reply, indeed.

No, there is no equivalent of Java-like reflection classes in the standard
C++ language. The only thing that's available in the standard C++ language
is a facility for retrieve an "implementation-defined" name of the object's
class, which may not necessary be the human-readable class name.

Having said that, your C++ compiler may or may not have its own
compiler-specific facilities for run-time type information that provides
more information than the C++ language standard requires. Check your
compiler's documentation for more information.

application_pgp-signature_part
1KHerunterladen
Jul 13 '08 #4

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

Similar topics

3
by: Alfred E Neuman | last post by:
I've read that... AClass ac = AClass( "name", 23 ); is less efficient than... AClass ac( "name", 23 ); because the first has to create a temporary object which is then assigned to ac. ...
5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
5
by: Rob | last post by:
Help me, I'm just beginning with programming in Access 2000. I've tried the http://www.mvps.org/access/api/api0001.htm but it won't work in Access. What am i doing wrong. I don't have...
13
by: Jason Shohet | last post by:
I have an ascx control, and it needs a value called 'orgID' which the parent page will have. I want to avoid the parent page setting values in fields on the ascx control since this violates...
10
by: bienwell | last post by:
Hi, I have a question about file included in ASP.NET. I have a file that includes all the Sub functions (e.g FileFunct.vb). One of the functions in this file is : Sub TestFunct(ByVal...
5
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3, I need to do it myself. I'm fairly...
5
by: SStory | last post by:
Hi all, I really needed to get the icons associated with each file that I want to show in a listview. I used the follow modified code sniplets found on the internet. I have left in...
5
by: rolandz | last post by:
Hi, Maybe somebody has been fighting with the problem that I do, currently. I have a class that has method f(). The two versions of the f() method accept different objects: Int and Short. These...
0
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,...
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
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...
1
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...
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,...
0
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...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.