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