Common Types

From Apache OpenOffice Wiki
< Documentation‎ | DevGuide
Revision as of 15:47, 15 February 2021 by DiGro (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Until now, literals and common Java types for method parameters and return values have been used as if the Apache OpenOffice 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 Apache OpenOffice 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 Apache OpenOffice 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.


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:

  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 Apache OpenOffice 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 that describes the possible values for the vertical adjustment of table cell content. The vertical adjustment of table cells is determined by their property 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 includes the service
  // 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

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

  'OpenOffice Basic
  oCellProps.VertJustify =

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

  rCellProps->setPropertyValue(OUString::createFromAscii( "VertJustify"),
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages