IDL类型

IDL 类型

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

表 1-1. 基本 CORBA 类型

类型意义
short16 bit signed integer
unsigned short16 bit unsigned integer
long32 bit signed integer
unsigned long32 bit unsigned integer
long long64 bit signed integer
unsigned long long64 bit unsigned integer
float32 bit IEEE float
double64 bit IEEE float
long double128 bit float
booleanboolean value: TRUE or FALSE
octet8 bit byte
char8 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;
            };
            };
            

转载于:https://www.cnblogs.com/kaikaile/archive/2008/09/23/1296757.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值