���κ���Ŀ��(������ֿռ���)�����ܴ��ڴ����� CORBA �������������Щ������Ҫ��Ψһ��������ôһ���������ֿռ��ͻ������ IDL ��������ģ��(module)��ģ��ָ��һ�����������ֿռ䣬������ C++ �����ֿռ�Ĺ����ԡ����ڶ����κνӿڶ�����ָ��ģ�飬������������չʾ��������
module FruitsBasket { interface Apple {}; interface Orange {}; }; |
����������� FruitsBasket ģ���ж������������� Apple �� Orange���������Ҫ������ģ��������һ���������DZ��������ȫ�Ķ������ã����磬�� VegetablesBasket ģ�������� Apple Ҫ��������FruitsBasket::Apple��
Ҳ�������´�ͬһ��ģ�������ӽӿڶ��壺����������ϸ�ĵȼ�����һ����
module FruitsBasket { interface Apple {}; }; module FruitsBasket { interface Orange {}; }; |
IDL�� C++ һ��Ҳ��Ԥ�����ָ��(directive): ֧�� #include �� #pragma (��Щ��ָ���� idl-compiler չ��)�� #include ͬ�� C/C++ �������Ƶ����塣���������������Ŀ�Ķ�����ͬһ��ģ���еIJ�ͬ�Ľӿڷָ��ڲ�ͬ���ļ��С�
/* ����һ�� C ʽ����ע�� */ // ����һ�� C++ ʽ����ע�� : ���߶���Ч // ��Щ������ apple.idl �ļ��� #include "orange.idl" module FruitsBasket interface Apple {}; }; |
// ��Щ������ orange.idl �ļ��� module FruitsBasket interface Orange {}; }; |
��Ϊ 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 ���ַ��� |
���ǵ�ʹ���Ƿdz���ֱ��: ����һЩʹ�����ַ����������͵� 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; }; }; |
������Щ����������������߶����������Ժͷ���������(����)����������
module FruitsBasket { interface Apple { // eat_me ���������� // ��һ�� boolean ������Ϊ���� void eat_me (in boolean eat_yes_or_not ); // ���� Apple �Ƿ��� boolean eaten (); // ���� Apple �Ƿ��� // �ͳ������˵��պ��� boolean who_ate ( out string who_surname, out string who_name ); }; }; |
���� in ���Σ���Щ�����dz��� C++ ����: ������ in, out, inout ��������֮һ�����Ρ����ǵ��������£�in �����ǿͻ�������͵����ݣ�out �����Ƕ�����ͻ����͵����ݣ�inout �����ȴӿͻ����͵������ٱ����ظ��ͻ���
������Щ������������ͬ������������˵��ʹ����Щ������ζ����ij��ȵ�����Ӧ��֮��ż���ִ�С����Զ����첽�ķ����������Ļ����÷����ij�����Լ���ִ�ж������ڶ���Ӧ��֮ǰһֱ�������첽�����������ùؼ��� oneway(����)��
module FruitsBasket { interface Apple { // eat_me ���������� // ��һ�� boolean ������Ϊ���� void eat_me (in boolean eat_yes_or_not ); // ���� Apple �Ƿ��� // �첽���� oneway boolean eaten (); // ���� Apple �Ƿ��� // �ͳ������˵��պ��� boolean who_ate ( out string who_surname, out string who_name ); }; }; |
Ҳ���Զ�������(exception)(������ C++ ��������)��
module FruitBasket { exception no_more_fruits { string reason; }; interface Apple { // ������ϣ���ĸ��ֵķ��� }; }; |
���գ�����������������������������(throwing)����ķ�����
module FruitsBasket { exception no_more_fruits { string reason; }; interface Apple { void eat_me (in boolean eat_yes_or_not ) raises ( no_more_fruits ); // ������ϣ�����������ķ��� }; }; |
�� C++ ����(�� Java �Ľӿ�)���ӿڿ��Դ������Ľӿڼ̳У�����֧�ֶ�̳�(multiple inheritance)��������� C++ �����һ����Ҫ�IJ�ͬ�� IDL ��֧�����ػ�ͬ�ķ�����������ͬ�����ֺͲ�ͬ�IJ���˵��(signature)��
module FruitsBasket { exception no_more_fruits { string reason; }; interface generic_fruit { void eat_me (in boolean eat_yes_or_not ) raises (no_more_fruits); oneway boolean eaten (); }; interface generic_fruit_one { boolean who_ate ( out string who_surname, out string who_name ); }; interface Apple : generic_fruit, generic_fruit_one { // �������ض��� Apple �ķ��� }; }; |
����չʾ�˸��� IDL ���ͣ�һЩ�����µĽӿں����ԡ�����������������ķ�ʽ������Ȥ�Ķ��߿��Դ� CORBA ���ж���Ȩ���� IDL ���岢�ҿ���һЩ����������� any��TypeCode��union������Щ���Ͷ��ڱ��IJ��Ǻ���Ҫ�ġ