常见类型

From Apache OpenOffice Wiki
Jump to: navigation, search



到目前为止,已使用了方法参数和返回值的文字和常见 Java 类型,就好像 OpenOffice.org API 是专为 Java 而设计。但是,您需要知道 UNO 是与语言无关的,因此它具有自己的类型集,这些类型需要 映射到您语言绑定的相应类型。本节将简要介绍这种类型映射。有关类型映射的详细信息,请参阅 专业 UNO


基本类型

基本 UNO 类型(其中“基本”与 OpenOffice.org Basic 无关)作为结构的成员、方法返回类型或方法参数出现。下表显示基本 UNO 类型,以及这些类型至 Java、C++ 和 OpenOffice.org Basic 类型的准确映射(如果可用)。


UNO 类型说明 Java C++ Basic
void 空类型,仅在 any 中用作方法返回类型 void void -
boolean 布尔类型;true 和 false boolean sal_Bool Boolean
byte 有符号 8 位整数类型 byte sal_Int8 Integer
short 有符号 16 位整数类型 short sal_Int16 Integer
unsigned short 无符号 16 位整数类型(已过时) - sal_uInt16 -
long 有符号 32 位整数类型 int sal_Int32 Long
unsigned long 无符号 32 位整数类型(已过时) - sal_uInt32 -
hyper 有符号 64 位整数类型 long sal_Int64 -
unsigned hyper 无符号 64 位整数类型(已过时) - sal_uInt64 -
float IEC 60559 单精度浮点类型 float float(如果适用) Single
double IEC 60559 双精度浮点类型 double double(如果适用) Double
char 16 位 Unicode 字符类型(更确切地说是 UTF-16代码单元)- char sal_Unicode -


对于此表中没有准确映射的类型,存在一些特殊的条件。有关这些类型的详细信息,请查阅章节 专业 UNO - UNO 语言绑定 中有关类型映射的部分。


字符串

UNO 将字符串看作简单类型,但由于在某些环境中需要对字符串进行特殊处理,因此我们单独在此 处对它们进行一下介绍。

UNO 说明 Java C++ Basic
string Unicode 字符串类型(更确切地说是 Unicode 标量值的字符串) java.lang.­String rtl::OUString String


在 Java 中,可以将 UNO 字符串当作本地 java.lang.String 对象来使用。


在 C++ 中,本地 char 字符串必须通过 SAL 转换函数(通常为 rtl::OUString 类中的 createFromAscii() 函数)转换为 UNO Unicode 字符串:

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

在 Basic 中,Basic 字符串以透明方式映射到 UNO 字符串。


枚举类型和常数组

OpenOffice.org API 使用多个枚举类型(称为枚举)和常数组。枚举用于列出特定上下文中每个可能值。常数组用于定义属性、参数、返回值和结构成员的可能值。


例如,枚举 com.sun.star.table.CellVertJustify 说明表格单元格内容垂直调整的可能值。表格单元格的垂直调整由它们的属性 com.sun.star.table.CellProperties:VertJustify 确定。根据 CellVertJustify,此属性的可能值是 STANDARDTOPCENTERBOTTOM


  // 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 可以识别枚举类型和常数组。它们的用法非常简单:

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


在 C++ 中,枚举和常数组与范围运算符 :: 一起使用

  //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