Difference between revisions of "Documentation/DevGuide/ProUNO/Predefined Values"
m (1 revision(s)) |
|||
(6 intermediate revisions by 4 users not shown) | |||
Line 5: | Line 5: | ||
|NextPage=Documentation/DevGuide/ProUNO/Sequences | |NextPage=Documentation/DevGuide/ProUNO/Sequences | ||
}} | }} | ||
+ | {{Documentation/DevGuideLanguages|Documentation/DevGuide/ProUNO/{{SUBPAGENAME}}}} | ||
{{DISPLAYTITLE:Predefined Values}} | {{DISPLAYTITLE:Predefined Values}} | ||
The API offers many predefined values, that are used as method parameters, or returned by methods. In UNO IDL there are two different data types for predefined values: constants and enumerations. | The API offers many predefined values, that are used as method parameters, or returned by methods. In UNO IDL there are two different data types for predefined values: constants and enumerations. | ||
Line 13: | Line 14: | ||
Since a wide selection of types and values is possible in a const, const is occasionally used to build bit vectors which encode combined values. | Since a wide selection of types and values is possible in a const, const is occasionally used to build bit vectors which encode combined values. | ||
− | + | <syntaxhighlight lang="idl"> | |
const short ID = 23; | const short ID = 23; | ||
const boolean ERROR = true; | const boolean ERROR = true; | ||
const double PI = 3.1415; | const double PI = 3.1415; | ||
− | + | </syntaxhighlight> | |
Usually const definitions are part of a constants group. | Usually const definitions are part of a constants group. | ||
Line 23: | Line 24: | ||
The constants type defines a named group of const values. A const in a constants group is denoted by the group name and the const name. In the UNO IDL example below, <code>ImageAlign.RIGHT</code> refers to the value 2: | The constants type defines a named group of const values. A const in a constants group is denoted by the group name and the const name. In the UNO IDL example below, <code>ImageAlign.RIGHT</code> refers to the value 2: | ||
− | + | <syntaxhighlight lang="idl"> | |
constants ImageAlign { | constants ImageAlign { | ||
const short LEFT = 0; | const short LEFT = 0; | ||
Line 30: | Line 31: | ||
const short BOTTOM = 3; | const short BOTTOM = 3; | ||
}; | }; | ||
− | + | </syntaxhighlight> | |
===enum=== | ===enum=== | ||
An <code>enum</code> type is equivalent to an enumeration type in C++. It contains an ordered list of one or more identifiers representing long values of the enum type. By default, the values are numbered sequentially, beginning with 0 and adding 1 for each new value. If an enum value has been assigned a value, all following enum values without a predefined value get a value starting from this assigned value. | An <code>enum</code> type is equivalent to an enumeration type in C++. It contains an ordered list of one or more identifiers representing long values of the enum type. By default, the values are numbered sequentially, beginning with 0 and adding 1 for each new value. If an enum value has been assigned a value, all following enum values without a predefined value get a value starting from this assigned value. | ||
− | + | <syntaxhighlight lang="idl"> | |
// com.sun.star.uno.TypeClass | // com.sun.star.uno.TypeClass | ||
enum TypeClass { | enum TypeClass { | ||
Line 42: | Line 43: | ||
BYTE, | BYTE, | ||
SHORT, | SHORT, | ||
− | + | … | |
}; | }; | ||
Line 52: | Line 53: | ||
SOFT // value 31 | SOFT // value 31 | ||
}; | }; | ||
− | + | </syntaxhighlight> | |
If enums are used during debugging, you should be able to derive the numeric value of an enum by counting its position in the API reference. However, never use literal numeric values instead of enums in your programs. | If enums are used during debugging, you should be able to derive the numeric value of an enum by counting its position in the API reference. However, never use literal numeric values instead of enums in your programs. | ||
− | {{ | + | {{Warn|Once an enum type has been specified and published, you can trust that it is not extended later on, for that would break existing code. However, new const values may be added to a constant group.}} |
{{PDL1}} | {{PDL1}} | ||
− | [[Category: Professional UNO]] | + | |
+ | [[Category:Documentation/Developer's Guide/Professional UNO]] |
Latest revision as of 10:42, 23 December 2020
The API offers many predefined values, that are used as method parameters, or returned by methods. In UNO IDL there are two different data types for predefined values: constants and enumerations.
const
A const
defines a named value of a valid UNO IDL type. The value depends on the specified type and can be a literal (integer number, floating point number or a character), an identifier of another const type or an arithmetic term using the operators: +
, -
, *
, /
, ~
, &
, |
, %
, ^
, <<
, >>
.
Since a wide selection of types and values is possible in a const, const is occasionally used to build bit vectors which encode combined values.
const short ID = 23; const boolean ERROR = true; const double PI = 3.1415;
Usually const definitions are part of a constants group.
constants
The constants type defines a named group of const values. A const in a constants group is denoted by the group name and the const name. In the UNO IDL example below, ImageAlign.RIGHT
refers to the value 2:
constants ImageAlign { const short LEFT = 0; const short TOP = 1; const short RIGHT = 2; const short BOTTOM = 3; };
enum
An enum
type is equivalent to an enumeration type in C++. It contains an ordered list of one or more identifiers representing long values of the enum type. By default, the values are numbered sequentially, beginning with 0 and adding 1 for each new value. If an enum value has been assigned a value, all following enum values without a predefined value get a value starting from this assigned value.
// com.sun.star.uno.TypeClass enum TypeClass { VOID, CHAR, BOOLEAN, BYTE, SHORT, … }; enum Error { SYSTEM = 10, // value 10 RUNTIME, // value 11 FATAL, // value 12 USER = 30, // value 30 SOFT // value 31 };
If enums are used during debugging, you should be able to derive the numeric value of an enum by counting its position in the API reference. However, never use literal numeric values instead of enums in your programs.
Once an enum type has been specified and published, you can trust that it is not extended later on, for that would break existing code. However, new const values may be added to a constant group. |
Content on this page is licensed under the Public Documentation License (PDL). |