473,395 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Macros, vTable?

Hi!

I've got an issue. I have more or less an internal class model for
which I want to write various bindings e.g. for Windows COM. Now I've
figured to make my internal classes based on IDispatchEx which works
fine. The biggest pain I have right now is that I need to register
properties and methods dynamically and I need to call those
dynamically, too. Take the following example:

struct method {
short calltype; // 0=property_get, 1=property_set, 2=method
unsigned id;
const char* name;
int* params;
}

class A :
public MyTemplate<A>
{
public:
BEGIN_METHODS(A)
METHOD(0, "something", 1, {})
METHOD(1, "something", 2, {})
METHOD(2, "doSomething", 3, {4,5,2})
END_METHODS
public:
// Properties
virtual std::string get_Something();
virtual void set_Something(const std::string& name);

// Methods
virtual void doSomething();
}
Now in myTemplate I have two functions called from outside, one to get
an unique id for the given name and type and one for calling it. The
question I have is this:

The biggest pain is that I've wanted to call the functions that I have
registered with METHOD() macro directly, passing the parameters
dynamically as an array. But as I'd require my own call stack frame
and my asm knowledge is not the best, I've thought to create two
functions within my BEGIN_METHODS and END_METHODS macros that is, one
for registering the functions which could look like

static const method* _get_methods()
{
...
}

and one that calls it like

