MapleListAlloc - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : OpenMaple : C Application Programming Interface : List and Table Manipulation : OpenMaple/C/MapleListAlloc

MapleListAlloc

create a list in external code

MapleListAssign

assign into a list in external code

MapleListSelect

select from a list in external code

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

MapleListAlloc(kv, n)

MapleListAssign(kv, list, i, val)

MapleListSelect(kv, list, i)

Parameters

kv

-

kernel handle of type MKernelVector

n

-

number of elements in the list

list

-

Maple list object

i

-

index of entry in a list

val

-

value to assign into the list

Description

• 

These functions can be used in external code with OpenMaple or define_external.

• 

MapleListAlloc creates a new list that can contain n elements.  The list must be filled completely before passing it back to Maple.

• 

MapleListAssign sets the ith element of the given list to the value val.  Lists can be modified only if they were created by MapleListAlloc and have never entered Maple (for example, as an argument to a function evaluation or returned value).  Lists are static objects; once created, they cannot change.  For information on working with a dynamic object, see ?RTableCreate.

• 

MapleListSelect retrieves the ith element of the given list.  Indexing in a list starts at 1.

• 

The size of a list can be obtained using the MapleNumArgs command.

Examples

    #include <sys/types.h>

    #include <time.h>

    #include "maplec.h"

    ALGEB M_DECL MyTimeList( MKernelVector kv, ALGEB *args )

    {

    time_t c;

    struct tm *t;

    ALGEB list, elem, val;

    char *code;

    M_INT n, i;

    if( MapleNumArgs(kv,(ALGEB)args) != 1 ) {

        MapleRaiseError(kv,"one argument expected");

        return( NULL );

    }

    if( !IsMapleList(kv,args[1]) ) {

        MapleRaiseError(kv,"list expected");

        return( NULL );

    }

    n = MapleNumArgs(kv,args[1]);

    list = MapleListAlloc(kv,n);

    c = time(&c);

    t = localtime(&c);

    for( i=1; i<=n; ++i ) {

        elem = MapleListSelect(kv,args[1],i);

        if( !IsMapleString(kv,elem) ) {

        MapleRaiseError1(kv,"string expected for %-1 parameter",

             ToMapleInteger(kv,i));

        return( NULL );

        }

        code = MapleToString(kv,elem);

        if( strcmp(code,"SS") == 0 ) {

        val = ToMapleInteger(kv,t->tm_sec);

        }

        else if( strcmp(code,"MM") == 0 ) {

        val = ToMapleInteger(kv,t->tm_min);

        }

        else if( strcmp(code,"HH") == 0 ) {

        val = ToMapleInteger(kv,t->tm_hour);

        }

        else if( strcmp(code,"dd") == 0 ) {

        val = ToMapleInteger(kv,t->tm_mday);

        }

        else if( strcmp(code,"mm") == 0 ) {

        val = ToMapleInteger(kv,t->tm_mon);

        }

        else if( strcmp(code,"yy") == 0 ) {

        val = ToMapleInteger(kv,t->tm_year+1900);

        }

        else if( strcmp(code,"ww") == 0 ) {

        val = ToMapleInteger(kv,t->tm_wday);

        }

        else if( strcmp(code,"jj") == 0 ) {

        val = ToMapleInteger(kv,t->tm_yday);

        }

        else if( strcmp(code,"vv") == 0 ) {

        val = ToMapleInteger(kv,t->tm_isdst);

        }

        else {

        MapleRaiseError1(kv,"unrecognized format code, %1",elem);

        return( NULL );

        }

        MapleListAssign(kv,list,i,val);

    }

    return( list );

    }

Execute the external function from Maple.

withExternalCalling&colon;

dllExternalLibraryNameHelpExamples&colon;

dateDefineExternalMyTimeList&comma;dll&colon;

datemm&comma;dd&comma;yy

2&comma;17&comma;2016

(1)

dateHH&comma;MM&comma;SS

2&comma;2&comma;18

(2)

See Also

CustomWrapper

define_external

OpenMaple

OpenMaple/C/API

OpenMaple/C/Examples

StringTools[FormatTime]

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam