Re: [cpp] Implementing structs: generic forwarders



On 14 Mar 2002, Murray Cumming wrote:

> 'the C struct'? You've put them in some kind of intermediate C++ class.
> I know that if I look at all this code I'll be able to figure out what
> you're doing, but it seems like it'd be easier for you to just tell us.
>  
> > I've pulled the term 'forwarder' from my... let's not get into that :)
> 
> Fair enough, but when creating names you should create a definition.

OK so here's the deal (I was hoping the code would be self-describing, but
alas, it looks like it's not)

The C++ mapping of CORBA structures requires allowing direct access to the
members of the structure from both code implementing services and code
that uses them. Our struct wrappers contain, as a private member, a C
structure as created by the C IDL compiler. So you need a way to 'forward'
assignments and method calls on the members of the C++ struct to the
'real' C objects which are stored in the C struct.

For example, given the following IDL:

module Test
{

	struct Foo
	{
		IFace bar;
	}
}

the following C code is generated (roughly):

struct Test_Foo
{
	Test_IFace bar;
}

Fair enough, you can access its member from C:

	Test_Foo foo;
	foo.bar = some_bar;
	Test_IFace_method (foo.bar, ev);

The following C++ code is generated:

namespace Test
{
	class Foo
	{
		Test_Foo c_struct;
	public:
		::Test::IFace_forwarder bar;
	}
}

This way, the following C++ code works, just like it should, and is
equivlaent to the C code above:

	Test::Foo foo;
	foo.bar = some_bar;
	foo.bar->method ();


Does that make it clear?

-- 
   .--= ULLA! =---------------------.   `We are not here to give users what
   \     http://cactus.rulez.org     \   they want'  -- RMS, at GUADEC 2001
    `---= cactus@cactus.rulez.org =---'
How can I insert disk #3 when only two will fit?




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]