Hitachi

VisiBroker Version 5 Borland(R) Enterprise Server VisiBroker(R) プログラマーズリファレンス


20.3 定数

interfaceの外で定義されたIDL定数がインクルードファイルでC++定数宣言にダイレクトにマッピングされます。コードサンプル20-4〜20-5に例を示します。

コードサンプル20-4 IDLのトップレベル定義
const string str_example = "this is an example";
const long long_example = 100;
const boolean bool_example = TRUE;
コードサンプル20-5 定数のC++コード
const char * str_example = "this is an example";
const CORBA::Long long_example = 100;
const CORBA::Boolean bool_example = 1;

interfaceの中で定義された定数がインクルードファイルで宣言され,またソースファイルに値が代入されます。コードサンプル20-6〜20-8に例を示します。

コードサンプル20-6 example.idlファイルのIDL定義
interface example {
    const string str_example = "this is an example";
    const long long_example = 100;
    const boolean bool_example = TRUE;
};
コードサンプル20-7 example_client.hhインクルードファイルに生成されたC++コード
class example :: public virtual CORBA::Object
{
   ...
   static const char *str_example; /* "this is an example" */
   static const CORBA::Long long_example; /* 100 */
   static const CORBA::Boolean bool_example; /* 1 */
   ...
};
コードサンプル20-8 example_client.ccソースファイルに生成されたC++コード
const char *example::str_example = "this is an example";
const CORBA::Long example::long_example = 100;
const CORBA::Boolean example::bool_example = 1;
〈この節の構成〉