Interstage Application Server アプリケーション作成ガイド (CORBAサービス編) |
目次
索引
![]() ![]() |
第5章 アプリケーションの開発(C++言語) | > 5.5 データ型に対するマッピング |
IDL言語でワイド文字列型wstringを指定した場合、C++言語ではCORBA::WChar *でデータを宣言します。
以降では、以下のIDL定義例をもとに説明します。
module ODsample{ interface wstringtest{ wstring op1(in wstring str1, out wstring str2, inout wstring str3); }; };
CORBA::WChar * ODsample::wstringtest::op1( const CORBA::WChar *str1, // inパラメタ CORBA::WChar *&str2, // outパラメタ CORBA::WChar *&str3, // inoutパラメタ CORBA::Environment &env ) // 例外情報
クライアントアプリケーションのパラメタの扱いについて、以下に示します。
パラメタ |
サーバへ渡すパラメタ |
サーバから渡されたパラメタ |
in |
CORBA::wstring_alloc()で領域を獲得します。 |
− |
inout |
(inパラメタと同じ) |
領域はスタブで自動的に獲得されます。 |
out |
− |
(inoutパラメタと同じ) |
クライアントおよびスタブで獲得した領域は、不要になった時点でCORBA::wstring_free()で解放する必要があります。
以下にクライアントアプリケーションでの処理例を示します。
CORBA::Environment env; CORBA::WChar *str1, *str2, *str3, *ret; // inパラメタ str1 = CORBA::wstring_alloc(2); // 領域獲得 str1[0] = ...; // パラメタ設定:(4)参照 : // inoutパラメタ str3 = CORBA_wstring_alloc(5); // 領域獲得 str3[0] = ...; // パラメタ設定:(4)参照 : // サーバ呼出し ret = obj->op1( str1, str2, str3, env ); // 領域解放 CORBA::wstring_free( ret ); // 復帰パラメタ CORBA::wstring_free( str1 ); // inパラメタ CORBA::wstring_free( str2 ); // outパラメタ CORBA::wstring_free( str3 ); // inoutパラメタ
サーバアプリケーションのパラメタの扱いについて、以下に示します。
パラメタ |
クライアントから渡されたパラメタ |
クライアントへ渡すパラメタ |
in |
領域はスケルトンで自動的に獲得/解放されます。 |
− |
inout |
領域はスケルトンで自動的に獲得されます。 |
渡されたパラメタより短い文字列を返す場合: 渡されたパラメタより長い文字列を返す場合: 渡した領域はスケルトンで自動的に解放されます。 |
out |
− |
CORBA::wstring_alloc()で獲得します。 |
以下にサーバアプリケーションでの処理例を示します。
CORBA::WChar * ODsample_wstringtest_impl::op1( const CORBA::WChar *str1, // inパラメタ CORBA::WChar *&str2, // outパラメタ CORBA::WChar *&str3, // inoutパラメタ CORBA::Environment &env ) // 例外情報 throws( CORBA::Exception ) { // outパラメタ str2 = CORBA::wstring_alloc(3); // 領域獲得 str2[0] = ...; // パラメタ設定:(4)参照 : // inoutパラメタ
CORBA::wstring_free( str3 ); // 領域解放 str3 = CORBA::wstring_alloc(5); // 領域再獲得 str3[0] = ...; // パラメタ設定:(4)参照 : // 復帰パラメタ str = CORBA::wstring_alloc(4); // 領域獲得 str[0] = ...; // パラメタ設定:(4)参照 : return( str ); }
ワイド文字列型への文字列の設定方法を以下に示します(変数wstrは、CORBA::WChar*型です)。
文字を1文字ずつ設定します(EUCの場合)。
wstr[0] = 0xc6fc; // "日" wstr[1] = 0xcbdc; // "本" wstr[2] = 0xb8ec; // "語" wstr[3] = 0x0000; // 終端子
""で囲んだ文字列にL修飾子を付けるとUNICODEになります。
wstr = L"日本語";
UNICODEの値を1文字ずつ直接数値で設定します。
wstr[0] = 0x65e5; // "日" wstr[1] = 0x672c; // "本" wstr[2] = 0x8a9e; // "語" wstr[3] = 0x0000; // 終端子
Solaris OEシステム、Linuxシステムでは、L"..."の形式の文字列を処理することはできません。
目次
索引
![]() ![]() |