ページの先頭行へ戻る
Interstage Application Server アプリケーション作成ガイド(CORBAサービス編)

4.5.3 ワイド文字列型

(1)IDLマッピング

  IDL言語でワイド文字列型wstringを指定した場合、C++言語ではCORBA::WChar *でデータを宣言します。
  以降では、以下のIDL定義例をもとに説明します。


IDL言語
  module ODsample{
      interface  wstringtest{
          wstring op1(in wstring str1, out wstring str2, inout wstring str3); 
      }; 
  }; 
C++言語
  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

領域はスケルトンで自動的に獲得されます。

渡されたパラメタより短い文字列を返す場合:
  渡された領域に文字列を設定します。

渡されたパラメタより長い文字列を返す場合:
  渡された領域をCORBA::wstring_free()で解放し、CORBA::wstring_alloc()で新しい領域を獲得します。

渡した領域はスケルトンで自動的に解放されます。

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*型です)。

EUCまたはShiftJISを使用する場合

  文字を1文字ずつ設定します(EUCの場合)。

  wstr[0] = 0xc6fc;  //  "日"
  wstr[1] = 0xcbdc;  //  "本"
  wstr[2] = 0xb8ec;  //  "語"
  wstr[3] = 0x0000;  //  終端子
Windows(R)でUNICODEを使用する場合

  ””で囲んだ文字列にL修飾子を付けるとUNICODEになります。

  wstr = L"日本語";
UNIXでUNICODEを使用する場合

  UNICODEの値を1文字ずつ直接数値で設定します。

  wstr[0] = 0x65e5;  //  "日"
  wstr[1] = 0x672c;  //  "本"
  wstr[2] = 0x8a9e;  //  "語"
  wstr[3] = 0x0000;  //  終端子


  ワイド文字列型をコンソール等に出力する場合、出力処理は各OSに依存するため、そのままでは正しい文字が出力できない場合があります。出力の方法に関しては、各OSのマニュアルを参照してください。


  Solarisシステム、Linuxシステムでは、L"..."の形式の文字列を処理することはできません。