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

Home Posts Topics Members FAQ

How to get the name of a parent class statically?

Hello all,

We're coding a really nice implementation of a generic abstract factory
at the moment, but we've come to a slight impass we have to work around:
when automagically registering a class to be built by the builder, we
are using a class and a macro that look like this:

template<
typename ClassT,
typename ParentT = typename ClassT::ParentType,
typename BuilderT = clsBuilder<typename ParentT> >
struct Initializer
{
Initializer(typename BuilderT::tKeyType oKey)
{
BuilderT::RegisterClass(oKey, ClassT::Create);
}

Initializer(typename BuilderT::tKeyType oKey,
typename BuilderT::tCreatorFunctor functor)
{
BuilderT::RegisterClass(oKey, functor);
}
};

#define REGISTER_CLASS( C, K ) \
static Initializer<C> C##__Initializer(K)

This requires a typedef (ParentType) in the class, its ancestor or (in
an alternative approach we tried) in the builder.

We were looking for a way to find the most remote - or even a direct -
ancestor of a given class C statically, but we didn't find one. However,
we're pretty sure the compiler has the information somewhere, as the
class was declared as having one or more parents. Is there any
*standard* way to gleen this information from the compiler?

Thanks,

rlc
Jul 23 '05 #1
1 1510
Victor Bazarov wrote:
Ronald Landheer-Cieslak wrote:
[...]
We were looking for a way to find the most remote - or even a direct -
ancestor of a given class C statically, but we didn't find one. However,
we're pretty sure the compiler has the information somewhere, as the
class was declared as having one or more parents. Is there any
*standard* way to gleen this information from the compiler? Just imagine, what if your class has more than one base class? What would
you expect in that case as "the most remote ancestor"?

A direct ancestor would suffice (a little recursive template magic will
get me the most remote ancestor if I want to). As for multiple
inheritance, I'd say there are plenty of ways to deal with that if we
want: a sort of get_parent(class, parent_id) where parent_id is a
non-negative integer would do the trick..

I'm not surprised the answer is "no", though: it just means the parent
class needs some kind of support for my factory or where-ever I use my
macro to register the class in the factory I'll have to specify which
factory I want to register in - which is not necessarilly a bad thing..
Maybe in Visual Basic, where there is no multiple inheritance...

I only write C and C++ - by Basic days are far behind me and I'd like to
keep it that way...

Thanks,

rlc
Jul 23 '05 #2

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

Similar topics

2
3353
by: Rick | last post by:
Class Foo { function Bob { return NAME_OF_CLASS } } Class Goo Extends Foo { } echo Goo::Bob();
11
4117
by: Mark | last post by:
hello! I have a class method that takes a variable number of parameters and correctly deals with them with func_get_args, etc ... i.e. class ABC { public function MooSaysTheCow()
7
1622
by: ~toki | last post by:
Having this: public class MyClass : UserControls { public int number=25; public MyClass { new TestClass(this); } }
2
1282
by: Andrew Baker | last post by:
I want to show the parent name of a control in an addin I am writing. However, when I use the following : string parentName = thisControl.Parent.Name // thisControl is of type Control it is...
1
1219
by: Jeremy | last post by:
Hi all, This is driving me crazy: I am trying to get the name of a child class from a parent class - the catch is that it's in a shared method. Here is what I have so far: Public Class Parent...
14
3234
by: Altman | last post by:
Ok I have a control that is inherited from another class. In the child I put msgbox(me.name) in the load event. What always pops up is the name of the parent class and not the name of the...
7
2007
by: Allan Ebdrup | last post by:
How do I get hold of the type when I have a string that represents the type. For example I have the string "OFiR.Recruitment.Department" And I want to get the type called...
22
4778
by: Boris | last post by:
I'm porting code from Windows to UNIX and ran into a problem with dynamic_cast. Imagine a class hierarchy with three levels: class Level2 derives from Level1 which derives from Base. If you look...
1
1190
by: mark.martinez2 | last post by:
How do I transfer the file name which is input in one .py (an MDI parent frame in wxPython) to another .py (an MDI child frame)? The parent gets the file name from the user via a file select...
0
7112
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
6974
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
7356
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
5448
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
4573
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...
0
3084
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
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1389
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 ...
0
277
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.