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

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 1: Line 1:
<maintab>[[Development Concepts|First Steps]]||[[Programming|Programming]]||[[Applications|Applications]]||[[Get Started|Get Started]]||[[Get Objects|Get Objects]]||[[Work with Objects|Work with Objects]]||[[Types|Types]]||[[Example|Example]]</maintab>
+
<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>
 
<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>
 
<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>
 
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.  
 
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.  

Revision as of 10:39, 5 April 2007

<maintab>Concepts||Programming||Applications||Get Started||Get Objects||Work with Objects||Types||Example</maintab> <subtab>Objects, Interfaces, and Services||Using Services||Example Spreadsheet||Types||Struct||Any||Sequence||Elements</subtab> 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.

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
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 [CHAPTER:ProfUNO.LangBind].

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 [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); [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);
Personal tools