Difference between revisions of "Documentation/DevGuide/WritingUNO/C++/Storing the Service Manager for Further Use"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (FINAL VERSION FOR L10N)
 
Line 7: Line 7:
 
{{Documentation/DevGuideLanguages|Documentation/DevGuide/WritingUNO/C++/{{SUBPAGENAME}}}}
 
{{Documentation/DevGuideLanguages|Documentation/DevGuide/WritingUNO/C++/{{SUBPAGENAME}}}}
 
{{DISPLAYTITLE:Storing the Service Manager for Further Use}}
 
{{DISPLAYTITLE:Storing the Service Manager for Further Use}}
The single factories expect a static <code>create_< ''ImplementationClass>'' ()</code> function. For instance, <code>create_MyService1Impl()</code> takes a reference to the component context and instantiates the implementation class using new <code>ImplementationClass()</code>. A constructor can be written for <code><ImplementationClass></code> that expects a reference to an <idl>com.sun.star.uno.XComponentContext</idl> and stores the reference in the instance for further use.
+
The single factories expect a static <code>create_< ''ImplementationClass>'' ()</code> function. For instance, <code>create_MyService1Impl()</code> takes a reference to the component context and instantiates the implementation class using new <code>ImplementationClass()</code>. A constructor can be written for <code><ImplementationClass></code> that expects a reference to a <idl>com.sun.star.uno.XComponentContext</idl> and stores the reference in the instance for further use.
<source lang="cpp">
+
<syntaxhighlight lang="cpp">
 
   static Reference< XInterface > SAL_CALL create_MyService2Impl(
 
   static Reference< XInterface > SAL_CALL create_MyService2Impl(
 
       Reference< XComponentContext > const & xContext )
 
       Reference< XComponentContext > const & xContext )
Line 16: Line 16:
 
       return static_cast< lang::XTypeProvider * >( new MyService2Impl( xContext ) );
 
       return static_cast< lang::XTypeProvider * >( new MyService2Impl( xContext ) );
 
   }
 
   }
</source>
+
</syntaxhighlight>
 
{{PDL1}}
 
{{PDL1}}
  
 
[[Category:Documentation/Developer's Guide/Writing UNO Components]]
 
[[Category:Documentation/Developer's Guide/Writing UNO Components]]

Latest revision as of 14:37, 24 December 2020



The single factories expect a static create_< ImplementationClass> () function. For instance, create_MyService1Impl() takes a reference to the component context and instantiates the implementation class using new ImplementationClass(). A constructor can be written for <ImplementationClass> that expects a reference to a com.sun.star.uno.XComponentContext and stores the reference in the instance for further use.

  static Reference< XInterface > SAL_CALL create_MyService2Impl(
      Reference< XComponentContext > const & xContext )
      SAL_THROW( () )
  {
      // passing the component context to the constructor of MyService2Impl
      return static_cast< lang::XTypeProvider * >( new MyService2Impl( xContext ) );
  }
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages