MLNewUnicodeContainer (C 関数)

MLNewUnicodeContainerWSNewUnicodeContainerに置き換えられた.

MLUnicodeContainer * MLNewUnicodeContainer(void *s, int l, enum MLUnicodeContainerType t)

長さ l のUnicodeの文字列 s の内容のコピー,タイプ t の文字列を含む新しいUnicodeのコンテナを割り当てて返す.

詳細

  • MLNewUnicodeContainer()は,解放されなければならないUnicodeの文字列 s を保存するためのメモリを割り当てる.そのメモリを解放するためには,MLNewUnicodeContainer()によって返されるMLUnicodeContainer *オブジェクトについてMLReleaseUnicodeContainer()を呼び出すとよい.
  • MLNewUnicodeContainer()は,エラーがあった場合にはNULLを返す.
  • MathLink テンプレートファイルで使えるようにMLUnicodeContainerオブジェクトを割り当てる場合に,MLNewUnicodeContainer()を使う.
  • MLNewUnicodeContainer()は, MathLink テンプレートファイルでMLUnicodeContainerオブジェクトを作成したり破壊したりするために,MLReleaseUnicodeContainer()と一緒に使われる.MLUnicodeContainerは,テンプレートファイル内の関数間でUnicodeの文字列とその長さを渡すのに便利なオブジェクトである.
  • MLNewUnicodeContainer()は,MathLinkヘッダファイルmathlink.hで宣言される.

例題

  (1)

#include "mathlink.h"

/* A MathLink template program for converting a string to a symbol */

:Begin:
:Function: convertStringToSymbol
:Pattern: ConvertStringToSymbol[string_String]
:Arguments: {string}
:ArgumentTypes: {String}
:ReturnType: UTF8Symbol
:End:

MLUnicodeContainer * convertStringToSymbol(const char *s)
{
    MLUnicodeContainer *newContainer;
    MLINK link;
    int error;

    unsigned char *utf8String;
    int utf8Length, utf8Chars;

    /* Use a loopback link to convert the string from Mathematica
    form to a UTF-8 encoded version */

    link = MLLoopbackOpen(stdenv, &error);
    if(link == NULL || error != MLEOK)
    { /* Unable to create loopback link */ }

    if(! MLPutString(link, s))
    { /* Unable to send the string to the loopback link */ }

    if(! MLFlush(link))
    [ /* Unable to flush the link buffers */ }

    if(! MLGetUTF8String(link, &utf8String, &utf8Length, &utf8Chars))
    { /* Unable to read the UTF-8 encoded string */ }

    /* The MLUnicodeContainer object is just for passing around
    Unicode strings and their lengths in an easy manner. The
    MathLink template code will call MLReleaseUnicodeContainer()
    for the memory allocated by MLNewUnicodeContainer() */

    /* UTF8ContainerType is the enum value that indicates the
    MLUnicodeContainer object contains an UTF-8 encoded string */

    newContainer = MLNewUnicodeContainer(utf8String, utf8Length,
        UTF8ContainerType);

    MLReleaseUTF8String(link, utf8String, utf8Length);

    return newContainer;
}


int main(int argc, char **argv)
{
    return MLMain(argc, argv);
}