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
|
|
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 update an RTableSettings structure. They are provided for convenience. The RTableSettings structure can be modified directly. Some extra argument checking is done.
|
•
|
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.
>
|
|
>
|
|
>
|
|
>
|
|
| (1) |
>
|
|
| (2) |
>
|
|
>
|
|
>
|
|
| (3) |
>
|
|
| (4) |
>
|
|
| (5) |
>
|
|
| (6) |
>
|
|
| (7) |
>
|
|
| (8) |
>
|
|
>
|
|
| (9) |
>
|
|
| (10) |
>
|
|
| (11) |
>
|
|
| (12) |
>
|
|
| (13) |
>
|
|
| (14) |
>
|
|
| (15) |
>
|
|
| (16) |
>
|
|
| (17) |
|
|