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  && (IDTYP(root)!=QRING_CMD)
162  && (!RingDependend(IDTYP(root)))&&(RingDependend(typ)))
163  WerrorS("cannot set ring-dependend objects at this type");
164  else
165  root->attribute=root->attribute->set(name,data,typ);
166  }
167 }
168 
169 void atSet(leftv root,const char * name,void * data,int typ)
170 {
171  if (root!=NULL)
172  {
173  attr *a=root->Attribute();
174  int rt=root->Typ();
175  if (a==NULL)
176  WerrorS("cannot set attributes of this object");
177  else if ((rt!=RING_CMD)
178  && (rt!=QRING_CMD)
179  && (!RingDependend(rt))&&(RingDependend(typ)))
180  WerrorS("cannot set ring-dependend objects at this type");
181  else
182  {
183  *a=(*a)->set(name,data,typ);
184  }
185  }
186 }
187 
188 void sattr::kill(const ring r)
189 {
190  attr_free(this,r);
191  omFree((ADDRESS)name);
192  name=NULL;
193  omFreeBin((ADDRESS)this, sattr_bin);
194 }
195 
196 void sattr::killAll(const ring r)
197 {
198  attr temp = this,temp1;
199 
200  while (temp!=NULL)
201  {
202  temp1 = temp->next;
203  omCheckAddr(temp);
204  temp->kill(r);
205  temp = temp1;
206  }
207 }
208 
209 void at_Kill(idhdl root,const char * name, const ring r)
210 {
211  attr temp = root->attribute->get(name);
212  if (temp!=NULL)
213  {
214  attr N = temp->next;
215  attr temp1 = root->attribute;
216  if (temp1==temp)
217  {
218  root->attribute = N;
219  }
220  else
221  {
222  while (temp1->next!=temp) temp1 = temp1->next;
223  temp1->next = N;
224  }
225  temp->kill(r);
226  }
227 }
228 
229 void at_KillAll(idhdl root, const ring r)
230 {
231  root->attribute->killAll(r);
232  root->attribute = NULL;
233 }
234 
235 void at_KillAll(leftv root, const ring r)
236 {
237  root->attribute->killAll(r);
238  root->attribute = NULL;
239 }
240 
242 {
243  int t;
244  attr *aa=(v->Attribute());
245  if (aa==NULL)
246  {
247  WerrorS("this object cannot have attributes");
248  return TRUE;
249  }
250  attr a=*aa;
251  BOOLEAN haveNoAttribute=TRUE;
252  if (v->e==NULL)
253  {
254  if (hasFlag(v,FLAG_STD))
255  {
256  PrintS("attr:isSB, type int\n");
257  haveNoAttribute=FALSE;
258  }
259  if (hasFlag(v,FLAG_QRING))
260  {
261  PrintS("attr:qringNF, type int\n");
262  haveNoAttribute=FALSE;
263  }
264  if (((t=v->Typ())==RING_CMD)||(t==QRING_CMD))
265  {
266  PrintS("attr:global, type int\n");
267  haveNoAttribute=FALSE;
268  }
269  }
270  else
271  {
272  leftv at=v->LData();
273  return atATTRIB1(res,at);
274  }
275  if (a!=NULL) a->Print();
276  else if(haveNoAttribute) PrintS("no attributes\n");
277  return FALSE;
278 }
280 {
281  char *name=(char *)b->Data();
282  int t;
283  leftv at=NULL;
284  if (v->e!=NULL)
285  at=v->LData();
286  if (strcmp(name,"isSB")==0)
287  {
288  res->rtyp=INT_CMD;
289  res->data=(void *)(long)hasFlag(v,FLAG_STD);
290  if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_STD)||(hasFlag(at,FLAG_STD)));
291  }
292  else if ((strcmp(name,"rank")==0)&&(v->Typ()==MODUL_CMD))
293  {
294  res->rtyp=INT_CMD;
295  res->data=(void *)(((ideal)v->Data())->rank);
296  }
297  else if ((strcmp(name,"global")==0)
298  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
299  {
300  res->rtyp=INT_CMD;
301  res->data=(void *)(((ring)v->Data())->OrdSgn==1);
302  }
303  else if ((strcmp(name,"ring_cf")==0)
304  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
305  {
306  res->rtyp=INT_CMD;
307  res->data=(void *)(long)(rField_is_Ring((ring)v->Data()));
308  }
309  else if (strcmp(name,"qringNF")==0)
310  {
311  res->rtyp=INT_CMD;
312  res->data=(void *)(long)hasFlag(v,FLAG_QRING);
313  if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_QRING)||(hasFlag(at,FLAG_QRING)));
314  }
315 #ifdef HAVE_SHIFTBBA
316  else if ((strcmp(name,"isLPring")==0)
317  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
318  {
319  res->rtyp=INT_CMD;
320  res->data=(void *)(long)(((ring)v->Data())->isLPring);
321  }
322 #endif
323  else
324  {
325  attr *aa=v->Attribute();
326  if (aa==NULL)
327  {
328  WerrorS("this object cannot have attributes");
329  return TRUE;
330  }
331  attr a=*aa;
332  a=a->get(name);
333  if (a!=NULL)
334  {
335  res->rtyp=a->atyp;
336  res->data=a->CopyA();
337  }
338  else
339  {
340  res->rtyp=STRING_CMD;
341  res->data=omStrDup("");
342  }
343  }
344  return FALSE;
345 }
347 {
348  idhdl h=(idhdl)v->data;
349  int t;
350  if (v->e!=NULL)
351  {
352  v=v->LData();
353  if (v==NULL) return TRUE;
354  h=NULL;
355  }
356  else if (v->rtyp!=IDHDL) h=NULL;
357 
358  char *name=(char *)b->Data();
359  if (strcmp(name,"isSB")==0)
360  {
361  if (c->Typ()!=INT_CMD)
362  {
363  WerrorS("attribute isSB must be int");
364  return TRUE;
365  }
366  if (((long)c->Data())!=0L)
367  {
368  if (h!=NULL) setFlag(h,FLAG_STD);
369  setFlag(v,FLAG_STD);
370  }
371  else
372  {
373  if (h!=NULL) resetFlag(h,FLAG_STD);
374  resetFlag(v,FLAG_STD);
375  }
376  }
377  else if (strcmp(name,"qringNF")==0)
378  {
379  if (c->Typ()!=INT_CMD)
380  {
381  WerrorS("attribute qringNF must be int");
382  return TRUE;
383  }
384  if (((long)c->Data())!=0L)
385  {
386  if (h!=NULL) setFlag(h,FLAG_QRING);
387  setFlag(v,FLAG_QRING);
388  }
389  else
390  {
391  if (h!=NULL) resetFlag(h,FLAG_QRING);
393  }
394  }
395  else if ((strcmp(name,"rank")==0)&&(v->Typ()==MODUL_CMD))
396  {
397  if (c->Typ()!=INT_CMD)
398  {
399  WerrorS("attribute `rank` must be int");
400  return TRUE;
401  }
402  ideal I=(ideal)v->Data();
403  I->rank=si_max((int)I->rank,(int)((long)c->Data()));
404  }
405  else if ((strcmp(name,"global")==0)
406  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
407  {
408  WerrorS("can not set attribute `global`");
409  return TRUE;
410  }
411 #ifdef HAVE_SHIFTBBA
412  else if ((strcmp(name,"isLPring")==0)
413  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
414  {
415  if (c->Typ()==INT_CMD)
416  ((ring)v->Data())->isLPring=(int)(long)c->Data();
417  else
418  {
419  WerrorS("attribute `isLPring` must be int");
420  return TRUE;
421  }
422  }
423 #endif
424  else
425  {
426  int typ=c->Typ();
427  if (h!=NULL) atSet(h,omStrDup(name),c->CopyD(typ),typ/*c->T(yp()*/);
428  else atSet(v,omStrDup(name),c->CopyD(typ),typ/*c->T(yp()*/);
429  }
430  return FALSE;
431 }
432 
434 {
435  idhdl h=NULL;
436  if ((a->rtyp==IDHDL)&&(a->e==NULL))
437  {
438  h=(idhdl)a->data;
440  }
441  resetFlag(a,FLAG_STD);
442  if (h->attribute!=NULL)
443  {
444  atKillAll(h);
445  a->attribute=NULL;
446  }
447  else atKillAll(a);
448  return FALSE;
449 }
451 {
452  if ((a->rtyp!=IDHDL)||(a->e!=NULL))
453  {
454  WerrorS("object must have a name");
455  return TRUE;
456  }
457  char *name=(char *)b->Data();
458  if (strcmp(name,"isSB")==0)
459  {
460  resetFlag(a,FLAG_STD);
462  }
463  else if (strcmp(name,"global")==0)
464  {
465  WerrorS("can not set attribut `global`");
466  return TRUE;
467  }
468  else
469  {
470  atKill((idhdl)a->data,name);
471  }
472  return FALSE;
473 }
474 
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:85
void killAll(const ring r)
Definition: attrib.cc:196
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:140
Compatiblity layer for legacy polynomial operations (over currRing)
attr * Attribute()
Definition: subexpr.cc:1366
void * data
Definition: attrib.h:20
void at_KillAll(idhdl root, const ring r)
Definition: attrib.cc:229
#define TRUE
Definition: auxiliary.h:144
void * ADDRESS
Definition: auxiliary.h:161
void WerrorS(const char *s)
Definition: feFopen.cc:24
BOOLEAN atKILLATTR2(leftv, leftv a, leftv b)
Definition: attrib.cc:450
BOOLEAN atKILLATTR1(leftv, leftv a)
Definition: attrib.cc:433
int Typ()
Definition: subexpr.cc:969
void kill(const ring r)
Definition: attrib.cc:188
Definition: idrec.h:34
#define IDHDL
Definition: tok.h:35
BOOLEAN atATTRIB2(leftv res, leftv v, leftv b)
Definition: attrib.cc:279
void at_Kill(idhdl root, const char *name, const ring r)
Definition: attrib.cc:209
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:12
#define IDTYP(a)
Definition: ipid.h:118
void * CopyA()
Definition: subexpr.cc:1932
sattr * attr
Definition: attrib.h:13
int RingDependend(int t)
Definition: gentable.cc:23
const ring r
Definition: syzextra.cc:208
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
BOOLEAN atATTRIB3(leftv, leftv v, leftv b, leftv c)
Definition: attrib.cc:346
#define omFree(addr)
Definition: omAllocDecl.h:261
#define assume(x)
Definition: mod2.h:405
void s_internalDelete(const int t, void *d, const ring r)
Definition: subexpr.cc:478
#define setFlag(A, F)
Definition: ipid.h:112
static int si_max(const int a, const int b)
Definition: auxiliary.h:166
idrec * idhdl
Definition: ring.h:18
#define FLAG_QRING
Definition: ipid.h:110
void PrintS(const char *s)
Definition: reporter.cc:294
#define atKill(H, A)
Definition: attrib.h:44
#define FLAG_STD
Definition: ipid.h:108
BOOLEAN atATTRIB1(leftv res, leftv v)
Definition: attrib.cc:241
#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
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:437
#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:128
#define hasFlag(A, F)
Definition: ipid.h:111
attr next
Definition: attrib.h:21
int rtyp
Definition: subexpr.h:92
void * Data()
Definition: subexpr.cc:1111
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
Definition: tok.h:126
#define omCheckAddr(addr)
Definition: omAllocDecl.h:328
#define resetFlag(A, F)
Definition: ipid.h:113
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:131
const poly b
Definition: syzextra.cc:213
leftv LData()
Definition: subexpr.cc:1380
void * CopyD(int t)
Definition: subexpr.cc:676
int atyp
Definition: attrib.h:22
return result
Definition: facAbsBiFact.cc:76
#define omStrDup(s)
Definition: omAllocDecl.h:263