14.19 ワイド文字列
C++では、制限付きワイド文字列型と無制限ワイド文字列型の両方がCORBA::WChar*にマッピングされます。また、CORBAモジュールでは、WString_varおよびWString_outクラスを定義します。これらの各クラスは、同じメンバー関数に、対応する文字列として同じセマンティクスを提供します。ただし、これらのクラスがワイド文字列およびワイド文字を扱う場合は例外です。
ワイド文字列の動的な割当てまたは割当て解除は、次の関数で実行します:
// C++
namespace CORBA {
// ...
WChar *wstring_alloc(ULong len);
WChar *wstring_dup(const WChar* ws);
void wstring_free(WChar*);
};これらのメンバー関数は、ワイド文字列を処理する点を除いて、文字列型の同じ関数と同じセマンティクスを持ちます。
準拠したマッピング実装では、C++入出力ストリームでWString_varおよびWString_outを直接使用するために、オーバーロードされたoperator<<(挿入)とoperator>>(抽出)の演算子が提供されます。
これらのメンバー関数の説明は、「文字列」の対応する関数を参照してください。
次のコード・スニペットは、ワイド文字列およびワイド文字を使用するコード例を示しています。
// Get a string from the user:
cout << "String?";
char mixed[256]; // this should be big enough!
char lower[256];
char upper[256];
wchar_t wmixed[256];
cin >> mixed;
// Convert the string to a wide char string,
// because this is what the server will expect.
mbstowcs(wmixed, mixed, 256);
// Convert the string to upper case:
CORBA::WString_var v_upper = CORBA::wstring_dup(wmixed);
v_simple->to_upper(v_upper.inout());
wcstombs(upper, v_upper.in(), 256);
cout << upper << endl;
// Convert the string to lower case:
CORBA::WString_var v_lower = v_simple->to_lower(wmixed);
wcstombs(lower, v_lower.in(), 256);
cout << lower << endl;
// Everything succeeded:
return 0;親トピック: CORBA API