Le Mercredi 27 Juillet 2005 15:22, Daniel Boelzle a écrit :
> Hello Pierre-André,

Hi Daniel,

> > using namespace com::sun::star::uno;
>
> side-note: using directives are bad in header files.  Use fully
> qualified names.

:-) Thanks, I will correct that.

> > class MyClass
> > {
> >
> >   public:
> >       connect();
> >       set_text();
> >
> >   private :
> >       // OK
> >       XInterface*  rInstance2;                
> >
> >       // Not OK because needs to be a pointer or a reference.
> >               Reference< XInterface > rInstance;
> > };
>
> This does not work.  I would recommend that you "pimpl" your class,
> hiding implementation details in a separate class, e.g.

> hpp file:
> // no need not to include OOo header files
> #include <memory>
> ...
> class MyClass
> {
> private:
>     class MyClassImpl;
>     ::std::auto_ptr<MyClassImpl> const m_pImpl;
> };
>
> cpp file:
> // using OOo headers, definitions of
> class MyClass::MyClassImpl ...
> class MyClass ...

Hum, the class I showed you is supposed already to be a class to hide OOo 
details...

> But if you only have to hold a single interface member, it is probably
> shorter to just use the plain "XInterface *", manually managing lifetime
> via acquire() / release().

From the Dev's Guide : "Acquire and release must be implemented in a 
thread-safe fashion."

Sounds scarry ;-)

How would that work ? Would it be ok that way :

- hpp file

class MyClass
{
   public:
       connect();

   private :
       XInterface*  rInstance; 
};


- cpp file :

MyClass::Myclass
{
        rInstance = new XInterface;
        *rInstance.acquire();
};

// Can release throw ? Hope it does not !
MyClass::~Myclass
{
        *rInstance.release();
};

void MyClass::connect()
{
        // Would this work ?
        *rInstance = rServiceManager->createInstanceWithContext(
                OUString::createFromAscii( "com.sun.star.bridge.UnoUrlResolver" 
),
                rComponentContext );
        ...
}


By the way, it now works using a pointer to the Reference.
Reference< XInterface > *rInstance;

Thanks for the comments,,
Pierre-André
-- 
StarXpert - www.starxpert.fr
e-mail : [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to