Difference between revisions of "Documentation/DevGuide/WritingUNO/Preprocessing"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (FINAL VERSION FOR L10N)
 
Line 9: Line 9:
 
{{DISPLAYTITLE:Preprocessing}}
 
{{DISPLAYTITLE:Preprocessing}}
 
Just like a C++ compiler, the UNOIDL compiler ''idlc'' can only use types it already knows. The idlc knows 15 simple types such as boolean, int or string (they are summarized below). Whenever a type other than a simple type is used in the idl file, its declaration has to be included first. For instance, to derive an interface from the interface XInterface, include the corresponding file <code>XInterface.idl</code>. Including means telling the preprocessor to read a given file and execute the instructions found in it.
 
Just like a C++ compiler, the UNOIDL compiler ''idlc'' can only use types it already knows. The idlc knows 15 simple types such as boolean, int or string (they are summarized below). Whenever a type other than a simple type is used in the idl file, its declaration has to be included first. For instance, to derive an interface from the interface XInterface, include the corresponding file <code>XInterface.idl</code>. Including means telling the preprocessor to read a given file and execute the instructions found in it.
<source lang="idl">
+
<syntaxhighlight lang="idl">
 
// searched in include path given in -I parameter
 
// searched in include path given in -I parameter
 
   #include <com/sun/star/uno/XInterface.idl>  
 
   #include <com/sun/star/uno/XInterface.idl>  
Line 15: Line 15:
 
// searched in current path, then in include path
 
// searched in current path, then in include path
 
   #include "com/sun/star/uno/XInterface.idl"  
 
   #include "com/sun/star/uno/XInterface.idl"  
</source>
+
</syntaxhighlight>
 
There are two ways to include idl files. A file name in angled brackets is searched on the include path passed to ''idlc'' using its -I option. File names in double quotes are first searched on the current path and then on the include path.
 
There are two ways to include idl files. A file name in angled brackets is searched on the include path passed to ''idlc'' using its -I option. File names in double quotes are first searched on the current path and then on the include path.
  
 
The <code>XUnoUrlResolver</code> definition above includes <idl>com.sun.star.uno.XInterface</idl> and the three exceptions thrown by the method <code>resolve()</code>, <idl>com.sun.star.lang.IllegalArgumentException</idl>, <idl>com.sun.star.connection.ConnectionSetupException</idl> and <idl>com.sun.star.connection.NoConnectException</idl>.  
 
The <code>XUnoUrlResolver</code> definition above includes <idl>com.sun.star.uno.XInterface</idl> and the three exceptions thrown by the method <code>resolve()</code>, <idl>com.sun.star.lang.IllegalArgumentException</idl>, <idl>com.sun.star.connection.ConnectionSetupException</idl> and <idl>com.sun.star.connection.NoConnectException</idl>.  
  
In {{PRODUCTNAME}} {{OOo2.x}}, it is no longer necessary to explicitly state that an interface type derives from <code>XInterface</code> - if an interface type derives from no other interface type, it is implicitly taken to derive from <code>XInterface</code>. However, even in such situations it is important to explicitly include the file <code>XInterface.idl</code>.
+
In OpenOffice.org 2.x, it is no longer necessary to explicitly state that an interface type derives from <code>XInterface</code> - if an interface type derives from no other interface type, it is implicitly taken to derive from <code>XInterface</code>. However, even in such situations it is important to explicitly include the file <code>XInterface.idl</code>.
  
 
Furthermore, to avoid warnings about redefinition of already included types, use <code>#ifndef</code> and <code>#define</code> as shown above. Note how the entire definition for <code>XUnoUrlResolver</code> is enclosed between <code>#ifndef</code> and <code>#endif</code>. The first thing the preprocessor does is to check if the flag <code>__com_sun_star_bridge_XUnoUrlResolver_idl__</code> has already been defined. If not, the flag is defined and ''idlc'' continues with the definition of <code>XUnoUrlResolver</code>.
 
Furthermore, to avoid warnings about redefinition of already included types, use <code>#ifndef</code> and <code>#define</code> as shown above. Note how the entire definition for <code>XUnoUrlResolver</code> is enclosed between <code>#ifndef</code> and <code>#endif</code>. The first thing the preprocessor does is to check if the flag <code>__com_sun_star_bridge_XUnoUrlResolver_idl__</code> has already been defined. If not, the flag is defined and ''idlc'' continues with the definition of <code>XUnoUrlResolver</code>.
  
Adhere to the naming scheme for include flags used by the {{PRODUCTNAME}} developers: Use the file name of the IDL file that is to be included, add double underscores at the beginning and end of the macro, and replace all slashes and dots by underscores.
+
Adhere to the naming scheme for include flags used by the {{AOo}} developers: Use the file name of the IDL file that is to be included, add double underscores at the beginning and end of the macro, and replace all slashes and dots by underscores.
  
 
For other preprocessing instructions supported by ''idlc'' refer to Bjarne Stroustrup: [http://www.research.att.com/~bs/3rd.html The C++ Programming Language].
 
For other preprocessing instructions supported by ''idlc'' refer to Bjarne Stroustrup: [http://www.research.att.com/~bs/3rd.html The C++ Programming Language].

Latest revision as of 16:12, 23 December 2020



Just like a C++ compiler, the UNOIDL compiler idlc can only use types it already knows. The idlc knows 15 simple types such as boolean, int or string (they are summarized below). Whenever a type other than a simple type is used in the idl file, its declaration has to be included first. For instance, to derive an interface from the interface XInterface, include the corresponding file XInterface.idl. Including means telling the preprocessor to read a given file and execute the instructions found in it.

// searched in include path given in -I parameter
  #include <com/sun/star/uno/XInterface.idl> 
 
// searched in current path, then in include path
  #include "com/sun/star/uno/XInterface.idl"

There are two ways to include idl files. A file name in angled brackets is searched on the include path passed to idlc using its -I option. File names in double quotes are first searched on the current path and then on the include path.

The XUnoUrlResolver definition above includes com.sun.star.uno.XInterface and the three exceptions thrown by the method resolve(), com.sun.star.lang.IllegalArgumentException, com.sun.star.connection.ConnectionSetupException and com.sun.star.connection.NoConnectException.

In OpenOffice.org 2.x, it is no longer necessary to explicitly state that an interface type derives from XInterface - if an interface type derives from no other interface type, it is implicitly taken to derive from XInterface. However, even in such situations it is important to explicitly include the file XInterface.idl.

Furthermore, to avoid warnings about redefinition of already included types, use #ifndef and #define as shown above. Note how the entire definition for XUnoUrlResolver is enclosed between #ifndef and #endif. The first thing the preprocessor does is to check if the flag __com_sun_star_bridge_XUnoUrlResolver_idl__ has already been defined. If not, the flag is defined and idlc continues with the definition of XUnoUrlResolver.

Adhere to the naming scheme for include flags used by the Apache OpenOffice developers: Use the file name of the IDL file that is to be included, add double underscores at the beginning and end of the macro, and replace all slashes and dots by underscores.

For other preprocessing instructions supported by idlc refer to Bjarne Stroustrup: The C++ Programming Language.

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