(1)IDLマッピング
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 ) // 例外情報(2)クライアントアプリケーションで扱うパラメタ
クライアントアプリケーションのパラメタの扱いについて以下に示します。
パラメタ | サーバへ渡すパラメタ | サーバから渡されたパラメタ |
|---|---|---|
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パラメタ(3)サーバアプリケーションで扱うパラメタ
サーバアプリケーションのパラメタの扱いについて、以下に示します。
パラメタ | クライアントから渡されたパラメタ | クライアントへ渡すパラメタ |
|---|---|---|
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 );
}(4)文字列の設定方法
ワイド文字列型への文字列の設定方法を以下に示します。変数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; // 終端子
注意
ワイド文字列型をコンソールなどに出力する場合、出力処理は各OSに依存するため、そのままでは正しい文字が出力できないことがあります。出力の方法については、各OSのマニュアルを参照してください。
![]()
L"..."の形式の文字列を処理することはできません。