Loading...
Searching...
No Matches
attrib.cc
Go to the documentation of this file.
/****************************************
* Computer Algebra System SINGULAR *
****************************************/
/*
* ABSTRACT: attributes to leftv and idhdl
*/
#include "kernel/mod2.h"
#include "misc/options.h"
#include "misc/intvec.h"
#include "polys/matpol.h"
#include "kernel/polys.h"
#include "kernel/ideals.h"
#include "Singular/tok.h"
#include "Singular/ipid.h"
#include "Singular/ipshell.h"
#include "Singular/attrib.h"
STATIC_VAR omBin sattr_bin = omGetSpecBin(sizeof(sattr));
void sattr::Print()
{
omCheckAddrSize(this,sizeof(sattr));
::Print("attr:%s, type %s \n",name,Tok2Cmdname(atyp));
if (next!=NULL) next->Print();
}
attr sattr::Copy()
{
assume (this!=NULL);
omCheckAddrSize(this,sizeof(sattr));
attr n=(attr)omAlloc0Bin(sattr_bin);
n->atyp=atyp;
if (name!=NULL) n->name=omStrDup(name);
n->data=CopyA();
if (next!=NULL)
{
n->next=next->Copy();
}
return n;
}
// in subexr.cc:
//void * sattr::CopyA()
//{
// omCheckAddrSize(this,sizeof(sattr));
// return s_internalCopy(atyp,data);
//}
static void attr_free(attr h, const ring r=currRing)
{
if (h->name!=NULL)
{
omFree(h->name);
h->name=NULL;
}
if (h->data!=NULL) /*avoid assume failure */
{
s_internalDelete(h->atyp,h->data,r);
h->data=NULL;
}
}
attr sattr::set(char * s, void * d, int t)
{
attr h = get(s);
attr result=this;
if (h!=NULL)
{
attr_free(h);
}
else
{
h = (attr)omAlloc0Bin(sattr_bin);
h->next = this;
result=h;
}
h->name = s;
h->data = d;
h->atyp = t;
#ifdef TEST
//::Print("set attr >>%s<< of type %s\n",h->name, Tok2Cmdname(t));
#endif
return result;
}
attr sattr::get(const char * s)
{
attr h = this;
while (h!=NULL)
{
if (0 == strcmp(s,h->name))
{
#ifdef TEST
//::Print("get attr >>%s<< of type %s\n",h->name, Tok2Cmdname(h->atyp));
#endif
return h;
}
h = h->next;
}
return NULL;
}
#if 0
void * atGet(idhdl root,const char * name)
{
attr temp = root->attribute->get(name);
if (temp!=NULL)
return temp->data;
else
return NULL;
}
void * atGet(leftv root,const char * name)
{
attr temp;
attr a=*(root->Attribute());
temp = a->get(name);
if (temp!=NULL)
return temp->data;
else
return NULL;
}
#endif
void * atGet(idhdl root,const char * name, int t, void *defaultReturnValue)
{
attr temp = root->attribute->get(name);
if ((temp!=NULL) && (temp->atyp==t))
return temp->data;
else
return defaultReturnValue;
}
void * atGet(leftv root,const char * name, int t)
{
attr *a=(root->Attribute());
if (a!=NULL)
{
attr temp = (*a)->get(name);
if ((temp!=NULL) && (temp->atyp==t))
return temp->data;
}
return NULL;
}
void atSet(idhdl root, char * name,void * data,int typ)
{
if (root!=NULL)
{
if ((IDTYP(root)!=RING_CMD)
&& (!RingDependend(IDTYP(root)))&&(RingDependend(typ)))
WerrorS("cannot set ring-dependend objects at this type");
else
root->attribute=root->attribute->set(name,data,typ);
}
}
void atSet(leftv root, char * name,void * data,int typ)
{
if (root!=NULL)
{
attr *a=root->Attribute();
int rt=root->Typ();
if (a==NULL)
WerrorS("cannot set attributes of this object");
else if ((rt!=RING_CMD)
&& (!RingDependend(rt))&&(RingDependend(typ)))
WerrorS("cannot set ring-dependend objects at this type");
else
{
*a=(*a)->set(name,data,typ);
}
}
}
void sattr::kill(const ring r)
{
attr_free(this,r);
omFreeBin((ADDRESS)this, sattr_bin);
}
void sattr::killAll(const ring r)
{
attr temp = this,temp1;
while (temp!=NULL)
{
temp1 = temp->next;
omCheckAddr(temp);
temp->kill(r);
temp = temp1;
}
}
void at_Kill(idhdl root,const char * name, const ring r)
{
attr temp = root->attribute->get(name);
if (temp!=NULL)
{
attr N = temp->next;
attr temp1 = root->attribute;
if (temp1==temp)
{
root->attribute = N;
}
else
{
while (temp1->next!=temp) temp1 = temp1->next;
temp1->next = N;
}
temp->kill(r);
}
}
void at_KillAll(idhdl root, const ring r)
{
root->attribute->killAll(r);
root->attribute = NULL;
}
void at_KillAll(leftv root, const ring r)
{
root->attribute->killAll(r);
root->attribute = NULL;
}
BOOLEAN atATTRIB1(leftv res,leftv v)
{
attr *aa=(v->Attribute());
if (aa==NULL)
{
WerrorS("this object cannot have attributes");
return TRUE;
}
attr a=*aa;
BOOLEAN haveNoAttribute=TRUE;
if (v->e==NULL)
{
if (hasFlag(v,FLAG_STD))
{
PrintS("attr:isSB, type int\n");
haveNoAttribute=FALSE;
}
if (hasFlag(v,FLAG_QRING))
{
PrintS("attr:qringNF, type int\n");
haveNoAttribute=FALSE;
}
if (v->Typ()==RING_CMD)
{
PrintS("attr:cf_class, type int\n");
PrintS("attr:cf_class_Zp, type int\n");
PrintS("attr:cf_class_QQ, type int\n");
PrintS("attr:global, type int\n");
PrintS("attr:maxExp, type int\n");
PrintS("attr:ring_cf, type int\n");
#ifdef HAVE_SHIFTBBA
PrintS("attr:isLetterplaceRing, type int\n");
if (rIsLPRing((ring)v->Data()))
PrintS("attr:ncgenCount, type int\n");
#endif
haveNoAttribute=FALSE;
}
}
else
{
leftv at=v->LData();
return atATTRIB1(res,at);
}
if (a!=NULL) a->Print();
else if(haveNoAttribute) PrintS("no attributes\n");
return FALSE;
}
BOOLEAN atATTRIB2(leftv res,leftv v,leftv b)
{
char *name=(char *)b->Data();
int t=v->Typ();
leftv at=NULL;
if (v->e!=NULL)
at=v->LData();
if (strcmp(name,"isSB")==0)
{
res->rtyp=INT_CMD;
res->data=(void *)(long)hasFlag(v,FLAG_STD);
if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_STD)||(hasFlag(at,FLAG_STD)));
}
else if ((strcmp(name,"rank")==0)&&(/*v->Typ()*/t==MODUL_CMD))
{
res->rtyp=INT_CMD;
res->data=(void *)(((ideal)v->Data())->rank);
}
else if ((strcmp(name,"global")==0)
&&(/*v->Typ()*/t==RING_CMD))
{
res->rtyp=INT_CMD;
res->data=(void *)(((ring)v->Data())->OrdSgn==1);
}
else if ((strcmp(name,"maxExp")==0)
&&(/*v->Typ()*/t==RING_CMD))
{
res->rtyp=INT_CMD;
res->data=(void *)(long)(((ring)v->Data())->bitmask);
}
else if ((strcmp(name,"ring_cf")==0)
&&(/*v->Typ()*/t==RING_CMD))
{
res->rtyp=INT_CMD;
res->data=(void *)(long)(rField_is_Ring((ring)v->Data()));
}
else if ((strncmp(name,"cf_class",strlen("cf_class"))==0)
&&(/*v->Typ()*/t==RING_CMD))
{
res->rtyp=INT_CMD;
coeffs cf;
cf=((ring)v->Data())->cf;
if (strcmp(name,"cf_class_Zp")==0)
res->data=(void *)(long)(int)(cf->type==n_Zp);
else if (strcmp(name,"cf_class_QQ")==0)
res->data=(void *)(long)(int)(cf->type==n_Q);
else
res->data=(void *)(long)(int)cf->type;
}
else if (strcmp(name,"qringNF")==0)
{
res->rtyp=INT_CMD;
res->data=(void *)(long)hasFlag(v,FLAG_QRING);
if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_QRING)||(hasFlag(at,FLAG_QRING)));
}
#ifdef HAVE_SHIFTBBA
else if ((strcmp(name,"isLetterplaceRing")==0)
&&(/*v->Typ()*/t==RING_CMD))
{
res->rtyp=INT_CMD;
res->data=(void *)(long)(((ring)v->Data())->isLPring);
}
else if ((strcmp(name,"ncgenCount")==0)
&&(/*v->Typ()*/t==RING_CMD))
{
res->rtyp=INT_CMD;
res->data=(void *)(long)(((ring)v->Data())->LPncGenCount);
}
#endif
else
{
attr *aa=v->Attribute();
if (aa==NULL)
{
WerrorS("this object cannot have attributes");
return TRUE;
}
attr a=*aa;
a=a->get(name);
if (a!=NULL)
{
res->rtyp=a->atyp;
res->data=a->CopyA();
}
else
{
res->rtyp=STRING_CMD;
res->data=omStrDup("");
}
}
return FALSE;
}
BOOLEAN atATTRIB3(leftv /*res*/,leftv v,leftv b,leftv c)
{
idhdl h=(idhdl)v->data;
if (v->e!=NULL)
{
v=v->LData();
if (v==NULL) return TRUE;
h=NULL;
}
else if (v->rtyp!=IDHDL) h=NULL;
int t=v->Typ();
char *name=(char *)b->Data();
if (strcmp(name,"isSB")==0)
{
if (c->Typ()!=INT_CMD)
{
WerrorS("attribute isSB must be int");
return TRUE;
}
if (((long)c->Data())!=0L)
{
if (h!=NULL) setFlag(h,FLAG_STD);
setFlag(v,FLAG_STD);
}
else
{
if (h!=NULL) resetFlag(h,FLAG_STD);
resetFlag(v,FLAG_STD);
}
}
else if (strcmp(name,"qringNF")==0)
{
if (c->Typ()!=INT_CMD)
{
WerrorS("attribute qringNF must be int");
return TRUE;
}
if (((long)c->Data())!=0L)
{
if (h!=NULL) setFlag(h,FLAG_QRING);
setFlag(v,FLAG_QRING);
}
else
{
if (h!=NULL) resetFlag(h,FLAG_QRING);
resetFlag(v,FLAG_QRING);
}
}
else if ((strcmp(name,"rank")==0)&&(/*v->Typ()*/t==MODUL_CMD))
{
if (c->Typ()!=INT_CMD)
{
WerrorS("attribute `rank` must be int");
return TRUE;
}
ideal I=(ideal)v->Data();
int rk=id_RankFreeModule(I,currRing);
I->rank=si_max(rk,(int)((long)c->Data()));
}
else if (((strcmp(name,"global")==0)
|| (strncmp(name,"cf_class",strlen("cf_class"))==0)
|| (strcmp(name,"ring_cf")==0)
|| (strcmp(name,"maxExp")==0))
&&(/*v->Typ()*/t==RING_CMD))
{
Werror("can not set attribute `%s`",name);
return TRUE;
}
#ifdef HAVE_SHIFTBBA
else if ((strcmp(name,"isLetterplaceRing")==0)
&&(/*v->Typ()*/t==RING_CMD))
{
if (c->Typ()==INT_CMD)
((ring)v->Data())->isLPring=(int)(long)c->Data();
else
{
WerrorS("attribute `isLetterplaceRing` must be int");
return TRUE;
}
}
else if ((strcmp(name,"ncgenCount")==0)
&&(/*v->Typ()*/t==RING_CMD))
{
if (c->Typ()==INT_CMD)
((ring)v->Data())->LPncGenCount=(int)(long)c->Data();
else
{
WerrorS("attribute `ncgenCount` must be int");
return TRUE;
}
}
#endif
else
{
int typ=c->Typ();
if (h!=NULL) atSet(h,omStrDup(name),c->CopyD(typ),typ/*c->T(yp()*/);
else atSet(v,omStrDup(name),c->CopyD(typ),typ/*c->T(yp()*/);
}
return FALSE;
}
BOOLEAN atKILLATTR1(leftv /*res*/,leftv a)
{
idhdl h=NULL;
if ((a->rtyp==IDHDL)&&(a->e==NULL))
{
h=(idhdl)a->data;
resetFlag((idhdl)a->data,FLAG_STD);
}
resetFlag(a,FLAG_STD);
if (h->attribute!=NULL)
{
atKillAll(h);
a->attribute=NULL;
}
else atKillAll(a);
return FALSE;
}
BOOLEAN atKILLATTR2(leftv /*res*/,leftv a,leftv b)
{
if ((a->rtyp!=IDHDL)||(a->e!=NULL))
{
WerrorS("object must have a name");
return TRUE;
}
char *name=(char *)b->Data();
if (strcmp(name,"isSB")==0)
{
resetFlag(a,FLAG_STD);
resetFlag((idhdl)a->data,FLAG_STD);
}
else if (strcmp(name,"global")==0)
{
WerrorS("can not set attribut `global`");
return TRUE;
}
else
{
atKill((idhdl)a->data,name);
}
return FALSE;
}
atATTRIB3
BOOLEAN atATTRIB3(leftv, leftv v, leftv b, leftv c)
Definition attrib.cc:374
sattr_bin
STATIC_VAR omBin sattr_bin
Definition attrib.cc:24
atKILLATTR2
BOOLEAN atKILLATTR2(leftv, leftv a, leftv b)
Definition attrib.cc:493
atKILLATTR1
BOOLEAN atKILLATTR1(leftv, leftv a)
Definition attrib.cc:476
at_KillAll
void at_KillAll(idhdl root, const ring r)
Definition attrib.cc:222
at_Kill
void at_Kill(idhdl root, const char *name, const ring r)
Definition attrib.cc:202
atSet
void atSet(idhdl root, char *name, void *data, int typ)
Definition attrib.cc:153
attr_free
static void attr_free(attr h, const ring r=currRing)
Definition attrib.cc:56
atATTRIB2
BOOLEAN atATTRIB2(leftv res, leftv v, leftv b)
Definition attrib.cc:282
atGet
void * atGet(idhdl root, const char *name, int t, void *defaultReturnValue)
Definition attrib.cc:132
atATTRIB1
BOOLEAN atATTRIB1(leftv res, leftv v)
Definition attrib.cc:234
attrib.h
attr
sattr * attr
Definition attrib.h:16
atKillAll
#define atKillAll(H)
Definition attrib.h:47
atKill
#define atKill(H, A)
Definition attrib.h:49
si_max
static int si_max(const int a, const int b)
Definition auxiliary.h:125
BOOLEAN
int BOOLEAN
Definition auxiliary.h:88
TRUE
#define TRUE
Definition auxiliary.h:101
FALSE
#define FALSE
Definition auxiliary.h:97
ADDRESS
void * ADDRESS
Definition auxiliary.h:120
N
const CanonicalForm CFMap CFMap & N
Definition cfEzgcd.cc:56
cf
CanonicalForm cf
Definition cfModGcd.cc:4091
b
CanonicalForm b
Definition cfModGcd.cc:4111
idrec::attribute
attr attribute
Definition idrec.h:41
sattr
Definition attrib.h:21
sattr::data
void * data
Definition attrib.h:25
sattr::Copy
attr Copy()
Definition attrib.cc:33
sattr::get
attr get(const char *s)
Definition attrib.cc:93
sattr::kill
void kill(const ring r)
Definition attrib.cc:183
sattr::killAll
void killAll(const ring r)
Definition attrib.cc:189
sattr::CopyA
void * CopyA()
Definition subexpr.cc:2192
sattr::set
attr set(char *s, void *data, int t)
Definition attrib.cc:70
sattr::atyp
int atyp
Definition attrib.h:27
sattr::Print
void Print()
Definition attrib.cc:26
sattr::name
char * name
Definition attrib.h:24
sattr::next
attr next
Definition attrib.h:26
sleftv::CopyD
void * CopyD(int t)
Definition subexpr.cc:714
sleftv::Typ
int Typ()
Definition subexpr.cc:1048
sleftv::rtyp
int rtyp
Definition subexpr.h:91
sleftv::Data
void * Data()
Definition subexpr.cc:1192
sleftv::data
void * data
Definition subexpr.h:88
sleftv::Attribute
attr * Attribute()
Definition subexpr.cc:1505
sleftv::e
Subexpr e
Definition subexpr.h:105
sleftv::attribute
attr attribute
Definition subexpr.h:89
n_Q
@ n_Q
rational (GMP) numbers
Definition coeffs.h:30
n_Zp
@ n_Zp
\F{p < 2^31}
Definition coeffs.h:29
result
return result
Definition facAbsBiFact.cc:76
s
const CanonicalForm int s
Definition facAbsFact.cc:51
res
CanonicalForm res
Definition facAbsFact.cc:60
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
name
char name(const Variable &v)
Definition factory.h:189
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
Tok2Cmdname
const char * Tok2Cmdname(int tok)
Definition gentable.cc:137
RingDependend
static int RingDependend(int t)
Definition gentable.cc:23
STATIC_VAR
#define STATIC_VAR
Definition globaldefs.h:7
MODUL_CMD
@ MODUL_CMD
Definition grammar.cc:288
RING_CMD
@ RING_CMD
Definition grammar.cc:282
ideals.h
intvec.h
ipid.h
resetFlag
#define resetFlag(A, F)
Definition ipid.h:114
hasFlag
#define hasFlag(A, F)
Definition ipid.h:112
setFlag
#define setFlag(A, F)
Definition ipid.h:113
FLAG_QRING
#define FLAG_QRING
Definition ipid.h:108
IDTYP
#define IDTYP(a)
Definition ipid.h:119
FLAG_STD
#define FLAG_STD
Definition ipid.h:106
ipshell.h
h
STATIC_VAR Poly * h
Definition janet.cc:971
matpol.h
mod2.h
assume
#define assume(x)
Definition mod2.h:389
coeffs
The main handler for Singular numbers which are suitable for Singular polynomials.
omStrDup
#define omStrDup(s)
Definition omAllocDecl.h:263
omCheckAddr
#define omCheckAddr(addr)
Definition omAllocDecl.h:328
omCheckAddrSize
#define omCheckAddrSize(addr, size)
Definition omAllocDecl.h:327
omAlloc0Bin
#define omAlloc0Bin(bin)
Definition omAllocDecl.h:206
omFree
#define omFree(addr)
Definition omAllocDecl.h:261
omFreeBin
#define omFreeBin(addr, bin)
Definition omAllocDecl.h:259
omGetSpecBin
#define omGetSpecBin(size)
Definition omBin.h:11
NULL
#define NULL
Definition omList.c:12
omBin
omBin_t * omBin
Definition omStructs.h:12
options.h
currRing
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
polys.h
Compatibility layer for legacy polynomial operations (over currRing).
PrintS
void PrintS(const char *s)
Definition reporter.cc:288
Werror
void Werror(const char *fmt,...)
Definition reporter.cc:189
rIsLPRing
static BOOLEAN rIsLPRing(const ring r)
Definition ring.h:417
rField_is_Ring
#define rField_is_Ring(R)
Definition ring.h:491
idhdl
idrec * idhdl
Definition ring.h:22
id_RankFreeModule
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
Definition simpleideals.cc:992
leftv
sleftv * leftv
Definition structs.h:53
s_internalDelete
void s_internalDelete(const int t, void *d, const ring r)
Definition subexpr.cc:518
tok.h
IDHDL
#define IDHDL
Definition tok.h:31
STRING_CMD
@ STRING_CMD
Definition tok.h:187
INT_CMD
@ INT_CMD
Definition tok.h:96