IDL 类型

因为 IDL 的主要目的是实现在不同的语言、机器和操作系统之间的可移植性,他是强类型的。这里是最基本(标准)的 CORBA 类型:

表 1-1. 基本 CORBA 类型

类型 意义
short 16 bit signed integer
unsigned short 16 bit unsigned integer
long 32 bit signed integer
unsigned long 32 bit unsigned integer
long long 64 bit signed integer
unsigned long long 64 bit unsigned integer
float 32 bit IEEE float
double 64 bit IEEE float
long double 128 bit float
boolean boolean value: TRUE or FALSE
octet 8 bit byte
char 8 bit character (ISO latin-1)
wchar 国际字符格式. FixMe: 谁知道这个格式?
string 基于 char 的字符串
wstring 基于 wchar 的字符串

它们的使用是非常率直的: 这有一些使用了字符串和浮点类型的 IDL 接口声明:

module FruitsBasket {
            interface Apple {
            attribute string color;
            };
            interface Orange {
            attribute float size;
            };
            };

每个对象得到一个浮点类型或字符串类型的属性。

有赖于const 修饰(就象在 C++ 中) IDL 允许你定义常量。这里有一些样例 IDL 代码:

module FruitsBasket {
            interface Apple {
            attribute string color;
            const float weight = 2.3;
            const string type = "sample type";
            };
            interface Orange {
            attribute float size;
            };
            };
            

使用 typedef 关键字就可以定义你自己的类型(还是很象在 C 和 C++ 中)。又是一个样例代码,这里定义了一个有自定义的类型属性的 Apple 对象,自定义的类型是一个字符串。

module FruitsBasket {
            typedef string fruit_type;
            interface Apple {
            attribute fruit_type type;
            };
            interface Orange {
            };
            };
            

我们也有标准的 C/C++ 结构,枚举和阵列。结构,枚举和定长(fixed size)阵列象 typedef 一样简直就是 C 代码:

module calendar {
            enum a_month {
            january, february, march, april, may, june,
            july, august, september, october, december
            };
            enum a_day {
            monday, tuesday, wednesday, thursday,
            friday, saturday, sunday
            };
            typedef long a_year;
            struct a_date {
            a_day    the_day;
            a_month  the_month;
            a_year   the_year;
            };
            interface calendar {
            attribute a_date the_date;
            // 一维阵列
            typedef a_date a_date_array[20];
            attribute a_date_array the_date_array;
            // 二维阵列
            typedef a_date_array a_date_array_multi[20];
            attribute a_date_array_multi the_date_array_multi;
            };
            };
            

变长(Variable-size)阵列在 CORBA 中叫序列(sequence):

module calendar {
            interface calendar {
            /* 定义了一个一维 long 阵列(数组)
            * 最大长度是 20.
            */
            typedef sequence <long,20> array_1;
            // 一个无边界的(unbounded)的一维字符串阵列
            typedef sequence <string> array_2;
            // 更复杂的: 一个序列的序列
            // 用于模拟多维变长阵列
            typedef sequence <sequence <long,20> > array_3;
            };
            };
            
posted on 2008-09-23 12:46  凯歌  阅读(625)  评论(0编辑  收藏  举报