void _call_method(int id, params* p)
{
switch( id)
{
case 2: doSomething(p[0].int, p[1].double);
....
}
Now as you can see the issue I have is that I cannot have my Macros
declare two independant functions that is, to be able to create a
_get_methods and a _call_method routine, I'd need to redeclare
evertything like this:
class A :
public MyTemplate<A>
{
public:
BEGIN_METHODS(A) // _get_methods()
METHOD(0, "something", 1, {})
METHOD(1, "something", 2, {})
METHOD(2, "doSomething", 3, {4,5,2})
END_METHODS
BEGIN_METHODS2(A) // _call_method
METHOD(0, (p[0].int, p[1].double))
END_METHODS2
public:
// Properties
virtual std::string get_Something();
virtual void set_Something(const std::string& name);

// Methods
virtual void doSomething();
}
You might see my issue here -- I have to declare everything twice
which is not really nice.

So after fighting and trying and everything for days, I was hoping
that someone could help me out here with a smart advice, hint, help or
anything?

Thanks and Regards
Alexander

Mar 12 '07 #1
5 1840
Alexander Adam wrote:
Hi!

I've got an issue. I have more or less an internal class model for
which I want to write various bindings e.g. for Windows COM. Now I've
figured to make my internal classes based on IDispatchEx which works
fine. The biggest pain I have right now is that I need to register
properties and methods dynamically and I need to call those
dynamically, too. Take the following example:

struct method {
short calltype; // 0=property_get, 1=property_set, 2=method
unsigned id;
const char* name;
int* params;
}

class A :
public MyTemplate<A>
{
public:
BEGIN_METHODS(A)
METHOD(0, "something", 1, {})
METHOD(1, "something", 2, {})
METHOD(2, "doSomething", 3, {4,5,2})
END_METHODS
public:
// Properties
virtual std::string get_Something();
virtual void set_Something(const std::string& name);

// Methods
virtual void doSomething();
}
Now in myTemplate I have two functions called from outside, one to get
an unique id for the given name and type and one for calling it. The
question I have is this:

The biggest pain is that I've wanted to call the functions that I have
registered with METHOD() macro directly, passing the parameters
dynamically as an array. But as I'd require my own call stack frame
and my asm knowledge is not the best, I've thought to create two
functions within my BEGIN_METHODS and END_METHODS macros that is, one
for registering the functions which could look like

static const method* _get_methods()
{
...
}

and one that calls it like

void _call_method(int id, params* p)
{
switch( id)
{
case 2: doSomething(p[0].int, p[1].double);
...
}
Now as you can see the issue I have is that I cannot have my Macros
declare two independant functions that is, to be able to create a
_get_methods and a _call_method routine, I'd need to redeclare
evertything like this:
class A :
public MyTemplate<A>
{
public:
BEGIN_METHODS(A) // _get_methods()
METHOD(0, "something", 1, {})
METHOD(1, "something", 2, {})
METHOD(2, "doSomething", 3, {4,5,2})
END_METHODS
BEGIN_METHODS2(A) // _call_method
METHOD(0, (p[0].int, p[1].double))
END_METHODS2
public:
// Properties
virtual std::string get_Something();
virtual void set_Something(const std::string& name);

// Methods
virtual void doSomething();
}
You might see my issue here -- I have to declare everything twice
which is not really nice.

So after fighting and trying and everything for days, I was hoping
that someone could help me out here with a smart advice, hint, help or
anything?
Well, my honest advice would be give up and do something more productive
with your time. But I guess you don't want me to tell you that.

So.

Why not combine _get_methods and _call_method into a single function?
Any reason that can't be done? Sure it's ugly but you seem to be in ugly
territory anyway.

john
Mar 12 '07 #2
Hi,
Well, my honest advice would be give up and do something more productive
with your time. But I guess you don't want me to tell you that.
How is it you come to that opinion?
The issue here is just that the internal object model is quite huge (>
1800 classes) and I've started building COM Wrappers around each
object but it took way too much time to just implement a few classes
so I've decided to let each single class be the COM Object itself.
So.

Why not combine _get_methods and _call_method into a single function?
Any reason that can't be done? Sure it's ugly but you seem to be in ugly
territory anyway.
Uhm that's what I've tried first, too. The issue is just that I need
to register the function before using it within _call_method. This is
necessary to be able to check for parameters count, types etc. and
combining both into one function wouldn't really work in this case as
the code gets really really unusable. How's it you're saying that I
seem to be in ugly territory anyway, do you mean my C Code is ugly?
Well I've just written that as more or less pseudo code, not saying
that the original code looks as crappy as this one. Or is it that you
say calling dynamic functions is the ugly territory?

I'd be very thankful for some more hints on such kind of issue, I
can't believe I am the only one having this as calling dynamic
functions including dynamic parameters and returns seems to me as a
quite common problem?

Regards
Alexander
Mar 12 '07 #3
Alexander Adam wrote:
Hi!

I've got an issue. I have more or less an internal class model for
which I want to write various bindings e.g. for Windows COM.
If I understand you right, you have some classes written (presumably) in
C++, but you want to publish your framework via Microsoft COM to the
world. This involves a lot of work, as you can only define interfaces in
COM, whereas C++ mixes interfaces and implementation into single
entities. This means that you'll have to untangle interfaces from
implementations by hand, which is going to be quite time-consuming.
Now I've
figured to make my internal classes based on IDispatchEx which works
fine. The biggest pain I have right now is that I need to register
properties and methods dynamically and I need to call those
dynamically, too. Take the following example:
I don't believe that working with IDispatchEx is useful here, as you'll
need to work over your code completely. So instead of doing this, you
may as well start with defining real COM interfaces and make your C++
classes to implementors of these interfaces.

IDispatchEx as COM interface doesn't make sense to me, as it is intended
for dynamically adding properties and methods to objects. Adding
properties can be done by any container class, and adding methods is not
useful (as they cannot access private data members, and that is what
half of object-orientation is all about: encapsulation).

Anyway, if you're using IDispatchEx you'll have to be automation
compatible, and I very much doubt that your C++ framework is automation
compatible. I'd advice you to start introducing real COM (not using
IDispatchEx) interfaces in your project step by step.

Regards,
Stuart
Mar 12 '07 #4
On Mar 12, 2:10 am, "Alexander Adam" <cont...@emiasys.comwrote:
....
Now as you can see the issue I have is that I cannot have my Macros
declare two independant functions that is, to be able to create a
_get_methods and a _call_method routine, I'd need to redeclare
evertything like this:

class A :
public MyTemplate<A>
{
public:
BEGIN_METHODS(A) // _get_methods()
METHOD(0, "something", 1, {})
METHOD(1, "something", 2, {})
METHOD(2, "doSomething", 3, {4,5,2})
END_METHODS

BEGIN_METHODS2(A) // _call_method
METHOD(0, (p[0].int, p[1].double))
END_METHODS2
public:
// Properties
virtual std::string get_Something();
virtual void set_Something(const std::string& name);

// Methods
virtual void doSomething();

}

You might see my issue here -- I have to declare everything twice
which is not really nice.
....

class A :
public MyTemplate<A>
{
public:
#undef L
#define L(METHOD) \
METHOD(0, "something", 1, {}) \
METHOD(1, "something", 2, {}) \
METHOD(2, "doSomething", 3, {4,5,2})

GENERATE_GET(L)

GENERATE_CALL(L)
....

On the other hand, I'm not sure I see why you
can't go with a (macro-free) solution that just
uses an array:

int doSomethingParam[] = {4,5,2};

method myMethods[] =
{
{"something", 1, 0},
{"something", 2, 0},
{"doSomething", 3, doSomethingParam}
};

Mar 12 '07 #5
hi,
>
class A :
public MyTemplate<A>
{
public:
#undef L
#define L(METHOD) \
METHOD(0, "something", 1, {}) \
METHOD(1, "something", 2, {}) \
METHOD(2, "doSomething", 3, {4,5,2})

GENERATE_GET(L)

GENERATE_CALL(L)
...

On the other hand, I'm not sure I see why you
can't go with a (macro-free) solution that just
uses an array:

int doSomethingParam[] = {4,5,2};

method myMethods[] =
{
{"something", 1, 0},
{"something", 2, 0},
{"doSomething", 3, doSomethingParam}

};
I would love to go with a macro free solution but the issue is exactly
what you mention here -- how tp pass the doSomethingParam over to the
dynamic function call? Because it is not one array of int but it can
be an array of different types and should go directly into the
function which could look like doSomething(int aNumber, string
aValue, ..)

Regards
Alexander

Mar 13 '07 #6

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

Similar topics

2
by: Quansheng Liang | last post by:
Hello, I struggled with the problem of "undefined reference to `vtable ...`" while migrating a project from windows to linux. After searching the google I removed all the inline functions and now...
6
by: Nolan Martin | last post by:
Hello, I was wondering if it were possible to access the vtable directly. Are there any resources that detail the inner workings of the vtable?
7
by: Karl Ebener | last post by:
Hi! I have created a program using several classes with inheritage. When I compile and link, I get the following error: :$ g++ service2.cpp Service.cpp Application.cpp Message.cpp...
4
by: Clint Ruen | last post by:
Hello all, I have written out a data structure using the binary flag on an ofstream. The struct/class is something like this class SomeData { public: int data1;
4
by: rahul8143 | last post by:
hello, what happens to VTABLE when base class has virtual function and derived class does not override it? Does derived class also builds VTABLE if it has no functions? eg. if code is like...
9
by: kish_nand | last post by:
Could someone please explain me the concept behind virtual functions and vtables. I am little confused about this. Please refer to the following code and tell me how many virtual tables would be...
17
by: ypjofficial | last post by:
Hello All, I have read in many c++ literature that vtable is nothing but an array of pointer to virtual functions inside a class.And the class where the virtual function/s are declared stores the...
5
by: druberego | last post by:
I read google and tried to find the solution myself. YES I do know that you can get undefined references if you: a) forget to implement the code for a prototype/header file item, or b) you forget...
10
by: Ole Nielsby | last post by:
James Kanze <james.kanze@gmail.comwrote: COM does rely on vtable layout. COM interfaces are declared as pure virtual classes, all methods using stdcall convention, and this works because most...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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
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,...

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.