Difference between revisions of "Documentation/DevGuide/FirstSteps/Common Types"

From Apache OpenOffice Wiki
Jump to: navigation, search
(FINAL VERSION FOR L10N)
(35 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<maintab>[[Development Concepts|Concepts]]||[[Programming|Programming]]||[[Applications|Applications]]||[[Get Started|Get Started]]||[[Get Objects|Get Objects]]||[[Work with Objects|Work with Objects]]||[[Types|Types]]||[[Example|Example]]</maintab>
+
{{Documentation/DevGuide/FirstStepsTOC
<subtab>[[Objects, Interfaces, and Services|Objects, Interfaces, and Services]]||[[Using Services|Using Services]]||[[Example Spreadsheet|Example Spreadsheet]]||[[Common Types|Types]]||[[Struct|Struct]]||[[Any|Any]]||[[Sequence|Sequence]]||[[Elements|Elements]]</subtab>
+
|FirstSteps2b=block
Until now, literals and common Java types for method parameters and return values have been used as if the [PRODUCTNAME] API was made for Java. However, it is important to understand that UNO is designed to be language independent and therefore has its own set of types which have to be mapped to the proper types for your language binding. The type mappings are briefly described in this section. Refer to [CHAPTER:ProfUNO] for detailed information about type mappings.  
+
|ShowPrevNext=block
 +
|PrevPage=Documentation/DevGuide/FirstSteps/Example: Working with a Spreadsheet Document
 +
|NextPage=Documentation/DevGuide/FirstSteps/Struct
 +
}}
 +
{{Documentation/DevGuideLanguages|Documentation/DevGuide/FirstSteps/{{SUBPAGENAME}}}}
 +
{{DISPLAYTITLE:Common Types}}
 +
Until now, literals and common Java types for method parameters and return values have been used as if the {{PRODUCTNAME}} API was made for Java. However, it is important to understand that UNO is designed to be language independent and therefore has its own set of types which have to be mapped to the proper types for your language binding. The type mappings are briefly described in this section. Refer to [[Documentation/DevGuide/ProUNO/Professional UNO|Professional UNO]] for detailed information about type mappings.  
  
====Basic Types====
+
===Basic Types===
The basic UNO types (where the term “basic” has nothing to do with [Productname] Basic) occur as members of structs, as method return types or method parameters. The following table shows the basic UNO types and, if available, their exact mappings to Java, C++, and [PRODUCTNAME] Basic types.  
+
The basic UNO types (where the term “basic” has nothing to do with {{PRODUCTNAME}} Basic) occur as members of structs, as method return types or method parameters. The following table shows the basic UNO types and, if available, their exact mappings to Java, C++, and {{PRODUCTNAME}} Basic types.  
{|
+
|-
+
|UNO
+
 
+
|Type description
+
 
+
|Java
+
 
+
|C++
+
 
+
|Basic
+
  
 +
{|border="1" cellpadding=4 style="border-collapse:collapse;"
 +
|-bgcolor=#EDEDED
 +
!  UNO        !!Type description                        !!Java  !!C++    !!  Basic
 
|-
 
|-
|void
+
|void         ||empty type, used only as method return type and in <code>any</code>||void||void||-
 
+
|empty type, used only as method return type and in any
+
 
+
|void
+
 
+
|void
+
 
+
 
|-
 
|-
 
+
|boolean      ||Boolean type; true and false            ||boolean||sal_Bool  ||Boolean
 
|-
 
|-
|boolean
+
|byte          ||signed 8-bit integer type               ||byte  ||sal_Int8  ||Integer
 
+
|Boolean type; true and false
+
 
+
|boolean
+
 
+
|sal_Bool
+
 
+
|Boolean
+
 
+
 
|-
 
|-
|byte
+
|short        ||signed 16-bit integer type               ||short  ||sal_Int16 ||Integer
 
+
|signed 8-bit integer type
+
 
+
|byte
+
 
+
|sal_Int8
+
 
+
|Integer
+
 
+
 
|-
 
|-
|short
+
|unsigned short||unsigned 16-bit integer type (deprecated)||-      ||sal_uInt16||-
 
+
|signed 16-bit integer type
+
 
+
|short
+
 
+
|sal_Int16
+
 
+
|Integer
+
 
+
 
|-
 
|-
|unsigned short
+
|long          ||signed 32-bit integer type               ||int    ||sal_Int32 ||Long
 
+
|unsigned 16-bit integer type (deprecated)
+
 
+
 
|-
 
|-
 
+
|unsigned long ||unsigned 32-bit integer type (deprecated)||-      ||sal_uInt32||-
|sal_uInt16
+
 
+
 
|-
 
|-
 
+
|hyper        ||signed 64-bit integer type              ||long  ||sal_Int64 ||-
 
|-
 
|-
|long
+
|unsigned hyper||unsigned 64-bit integer type (deprecated)||-      ||sal_uInt64||-
 
+
|signed 32-bit integer type
+
 
+
|int
+
 
+
|sal_Int32
+
 
+
|Long
+
 
+
 
|-
 
|-
|unsigned long
+
|float        ||IEC 60559 single precision floating point type||float||float (if appropriate)||Single
 
+
|unsigned 32-bit integer type (deprecated)
+
 
+
 
|-
 
|-
 
+
|double        ||IEC 60559 double precision floating point type||double||double (if appropriate)||Double
|sal_uInt32
+
 
+
 
|-
 
|-
 +
|char          ||16-bit Unicode character type (more precisely: UTF-16 code units)-||char||sal_Unicode||-
 +
|}
 +
There are special conditions for types that do not have an exact mapping in this table. Check for details about these types in the corresponding sections about type mappings in [[Documentation/DevGuide/ProUNO/UNO Language Bindings|UNO Language Bindings]].
  
|-
+
===Strings===
|hyper
+
UNO considers strings to be simple types, but since they need special treatment in some environments, we discuss them separately here.
 
+
|signed 64-bit integer type
+
 
+
|long
+
 
+
|sal_Int64
+
  
 +
{|border="1" cellpadding=4 style="border-collapse:collapse;"
 +
|-bgcolor=#EDEDED
 +
!UNO!!Description!!Java!!C++!!Basic
 
|-
 
|-
 
+
|string||Unicode string type (more precisely: strings of Unicode scalar values)||java.lang.­String||rtl::OUString||String
|-
+
|unsigned hyper
+
 
+
|unsigned 64-bit integer type (deprecated)
+
 
+
|-
+
 
+
|sal_uInt64
+
 
+
|-
+
 
+
|-
+
|float
+
 
+
|IEC 60559 single precision floating point type
+
 
+
|float
+
 
+
|float (if appropriate)
+
 
+
|Single
+
 
+
|-
+
|double
+
 
+
|IEC 60559 double precision floating point type
+
 
+
|double
+
 
+
|double (if appropriate)
+
 
+
|Double
+
 
+
|-
+
|char
+
 
+
|16-bit Unicode character type (more precisely: UTF-16 code units)-
+
 
+
|char
+
 
+
|sal_Unicode
+
 
+
|-
+
 
+
 
|}
 
|}
There are special conditions for types that do not have an exact mapping in this table. Check for details about these types in the corresponding sections about type mappings in [CHAPTER:ProfUNO.LangBind].
 
  
====Strings====
+
In Java, use UNO strings as if they were native <code>java.lang.String</code> objects.
UNO considers strings to be simple types, but since they need special treatment in some environments, we discuss them separately here.
+
In C++, native <code>char</code> strings must be converted to UNO Unicode strings by means of SAL conversion functions, usually the function <code>createFromAscii()</code> in the <code>rtl::OUString</code> class:
{|
+
|-
+
|UNO
+
  
|Description
+
  <source lang="cpp">
 +
  //C++
 +
  static OUString createFromAscii( const sal_Char * value ) throw();
 +
  </source>
  
|Java
+
In Basic, Basic strings are mapped to UNO strings transparently.
  
|C++
+
===Enum Types and Groups of Constants===
 +
The {{PRODUCTNAME}} API uses many enumeration types (called enums) and groups of constants (called constant groups). ''Enums'' are used to list every plausible value in a certain context. The ''constant'' groups define possible values for properties, parameters, return values and struct members.
 +
For example, there is an enum <idl>com.sun.star.table.CellVertJustify</idl> that describes the possible values for the vertical adjustment of table cell content. The vertical adjustment of table cells is determined by their property [http://api.openoffice.org/docs/common/ref/com/sun/star/table/CellProperties.html#VertJustify com.sun.star.table.CellProperties:VertJustify]. The possible values for this property are, according to <code>CellVertJustify</code>, the values <code>STANDARD</code>, <code>TOP</code>, <code>CENTER</code> and <code>BOTTOM</code>.
  
|Basic
+
  <source lang="java">
 +
  // adjust a cell content to the upper cell border
 +
  // The service com.sun.star.table.Cell includes the service com.sun.star.table.CellProperties
 +
  // and therefore has a property VertJustify that controls the vertical cell adjustment
 +
  // we have to use the XPropertySet interface of our Cell to set it
 +
 
 +
  xCellProps.setPropertyValue("VertJustify", com.sun.star.table.CellVertJustify.TOP);
 +
  </source>
  
|-
+
{{PRODUCTNAME}} Basic understands enumeration types and constant groups. Their usage is straightforward:
|string
+
  
|Unicode string type (more precisely: strings of Unicode scalar values)
+
  <source lang="vb">
 +
  'OpenOffice.org Basic
 +
  oCellProps.VertJustify = com.sun.star.table.CellVertJustify.TOP
 +
  </source>
  
|java.lang.­String
+
In C++ enums and constant groups are used with the scope operator <code>::</code>
  
|rtl::OUString
+
  <source lang="java">
 
+
|String
+
 
+
|}
+
In Java, use UNO strings as if they were native java.lang.String objects.
+
In C++, native char strings must be converted to UNO Unicode strings by means of SAL conversion functions, usually the function createFromAscii() in the rtl::OUString class:
+
 
   //C++
 
   //C++
   static OUString createFromAscii( const sal_Char * value ) throw();
+
   rCellProps->setPropertyValue(OUString::createFromAscii( "VertJustify"),
In Basic, Basic strings are mapped to UNO strings transparently.
+
          ::com::sun::star::table::CellVertJustify.TOP);
 
+
  </source>
====Enum Types and Groups of Constants====
+
The [PRODUCTNAME] API uses many enumeration types (called enums) and groups of constants (called constant groups). Enums are used to list every plausible value in a certain context. The constant groups define possible values for properties, parameters, return values and struct members.
+
For example, there is an enum [IDL:com.sun.star.table.CellVertJustify] that describes the possible values for the vertical adjustment of table cell content. The vertical adjustment of table cells is determined by their property [IDL:com.sun.star.table.CellProperties:VertJustify]. The possible values for this property are, according to CellVertJustify, the values STANDARD, TOP, CENTER and BOTTOM.
+
// adjust a cell content to the upper cell border
+
// The service com.sun.star.table.Cell includes the service com.sun.star.table.CellProperties
+
// and therefore has a property VertJustify that controls the vertical cell adjustment
+
// we have to use the XPropertySet interface of our Cell to set it
+
  
xCellProps.setPropertyValue("VertJustify", com.sun.star.table.CellVertJustify.TOP);
+
{{PDL1}}
[PRODUCTNAME] Basic understands enumeration types and constant groups. Their usage is straightforward:
+
'[PRODUCTNAME] Basic
+
oCellProps.VertJustify = com.sun.star.table.CellVertJustify.TOP
+
In C++ enums and constant groups are used with the scope operator ::
+
//C++
+
rCellProps->setPropertyValue(OUString::createFromAscii( "VertJustify" ),
+
::com::sun::star::table::CellVertJustify.TOP);
+
  
[[Category: Development Concepts]]
+
[[Category:Documentation/Developer's Guide/First Steps]]

Revision as of 09:17, 18 May 2009



Until now, literals and common Java types for method parameters and return values have been used as if the OpenOffice.org API was made for Java. However, it is important to understand that UNO is designed to be language independent and therefore has its own set of types which have to be mapped to the proper types for your language binding. The type mappings are briefly described in this section. Refer to Professional UNO for detailed information about type mappings.

Basic Types

The basic UNO types (where the term “basic” has nothing to do with OpenOffice.org Basic) occur as members of structs, as method return types or method parameters. The following table shows the basic UNO types and, if available, their exact mappings to Java, C++, and OpenOffice.org Basic types.

UNO Type description Java C++ Basic
void empty type, used only as method return type and in any void void -
boolean Boolean type; true and false boolean sal_Bool Boolean
byte signed 8-bit integer type byte sal_Int8 Integer
short signed 16-bit integer type short sal_Int16 Integer
unsigned short unsigned 16-bit integer type (deprecated) - sal_uInt16 -
long signed 32-bit integer type int sal_Int32 Long
unsigned long unsigned 32-bit integer type (deprecated) - sal_uInt32 -
hyper signed 64-bit integer type long sal_Int64 -
unsigned hyper unsigned 64-bit integer type (deprecated) - sal_uInt64 -
float IEC 60559 single precision floating point type float float (if appropriate) Single
double IEC 60559 double precision floating point type double double (if appropriate) Double
char 16-bit Unicode character type (more precisely: UTF-16 code units)- char sal_Unicode -

There are special conditions for types that do not have an exact mapping in this table. Check for details about these types in the corresponding sections about type mappings in UNO Language Bindings.

Strings

UNO considers strings to be simple types, but since they need special treatment in some environments, we discuss them separately here.

UNO Description Java C++ Basic
string Unicode string type (more precisely: strings of Unicode scalar values) java.lang.­String rtl::OUString String

In Java, use UNO strings as if they were native java.lang.String objects. In C++, native char strings must be converted to UNO Unicode strings by means of SAL conversion functions, usually the function createFromAscii() in the rtl::OUString class:

  //C++
  static OUString createFromAscii( const sal_Char * value ) throw();

In Basic, Basic strings are mapped to UNO strings transparently.

Enum Types and Groups of Constants

The OpenOffice.org API uses many enumeration types (called enums) and groups of constants (called constant groups). Enums are used to list every plausible value in a certain context. The constant groups define possible values for properties, parameters, return values and struct members. For example, there is an enum com.sun.star.table.CellVertJustify that describes the possible values for the vertical adjustment of table cell content. The vertical adjustment of table cells is determined by their property com.sun.star.table.CellProperties:VertJustify. The possible values for this property are, according to CellVertJustify, the values STANDARD, TOP, CENTER and BOTTOM.

  // adjust a cell content to the upper cell border
  // The service com.sun.star.table.Cell includes the service com.sun.star.table.CellProperties
  // and therefore has a property VertJustify that controls the vertical cell adjustment
  // we have to use the XPropertySet interface of our Cell to set it
 
  xCellProps.setPropertyValue("VertJustify", com.sun.star.table.CellVertJustify.TOP);

OpenOffice.org Basic understands enumeration types and constant groups. Their usage is straightforward:

  'OpenOffice.org Basic
  oCellProps.VertJustify = com.sun.star.table.CellVertJustify.TOP

In C++ enums and constant groups are used with the scope operator ::

  //C++
  rCellProps->setPropertyValue(OUString::createFromAscii( "VertJustify"),
          ::com::sun::star::table::CellVertJustify.TOP);
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages