Re: [orbitcpp-list] Re: cpp branch: CORBA_Object struct hidden?
Status: Beta
Brought to you by:
philipd
From: <bb...@ya...> - 2002-02-21 22:37:43
|
> I can't think of any way of retaining this C <-> C++ compatibility > if > the CORBA_Object struct definition remains private and subject to > change. But I'm certainly not a C++ expert by any stretch of the > imagination. > > So... thoughts, anyone? More thinking aloud, if anyone still want to pursue this course... If you did inherit CORBA::Object privately from CORBA_Object, then the same piece of memory could be used for C and C++ objects. You would have to have an overloaded operator new and delete for the CORBA::Object which used the C allocator and deallocator for CORBA_Object. It doesn't seem possible that a CORBA::Object could ever exist as a concrete object on the stack since its size cannot be determined but only pointers should ever exist to this type anyway. Allocation on the heap through new should be sufficient and possible. The concrete types are X_var and X_ptr which hold pointers, so this seems OK. A narrow operation might operate like CORBA::XXX_ptr CORBA::XXX_ptr::narrow( const CORBA::Object_ptr & rhs ) { // Note: rhs.internalPtr_ is a CORBA::Object * // a CORBA_Object * is the same as a CORBA::Object * CORBA_Object * rhsPtr = reinterpret_cast<CORBA_Object *>( rhs.internalPtr_ ); // do ORBit narrow on internal pointer CORBA_XXX * newObj = CORBA_XXX_narrow( rhsPtr, env ); // check for exceptions and throw if a bad narrow // this should be OK since CORBA::XXX inherits from CORBA_XXX CORBA::XXX * internalPtr = static_cast<CORBA::XXX *>(newObj); // create new XXX_ptr which is now responsible for newObj return CORBA::XXX_ptr(internalPtr); } When the XXX_ptr deletes its internal pointer, the operator delete for the XXX * will actually call the ORBit routine to deallocate itself (because it is also a CORBA_XXX pointer). (Disclaimer: I've come in half way through this discussion so I may be missing some important point. Also I don't know the C binding.) Or is this all just wrong? http://movies.yahoo.com.au - Yahoo! Movies - Vote for your nominees in our online Oscars pool. |