Difference between revisions of "Documentation/DevGuide/ProUNO/C++/Mapping of Singletons"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Robot: Changing Category:Professional UNO)
 
(3 intermediate revisions by 2 users not shown)
Line 7: Line 7:
 
|NextPage=Documentation/DevGuide/ProUNO/C++/Using Weak References
 
|NextPage=Documentation/DevGuide/ProUNO/C++/Using Weak References
 
}}
 
}}
 +
{{Documentation/DevGuideLanguages|Documentation/DevGuide/ProUNO/C++/{{SUBPAGENAME}}}}
 
{{DISPLAYTITLE:Mapping of Singletons}}
 
{{DISPLAYTITLE:Mapping of Singletons}}
 
A new-style singleton of the form
 
A new-style singleton of the form
Line 13: Line 14:
  
 
is mapped to a C++ class with the same name. The class has a single member function
 
is mapped to a C++ class with the same name. The class has a single member function
 
+
<syntaxhighlight lang="cpp">
 
   public:
 
   public:
 
   static com::sun::star::uno::Reference< XIfc > get(
 
   static com::sun::star::uno::Reference< XIfc > get(
 
       com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > const & context)  
 
       com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > const & context)  
 
       throw (com::sun::star::uno::RuntimeException) { ... }
 
       throw (com::sun::star::uno::RuntimeException) { ... }
 
+
</syntaxhighlight>
 
The semantics of such a singleton getter function in C++ are as follows (they are the same as for Java):
 
The semantics of such a singleton getter function in C++ are as follows (they are the same as for Java):
  
 
* The <idl>com.sun.star.uno.XComponentContext</idl> argument must be non-null.
 
* The <idl>com.sun.star.uno.XComponentContext</idl> argument must be non-null.
* The singleton getter uses [http://api.openoffice.org/docs/common/ref/com/sun/star/uno/XComponentContext.html#getValueByName com.sun.star.uno.XComponentContext:getValueByName] to obtain the singleton instance (within the "<code>/singletons/</code>" name space).
+
* The singleton getter uses <idlm>com.sun.star.uno.XComponentContext:getValueByName</idlm> to obtain the singleton instance (within the "<code>/singletons/</code>" name space).
 
* If no singleton instance could be obtained, the singleton getter fails by throwing a <idl>com.sun.star.uno.DeploymentException</idl>. The net effect is that a singleton getter either returns the requested non-null singleton instance, or throws an exception; a singleton getter will never return a null instance.
 
* If no singleton instance could be obtained, the singleton getter fails by throwing a <idl>com.sun.star.uno.DeploymentException</idl>. The net effect is that a singleton getter either returns the requested non-null singleton instance, or throws an exception; a singleton getter will never return a null instance.
  
Line 29: Line 30:
 
{{PDL1}}
 
{{PDL1}}
  
[[Category:Documentation/Developers Guide/Professional UNO]]
+
[[Category:Documentation/Developer's Guide/Professional UNO]]

Latest revision as of 13:14, 23 December 2020



A new-style singleton of the form

 singleton Name: XIfc;

is mapped to a C++ class with the same name. The class has a single member function

  public:
  static com::sun::star::uno::Reference< XIfc > get(
      com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > const & context) 
      throw (com::sun::star::uno::RuntimeException) { ... }

The semantics of such a singleton getter function in C++ are as follows (they are the same as for Java):

  • The com.sun.star.uno.XComponentContext argument must be non-null.
  • The singleton getter uses getValueByName to obtain the singleton instance (within the "/singletons/" name space).
  • If no singleton instance could be obtained, the singleton getter fails by throwing a com.sun.star.uno.DeploymentException. The net effect is that a singleton getter either returns the requested non-null singleton instance, or throws an exception; a singleton getter will never return a null instance.

Old-style services are not mapped into the C++ language binding.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages