RTableAppendAttribute - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


RTableSetAttribute

assign to the attribute RTableSettings field in external code

RTableAppendAttribute

append to the attribute RTableSettings field in external code

RTableSetIndFn

assign to the index_functions RTableSettings field in external code

RTableAppendIndFn

append to the index_functions RTableSettings field in external code

RTableSetType

assign to the data_type and maple_type RTableSettings field in external code

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

RTableSetAttribute(kv, rts, name)

RTableAppendAttribute(kv, rts, name)

RTableSetIndFn(kv, rts, indfn)

RTableAppendIndFn(kv, rts, indfn)

RTableSetType(kv, rts, id, name)

Parameters

kv

-

kernel handle of type MKernelVector

rts

-

pointer to an RTableSettings structure

name

-

name of an attribute or type

indfn

-

type ALGEB indexing function object

id

-

data_type identifier

Description

• 

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

• 

These functions update an RTableSettings structure. They are provided for convenience. The RTableSettings structure can be modified directly. Some extra argument checking is done.

• 

RTableSetAttribute(kv,rts,name) is equivalent to rts->attributes = ToMapleExpressionSequence(kv,1,ToMapleName(kv,name,TRUE)); Attributes can be retrieved using the attributes command in Maple.

• 

RTableAppendAttribute(kv,rts,name) is equivalent to the following.

M_INT n, i;

ALGEB attrib;

n = MapleNumArgs(kv,rts->attributes);

attrib = NewMapleExpressionSequence(kv,n+1);

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

    attrib[i] = rts->attributes[i];

}

rts->attributes[n] = (ALGEB)MapleToName(kv,name,TRUE);

• 

RTableSetIndFn and RTableAppendIndFn are the same as RTableSetAttribute and RTableAppendAttribute except they work on rts->index_functions instead of rts->attributes to set the indexing function property.

• 

RTableSetType sets the data_type and maple_type fields of the RTableSettings structure.  This command is equivalent to the following code.

rts->data_type = id;

if( id == RTABLE_DAG } {

    rts->maple_type = ToMapleName(kv,name,TRUE);

}

Examples

    #include <string.h>

    #include "maplec.h"

    ALGEB M_DECL MyStack( MKernelVector kv, ALGEB *args )

    {

    M_INT argc;

    RTableSettings rts;

    ALGEB rt;

    char *method;

    M_INT size;

    argc = MapleNumArgs(kv,(ALGEB)args);

    if( argc == 0 ) {

        MapleRaiseError(kv,"method expected");

            return( NULL );

        }

    method = MapleToString(kv,args[1]);

    if( strcmp(method,"create") == 0 ) {

        M_INT bounds[2];

        if( argc != 2 ) {

        MapleRaiseError(kv,"size expected");

                return( NULL );

            }

        size = MapleToM_INT(kv,args[2]);

        RTableGetDefaults(kv,&rts);

        RTableSetAttribute(kv,&rts,"stack");

        RTableAppendAttribute(kv,&rts,"12345");

        RTableSetType(kv,&rts,RTABLE_DAG,"numeric");

        rts.num_dimensions = 1;

        bounds[0] = 1;

        bounds[1] = size+1;

        rt = RTableCreate(kv,&rts,NULL,bounds);

        return( rt );

    }

    else {

        RTableData rtd;

        M_INT index[1];

        if( argc < 2 ) {

        MapleRaiseError(kv,"stack rtable expected");

        return( NULL );

            }

        if( !IsMapleRTable(kv,args[2]) ) {

        MapleRaiseError(kv,"stack rtable expected");

        return( NULL );

            }

        rt = args[2];

        RTableGetSettings(kv,&rts,rt);

        if( MapleNumArgs(kv,rts.attributes) < 2

        || !IsMapleName(kv,(ALGEB)rts.attributes[1])

        || !IsMapleName(kv,(ALGEB)rts.attributes[2])

        || strcmp(MapleToString(kv,(ALGEB)rts.attributes[1]),"stack")

        || strcmp(MapleToString(kv,(ALGEB)rts.attributes[2]),"12345")

        || rts.num_dimensions != 1

        || rts.data_type != RTABLE_DAG

        || rts.storage != RTABLE_RECT ) {

        MapleRaiseError(kv,"invalid stack rtable");

        return( NULL );

            }

        if( strcmp(method,"push") == 0 ) {

        if( argc < 3 ) {

            MapleRaiseError(kv,"element to push expected");

            return( NULL );

                }

        index[0] = 1;

        rtd = RTableSelect(kv,rt,index);

        size = MapleToM_INT(kv,rtd.dag);

        if( size+1 == RTableUpperBound(kv,rt,1) ) {

            MapleRaiseError(kv,"stack is full");

                    return( NULL );

                }

        index[0] = size+2;

        rtd.dag = args[3];

        RTableAssign(kv,rt,index,rtd);

        size++;

        rtd.dag = ToMapleInteger(kv,size);

                index[0] = 1;

        RTableAssign(kv,rt,index,rtd);

        return( args[3] );

        }

        else if( strcmp(method,"pop") == 0 ) {

        index[0] = 1;

        rtd = RTableSelect(kv,rt,index);

        size = MapleToM_INT(kv,rtd.dag);

        if( size == 0 ) {

            MapleRaiseError(kv,"stack is empty");

                    return( NULL );

                }

        size--;

        rtd.dag = ToMapleInteger(kv,size);

        RTableAssign(kv,rt,index,rtd);

        index[0] = size+2;

        rtd = RTableSelect(kv,rt,index);

        return( rtd.dag );

        }

        else if( strcmp(method,"isempty") == 0 ) {

        index[0] = 1;

        rtd = RTableSelect(kv,rt,index);

        size = MapleToM_INT(kv,rtd.dag);

        return( ToMapleBoolean(kv,size==0) );

        }

        else {

        MapleRaiseError1(kv,"invalid method %1",args[1]);

        return( ToMapleNULL(kv) );

        }

    }

    }

Execute the external function from Maple.

withExternalCalling&colon;

dllExternalLibraryNameHelpExamples&colon;

mystackDefineExternalMyStack&comma;dll&colon;

smystackcreate&comma;5

s000000

(1)

attributess

stack,12345

(2)

mystackpush&comma;s&comma;1&comma;2&comma;3

Error, (in mystack) unable to store '[1, 2, 3]' when datatype=numeric

mystackpop&comma;s

Error, (in mystack) stack is empty

mystackisempty&comma;s

true

(3)

mystackpush&comma;s&comma;1

1

(4)

mystackpush&comma;s&comma;2

2

(5)

mystackpush&comma;s&comma;3

3

(6)

mystackpush&comma;s&comma;4

4

(7)

mystackpush&comma;s&comma;5

5

(8)

mystackpush&comma;s&comma;6

Error, (in mystack) stack is full

mystackpop&comma;s

5

(9)

mystackpush&comma;s&comma;99

99

(10)

mystackpop&comma;s

99

(11)

mystackisempty&comma;s

false

(12)

mystackpop&comma;s

4

(13)

mystackpop&comma;s

3

(14)

mystackpop&comma;s

2

(15)

mystackpop&comma;s

1

(16)

mystackisempty&comma;s

true

(17)

See Also

CustomWrapper

define_external

OpenMaple

OpenMaple/C/API

OpenMaple/C/Examples

rtable