My Project  debian-1:4.1.2-p1+ds-2
attrib.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 
5 /*
6 * ABSTRACT: attributes to leftv and idhdl
7 */
8 
9 #include "kernel/mod2.h"
10 
11 #include "misc/options.h"
12 #include "misc/intvec.h"
13 
14 #include "polys/matpol.h"
15 
16 #include "kernel/polys.h"
17 #include "kernel/ideals.h"
18 
19 #include "Singular/tok.h"
20 #include "Singular/ipid.h"
21 #include "Singular/ipshell.h"
22 #include "Singular/attrib.h"
23 
25 
27 {
28  omCheckAddrSize(this,sizeof(sattr));
29  ::Print("attr:%s, type %s \n",name,Tok2Cmdname(atyp));
30  if (next!=NULL) next->Print();
31 }
32 
34 {
35  assume (this!=NULL);
36 
37  omCheckAddrSize(this,sizeof(sattr));
39  n->atyp=atyp;
40  if (name!=NULL) n->name=omStrDup(name);
41  n->data=CopyA();
42  if (next!=NULL)
43  {
44  n->next=next->Copy();
45  }
46  return n;
47 }
48 
49 // in subexr.cc:
50 //void * sattr::CopyA()
51 //{
52 // omCheckAddrSize(this,sizeof(sattr));
53 // return s_internalCopy(atyp,data);
54 //}
55 
56 static void attr_free(attr h, const ring r=currRing)
57 {
58  if (h->data!=NULL) /*avoid assume failure */
59  {
60  s_internalDelete(h->atyp,h->data,r);
61  h->data=NULL;
62  omFree(h->name);
63  h->name=NULL;
64  }
65 }
66 
67 attr sattr::set(char * s, void * d, int t)
68 {
69  attr h = get(s);
70  attr result=this;
71  if (h!=NULL)
72  {
73  attr_free(h);
74  }
75  else
76  {
78  h->next = this;
79  result=h;
80  }
81  h->name = s;
82  h->data = d;
83  h->atyp = t;
84 #ifdef TEST
85  //::Print("set attr >>%s<< of type %s\n",h->name, Tok2Cmdname(t));
86 #endif
87  return result;
88 }
89 
90 attr sattr::get(const char * s)
91 {
92  attr h = this;
93  while (h!=NULL)
94  {
95  if (0 == strcmp(s,h->name))
96  {
97 #ifdef TEST
98  //::Print("get attr >>%s<< of type %s\n",h->name, Tok2Cmdname(h->atyp));
99 #endif
100  return h;
101  }
102  h = h->next;
103  }
104  return NULL;
105 }
106 
107 #if 0
108 void * atGet(idhdl root,const char * name)
109 {
110  attr temp = root->attribute->get(name);
111  if (temp!=NULL)
112  return temp->data;
113  else
114  return NULL;
115 }
116 
117 void * atGet(leftv root,const char * name)
118 {
119  attr temp;
120  attr a=*(root->Attribute());
121  temp = a->get(name);
122  if (temp!=NULL)
123  return temp->data;
124  else
125  return NULL;
126 }
127 #endif
128 
129 void * atGet(idhdl root,const char * name, int t, void *defaultReturnValue)
130 {
131  attr temp = root->attribute->get(name);
132  if ((temp!=NULL) && (temp->atyp==t))
133  return temp->data;
134  else
135  return defaultReturnValue;
136 }
137 
138 void * atGet(leftv root,const char * name, int t)
139 {
140  attr *a=(root->Attribute());
141  if (a!=NULL)
142  {
143  attr temp = (*a)->get(name);
144  if ((temp!=NULL) && (temp->atyp==t))
145  return temp->data;
146  }
147  return NULL;
148 }
149 
150 void atSet(idhdl root, char * name,void * data,int typ)
151 {
152  if (root!=NULL)
153  {
154  if ((IDTYP(root)!=RING_CMD)
155  && (!RingDependend(IDTYP(root)))&&(RingDependend(typ)))
156  WerrorS("cannot set ring-dependend objects at this type");
157  else
158  root->attribute=root->attribute->set(name,data,typ);
159  }
160 }
161 
162 void atSet(leftv root, char * name,void * data,int typ)
163 {
164  if (root!=NULL)
165  {
166  attr *a=root->Attribute();
167  int rt=root->Typ();
168  if (a==NULL)
169  WerrorS("cannot set attributes of this object");
170  else if ((rt!=RING_CMD)
171  && (!RingDependend(rt))&&(RingDependend(typ)))
172  WerrorS("cannot set ring-dependend objects at this type");
173  else
174  {
175  *a=(*a)->set(name,data,typ);
176  }
177  }
178 }
179 
180 void sattr::kill(const ring r)
181 {
182  attr_free(this,r);
183  omFreeBin((ADDRESS)this, sattr_bin);
184 }
185 
186 void sattr::killAll(const ring r)
187 {
188  attr temp = this,temp1;
189 
190  while (temp!=NULL)
191  {
192  temp1 = temp->next;
193  omCheckAddr(temp);
194  temp->kill(r);
195  temp = temp1;
196  }
197 }
198 
199 void at_Kill(idhdl root,const char * name, const ring r)
200 {
201  attr temp = root->attribute->get(name);
202  if (temp!=NULL)
203  {
204  attr N = temp->next;
205  attr temp1 = root->attribute;
206  if (temp1==temp)
207  {
208  root->attribute = N;
209  }
210  else
211  {
212  while (temp1->next!=temp) temp1 = temp1->next;
213  temp1->next = N;
214  }
215  temp->kill(r);
216  }
217 }
218 
219 void at_KillAll(idhdl root, const ring r)
220 {
221  root->attribute->killAll(r);
222  root->attribute = NULL;
223 }
224 
225 void at_KillAll(leftv root, const ring r)
226 {
227  root->attribute->killAll(r);
228  root->attribute = NULL;
229 }
230 
232 {
233  attr *aa=(v->Attribute());
234  if (aa==NULL)
235  {
236  WerrorS("this object cannot have attributes");
237  return TRUE;
238  }
239  attr a=*aa;
240  BOOLEAN haveNoAttribute=TRUE;
241  if (v->e==NULL)
242  {
243  if (hasFlag(v,FLAG_STD))
244  {
245  PrintS("attr:isSB, type int\n");
246  haveNoAttribute=FALSE;
247  }
248  if (hasFlag(v,FLAG_QRING))
249  {
250  PrintS("attr:qringNF, type int\n");
251  haveNoAttribute=FALSE;
252  }
253  if (v->Typ()==RING_CMD)
254  {
255  PrintS("attr:cf_class, type int\n");
256  PrintS("attr:global, type int\n");
257  PrintS("attr:maxExp, type int\n");
258  PrintS("attr:ring_cf, type int\n");
259  #ifdef HAVE_SHIFTBBA
260  PrintS("attr:isLetterplaceRing, type int\n");
261  #endif
262 
263  haveNoAttribute=FALSE;
264  }
265  }
266  else
267  {
268  leftv at=v->LData();
269  return atATTRIB1(res,at);
270  }
271  if (a!=NULL) a->Print();
272  else if(haveNoAttribute) PrintS("no attributes\n");
273  return FALSE;
274 }
276 {
277  char *name=(char *)b->Data();
278  int t=v->Typ();
279  leftv at=NULL;
280  if (v->e!=NULL)
281  at=v->LData();
282  if (strcmp(name,"isSB")==0)
283  {
284  res->rtyp=INT_CMD;
285  res->data=(void *)(long)hasFlag(v,FLAG_STD);
286  if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_STD)||(hasFlag(at,FLAG_STD)));
287  }
288  else if ((strcmp(name,"rank")==0)&&(/*v->Typ()*/t==MODUL_CMD))
289  {
290  res->rtyp=INT_CMD;
291  res->data=(void *)(((ideal)v->Data())->rank);
292  }
293  else if ((strcmp(name,"global")==0)
294  &&(/*v->Typ()*/t==RING_CMD))
295  {
296  res->rtyp=INT_CMD;
297  res->data=(void *)(((ring)v->Data())->OrdSgn==1);
298  }
299  else if ((strcmp(name,"maxExp")==0)
300  &&(/*v->Typ()*/t==RING_CMD))
301  {
302  res->rtyp=INT_CMD;
303  res->data=(void *)(long)(((ring)v->Data())->bitmask/2);
304  }
305  else if ((strcmp(name,"ring_cf")==0)
306  &&(/*v->Typ()*/t==RING_CMD))
307  {
308  res->rtyp=INT_CMD;
309  res->data=(void *)(long)(rField_is_Ring((ring)v->Data()));
310  }
311  else if ((strcmp(name,"cf_class")==0)
312  &&(/*v->Typ()*/t==RING_CMD))
313  {
314  res->rtyp=INT_CMD;
315  coeffs cf;
316  if (t==RING_CMD) cf=((ring)v->Data())->cf;
317  else cf=(coeffs)v->Data();
318  res->data=(void *)(long)(cf->type);
319  }
320  else if (strcmp(name,"qringNF")==0)
321  {
322  res->rtyp=INT_CMD;
323  res->data=(void *)(long)hasFlag(v,FLAG_QRING);
324  if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_QRING)||(hasFlag(at,FLAG_QRING)));
325  }
326 #ifdef HAVE_SHIFTBBA
327  else if ((strcmp(name,"isLetterplaceRing")==0)
328  &&(/*v->Typ()*/t==RING_CMD))
329  {
330  res->rtyp=INT_CMD;
331  res->data=(void *)(long)(((ring)v->Data())->isLPring);
332  }
333 #endif
334  else
335  {
336  attr *aa=v->Attribute();
337  if (aa==NULL)
338  {
339  WerrorS("this object cannot have attributes");
340  return TRUE;
341  }
342  attr a=*aa;
343  a=a->get(name);
344  if (a!=NULL)
345  {
346  res->rtyp=a->atyp;
347  res->data=a->CopyA();
348  }
349  else
350  {
351  res->rtyp=STRING_CMD;
352  res->data=omStrDup("");
353  }
354  }
355  return FALSE;
356 }
358 {
359  idhdl h=(idhdl)v->data;
360  if (v->e!=NULL)
361  {
362  v=v->LData();
363  if (v==NULL) return TRUE;
364  h=NULL;
365  }
366  else if (v->rtyp!=IDHDL) h=NULL;
367  int t=v->Typ();
368 
369  char *name=(char *)b->Data();
370  if (strcmp(name,"isSB")==0)
371  {
372  if (c->Typ()!=INT_CMD)
373  {
374  WerrorS("attribute isSB must be int");
375  return TRUE;
376  }
377  if (((long)c->Data())!=0L)
378  {
379  if (h!=NULL) setFlag(h,FLAG_STD);
380  setFlag(v,FLAG_STD);
381  }
382  else
383  {
384  if (h!=NULL) resetFlag(h,FLAG_STD);
386  }
387  }
388  else if (strcmp(name,"qringNF")==0)
389  {
390  if (c->Typ()!=INT_CMD)
391  {
392  WerrorS("attribute qringNF must be int");
393  return TRUE;
394  }
395  if (((long)c->Data())!=0L)
396  {
397  if (h!=NULL) setFlag(h,FLAG_QRING);
399  }
400  else
401  {
402  if (h!=NULL) resetFlag(h,FLAG_QRING);
404  }
405  }
406  else if ((strcmp(name,"rank")==0)&&(/*v->Typ()*/t==MODUL_CMD))
407  {
408  if (c->Typ()!=INT_CMD)
409  {
410  WerrorS("attribute `rank` must be int");
411  return TRUE;
412  }
413  ideal I=(ideal)v->Data();
414  int rk=id_RankFreeModule(I,currRing);
415  I->rank=si_max(rk,(int)((long)c->Data()));
416  }
417  else if (((strcmp(name,"global")==0)
418  || (strcmp(name,"cf_class")==0)
419  || (strcmp(name,"ring_cf")==0)
420  || (strcmp(name,"maxExp")==0))
421  &&(/*v->Typ()*/t==RING_CMD))
422  {
423  Werror("can not set attribute `%s`",name);
424  return TRUE;
425  }
426 #ifdef HAVE_SHIFTBBA
427  else if ((strcmp(name,"isLetterplaceRing")==0)
428  &&(/*v->Typ()*/t==RING_CMD))
429  {
430  if (c->Typ()==INT_CMD)
431  ((ring)v->Data())->isLPring=(int)(long)c->Data();
432  else
433  {
434  WerrorS("attribute `isLetterplaceRing` must be int");
435  return TRUE;
436  }
437  }
438 #endif
439  else
440  {
441  int typ=c->Typ();
442  if (h!=NULL) atSet(h,omStrDup(name),c->CopyD(typ),typ/*c->T(yp()*/);
443  else atSet(v,omStrDup(name),c->CopyD(typ),typ/*c->T(yp()*/);
444  }
445  return FALSE;
446 }
447 
449 {
450  idhdl h=NULL;
451  if ((a->rtyp==IDHDL)&&(a->e==NULL))
452  {
453  h=(idhdl)a->data;
455  }
456  resetFlag(a,FLAG_STD);
457  if (h->attribute!=NULL)
458  {
459  atKillAll(h);
460  a->attribute=NULL;
461  }
462  else atKillAll(a);
463  return FALSE;
464 }
466 {
467  if ((a->rtyp!=IDHDL)||(a->e!=NULL))
468  {
469  WerrorS("object must have a name");
470  return TRUE;
471  }
472  char *name=(char *)b->Data();
473  if (strcmp(name,"isSB")==0)
474  {
475  resetFlag(a,FLAG_STD);
477  }
478  else if (strcmp(name,"global")==0)
479  {
480  WerrorS("can not set attribut `global`");
481  return TRUE;
482  }
483  else
484  {
485  atKill((idhdl)a->data,name);
486  }
487  return FALSE;
488 }
489 
BOOLEAN atATTRIB3(leftv, leftv v, leftv b, leftv c)
Definition: attrib.cc:357
STATIC_VAR omBin sattr_bin
Definition: attrib.cc:24
BOOLEAN atKILLATTR2(leftv, leftv a, leftv b)
Definition: attrib.cc:465
void * atGet(idhdl root, const char *name, int t, void *defaultReturnValue)
Definition: attrib.cc:129
BOOLEAN atKILLATTR1(leftv, leftv a)
Definition: attrib.cc:448
void at_KillAll(idhdl root, const ring r)
Definition: attrib.cc:219
void at_Kill(idhdl root, const char *name, const ring r)
Definition: attrib.cc:199
void atSet(idhdl root, char *name, void *data, int typ)
Definition: attrib.cc:150
static void attr_free(attr h, const ring r=currRing)
Definition: attrib.cc:56
BOOLEAN atATTRIB2(leftv res, leftv v, leftv b)
Definition: attrib.cc:275
BOOLEAN atATTRIB1(leftv res, leftv v)
Definition: attrib.cc:231
sattr * attr
Definition: attrib.h:15
#define atKillAll(H)
Definition: attrib.h:47
#define atKill(H, A)
Definition: attrib.h:49
static int si_max(const int a, const int b)
Definition: auxiliary.h:140
int BOOLEAN
Definition: auxiliary.h:87
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
void * ADDRESS
Definition: auxiliary.h:135
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
CanonicalForm cf
Definition: cfModGcd.cc:4024
CanonicalForm b
Definition: cfModGcd.cc:4044
Definition: idrec.h:35
attr attribute
Definition: idrec.h:41
Definition: attrib.h:21
void * data
Definition: attrib.h:25
attr Copy()
Definition: attrib.cc:33
attr get(const char *s)
Definition: attrib.cc:90
void kill(const ring r)
Definition: attrib.cc:180
void killAll(const ring r)
Definition: attrib.cc:186
void * CopyA()
Definition: subexpr.cc:2034
attr set(char *s, void *data, int t)
Definition: attrib.cc:67
int atyp
Definition: attrib.h:27
void Print()
Definition: attrib.cc:26
char * name
Definition: attrib.h:24
attr next
Definition: attrib.h:26
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
void * CopyD(int t)
Definition: subexpr.cc:739
int Typ()
Definition: subexpr.cc:1033
int rtyp
Definition: subexpr.h:91
void * Data()
Definition: subexpr.cc:1176
void * data
Definition: subexpr.h:88
attr * Attribute()
Definition: subexpr.cc:1470
Subexpr e
Definition: subexpr.h:105
attr attribute
Definition: subexpr.h:89
return result
Definition: facAbsBiFact.cc:76
const CanonicalForm int s
Definition: facAbsFact.cc:55
CanonicalForm res
Definition: facAbsFact.cc:64
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
char name(const Variable &v)
Definition: factory.h:180
void WerrorS(const char *s)
Definition: feFopen.cc:24
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:140
int RingDependend(int t)
Definition: gentable.cc:28
#define STATIC_VAR
Definition: globaldefs.h:7
@ MODUL_CMD
Definition: grammar.cc:287
@ RING_CMD
Definition: grammar.cc:281
#define resetFlag(A, F)
Definition: ipid.h:109
#define hasFlag(A, F)
Definition: ipid.h:107
#define setFlag(A, F)
Definition: ipid.h:108
#define FLAG_QRING
Definition: ipid.h:106
#define IDTYP(a)
Definition: ipid.h:114
#define FLAG_STD
Definition: ipid.h:104
STATIC_VAR Poly * h
Definition: janet.cc:971
if(yy_init)
Definition: libparse.cc:1420
#define assume(x)
Definition: mod2.h:390
The main handler for Singular numbers which are suitable for Singular polynomials.
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omCheckAddr(addr)
Definition: omAllocDecl.h:328
#define omCheckAddrSize(addr, size)
Definition: omAllocDecl.h:327
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
#define omFree(addr)
Definition: omAllocDecl.h:261
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
#define omGetSpecBin(size)
Definition: omBin.h:11
#define NULL
Definition: omList.c:12
omBin_t * omBin
Definition: omStructs.h:12
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
Compatiblity layer for legacy polynomial operations (over currRing)
void PrintS(const char *s)
Definition: reporter.cc:284
void Werror(const char *fmt,...)
Definition: reporter.cc:189
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:479
idrec * idhdl
Definition: ring.h:21
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
void s_internalDelete(const int t, void *d, const ring r)
Definition: subexpr.cc:514
#define IDHDL
Definition: tok.h:31
@ STRING_CMD
Definition: tok.h:184
@ INT_CMD
Definition: tok.h:96