source: git/Singular/attrib.cc @ faed79

spielwiese
Last change on this file since faed79 was b27003e, checked in by Viktor Levandovskyy <levandov@…>, 15 years ago
*levandov: introducing the attribute isLPring for letterplace rings git-svn-id: file:///usr/local/Singular/svn/trunk@11230 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 8.5 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: attrib.cc,v 1.31 2008-12-09 17:32:52 levandov Exp $ */
5
6/*
7* ABSTRACT: attributes to leftv and idhdl
8*/
9
10#include <stdlib.h>
11#include <stdio.h>
12#include <string.h>
13#include <ctype.h>
14#include <unistd.h>
15
16#include "mod2.h"
17#include "omalloc.h"
18#include "tok.h"
19#include "ipid.h"
20#include "intvec.h"
21#include "polys.h"
22#include "ideals.h"
23#include "matpol.h"
24#include "ipshell.h"
25#include "attrib.h"
26
27static omBin sattr_bin = omGetSpecBin(sizeof(sattr));
28
29void sattr::Print()
30{
31  omCheckAddrSize(this,sizeof(sattr));
32  ::Print("attr:%s, type %s \n",name,Tok2Cmdname(atyp));
33  if (next!=NULL) next->Print();
34}
35
36attr sattr::Copy()
37{
38  omCheckAddrSize(this,sizeof(sattr));
39  attr n=(attr)omAlloc0Bin(sattr_bin);
40  n->atyp=atyp;
41  if (name!=NULL) n->name=omStrDup(name);
42  n->data=CopyA();
43  if (next!=NULL)
44  {
45    n->next=next->Copy();
46  }
47  return n;
48}
49
50// in subexr.cc:
51//void * sattr::CopyA()
52//{
53//  omCheckAddrSize(this,sizeof(sattr));
54//  return s_internalCopy(atyp,data);
55//}
56
57attr sattr::set(const char * s, void * data, int t)
58{
59  attr h = get(s);
60  if (h!=NULL)
61  {
62    switch (h->atyp)
63    {
64    case INTVEC_CMD:
65      delete (intvec *)h->data;
66      break;
67    case IDEAL_CMD:
68    case MODUL_CMD:
69    case MATRIX_CMD:
70      idDelete((ideal *)&h->data);
71      break;
72    case POLY_CMD:
73    case VECTOR_CMD:
74      pDelete((poly *)&h->data);
75      break;
76    case INT_CMD:
77      break;
78    case STRING_CMD:
79      omFree((ADDRESS)h->data);
80      break;
81#ifdef TEST
82    default:
83      ::Print("at-set: unknown type(%d)\n",atyp);  /* DEBUG */
84#endif
85    } /* end switch: (atyp) */
86    omFree((ADDRESS)s);
87  }
88  else
89  {
90     h = (attr)omAlloc0Bin(sattr_bin);
91     h->name = s;
92     h->next = this;
93     h->data = data;
94     h->atyp = t;
95     return  h;
96  }
97  //::Print("set attr >>%s<< of type %d\n",h->name,t);
98  h->data = data;
99  h->atyp = t;
100  return  this;
101}
102
103attr sattr::get(const char * s)
104{
105  attr h = this;
106  while (h!=NULL)
107  {
108    if (0 == strcmp(s,h->name)) return h;
109    h = h->next;
110  }
111  return NULL;
112}
113
114void * 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
123void * atGet(leftv root,const char * name)
124{
125  attr temp;
126  if (root->e==NULL)
127    temp = root->attribute->get(name);
128  else
129    temp = (root->LData())->attribute->get(name);
130  if ((temp==NULL) && (root->rtyp==IDHDL))
131  {
132    idhdl h=(idhdl)root->data;
133    temp=h->attribute->get(name);
134  }
135  if (temp!=NULL)
136    return temp->data;
137  else
138    return NULL;
139}
140
141void * atGet(idhdl root,const char * name, int t)
142{
143  attr temp = root->attribute->get(name);
144  if ((temp!=NULL) && (temp->atyp==t))
145    return temp->data;
146  else
147    return NULL;
148}
149
150void * atGet(leftv root,const char * name, int t)
151{
152  attr temp = root->attribute->get(name);
153  if ((temp==NULL) && (root->rtyp==IDHDL))
154  {
155    idhdl h=(idhdl)root->data;
156    temp=h->attribute->get(name);
157  }
158  if ((temp!=NULL) && (temp->atyp==t))
159    return temp->data;
160  else
161    return NULL;
162}
163
164void atSet(idhdl root,const char * name,void * data,int typ)
165{
166  if (root!=NULL)
167  {
168    root->attribute=root->attribute->set(name,data,typ);
169  }
170}
171
172void atSet(leftv root,const char * name,void * data,int typ)
173{
174  if (root!=NULL)
175  {
176    if (root->e!=NULL)
177    {
178      Werror("object must have a name for attrib %s",name);
179    }
180    else
181    {
182      if (root->rtyp==IDHDL)
183      {
184        idhdl h=(idhdl)root->data;
185        h->attribute=h->attribute->set(name,data,typ);
186        root->attribute=h->attribute;
187      }
188      else
189      {
190        root->attribute=root->attribute->set(name,data,typ);
191      }
192    }
193  }
194}
195
196void sattr::kill()
197{
198  omFree((ADDRESS)name);
199  name=NULL;
200  switch (atyp)
201  {
202  case INTVEC_CMD:
203    delete (intvec *)data;
204    break;
205  case IDEAL_CMD:
206  case MODUL_CMD:
207  case MATRIX_CMD:
208    idDelete((ideal *)&data);
209    break;
210  case POLY_CMD:
211  case VECTOR_CMD:
212    pDelete((poly *)&data);
213    break;
214  case INT_CMD:
215    break;
216  case STRING_CMD:
217    omFree((ADDRESS)data);
218    break;
219#ifdef TEST
220  default:
221    ::Print("atKill: unknown type(%d)\n",atyp);  /* DEBUG */
222#endif
223  } /* end switch: (atyp) */
224  data=NULL;
225  omFreeBin((ADDRESS)this, sattr_bin);
226}
227
228void sattr::killAll()
229{
230  attr temp = this,temp1;
231
232  while (temp!=NULL)
233  {
234    temp1 = temp->next;
235    temp->kill();
236    temp = temp1;
237  }
238}
239
240void atKill(idhdl root,const char * name)
241{
242  attr temp = root->attribute->get(name);
243  if (temp!=NULL)
244  {
245    attr N = temp->next;
246    attr temp1 = root->attribute;
247    if (temp1==temp)
248    {
249      root->attribute = N;
250    }
251    else
252    {
253      while (temp1->next!=temp) temp1 = temp1->next;
254      temp1->next = N;
255    }
256    temp->kill();
257  }
258}
259
260void atKillAll(idhdl root)
261{
262  root->attribute->killAll();
263  root->attribute = NULL;
264}
265
266BOOLEAN atATTRIB1(leftv res,leftv a)
267{
268  leftv v=a;
269  int t;
270  if (a->e!=NULL)
271  {
272    v=a->LData();
273    if (v==NULL) return TRUE;
274  }
275  attr at=v->attribute;
276  if (hasFlag(v,FLAG_STD))
277  {
278    PrintS("attr:isSB, type int\n");
279    if (at!=NULL) at->Print();
280  }
281  else if (((t=v->Typ())==RING_CMD)||(t==QRING_CMD))
282  {
283    PrintS("attr:global, type int\n");
284  }
285  else
286  {
287    if (at!=NULL) at->Print();
288    else          PrintS("no attributes\n");
289  }
290  return FALSE;
291}
292BOOLEAN atATTRIB2(leftv res,leftv a,leftv b)
293{
294  char *name=(char *)b->Data();
295  int t;
296  leftv v=a;
297  if (a->e!=NULL)
298  {
299    v=a->LData();
300    if (v==NULL) return TRUE;
301  }
302  if (strcmp(name,"isSB")==0)
303  {
304    res->rtyp=INT_CMD;
305    res->data=(void *)(long)hasFlag(v,FLAG_STD);
306  }
307  else if ((strcmp(name,"rank")==0)&&(v->Typ()==MODUL_CMD))
308  {
309    res->rtyp=INT_CMD;
310    res->data=(void *)(((ideal)v->Data())->rank);
311  }
312  else if ((strcmp(name,"global")==0)
313  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
314  {
315    res->rtyp=INT_CMD;
316    res->data=(void *)(((ring)v->Data())->OrdSgn==1);
317  }
318#ifdef HAVE_SHIFTBBA
319  else if ((strcmp(name,"isLPring")==0)
320  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
321  {
322    res->rtyp=INT_CMD;
323    res->data=(void *)(((ring)v->Data())->isLPring);
324  }
325#endif
326  else
327  {
328    attr at=v->attribute->get(name);
329    if (at!=NULL)
330    {
331      res->rtyp=at->atyp;
332      res->data=at->CopyA();
333    }
334    else
335    {
336      res->rtyp=STRING_CMD;
337      res->data=omStrDup("");
338    }
339  }
340  return FALSE;
341}
342BOOLEAN atATTRIB3(leftv res,leftv a,leftv b,leftv c)
343{
344  idhdl h=(idhdl)a->data;
345  int t;
346  leftv v=a;
347  if (a->e!=NULL)
348  {
349    v=a->LData();
350    if (v==NULL) return TRUE;
351    h=NULL;
352  }
353  attr *at=&(v->attribute);
354  char *name=(char *)b->Data();
355  if (strcmp(name,"isSB")==0)
356  {
357    if (c->Typ()!=INT_CMD)
358    {
359      WerrorS("attribute isSB must be int");
360      return TRUE;
361    }
362    if (((long)c->Data())!=0L)
363    {
364      if (h!=NULL) setFlag(h,FLAG_STD);
365      setFlag(v,FLAG_STD);
366    }
367    else
368    {
369      if (h!=NULL) resetFlag(h,FLAG_STD);
370      resetFlag(v,FLAG_STD);
371    }
372  }
373  else if ((strcmp(name,"rank")==0)&&(v->Typ()==MODUL_CMD))
374  {
375    if (c->Typ()!=INT_CMD)
376    {
377      WerrorS("attribute `rank` must be int");
378      return TRUE;
379    }
380    ideal I=(ideal)v->Data();
381    I->rank=si_max((int)I->rank,(int)((long)c->Data()));
382  }
383  else if ((strcmp(name,"global")==0)
384  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
385  {
386    WerrorS("can not set attribute `global`");
387    return TRUE;
388  }
389#ifdef HAVE_SHIFTBBA
390  else if ((strcmp(name,"isLPring")==0)
391  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
392  {
393    if (c->Typ()==INT_CMD)
394      ((ring)v->Data())->isLPring=(int)(long)c->Data();
395    else
396    {
397      WerrorS("attribute `isLPring` must be int");
398      return TRUE;
399    }
400  }
401#endif
402  else
403  {
404    int typ=c->Typ();
405    atSet(v,omStrDup(name),c->CopyD(typ),typ/*c->T(yp()*/);
406    if (h!=NULL) IDATTR(h)=v->attribute;
407  }
408  return FALSE;
409}
410
411BOOLEAN atKILLATTR1(leftv res,leftv a)
412{
413  if ((a->rtyp!=IDHDL)||(a->e!=NULL))
414  {
415    WerrorS("object must have a name");
416    return TRUE;
417  }
418  resetFlag(a,FLAG_STD);
419  resetFlag((idhdl)a->data,FLAG_STD);
420  if (a->attribute!=NULL)
421  {
422    atKillAll((idhdl)a->data);
423    a->attribute=NULL;
424  }
425  return FALSE;
426}
427BOOLEAN atKILLATTR2(leftv res,leftv a,leftv b)
428{
429  if ((a->rtyp!=IDHDL)||(a->e!=NULL))
430  {
431    WerrorS("object must have a name");
432    return TRUE;
433  }
434  char *name=(char *)b->Data();
435  if (strcmp(name,"isSB")==0)
436  {
437    resetFlag(a,FLAG_STD);
438    resetFlag((idhdl)a->data,FLAG_STD);
439  }
440  else if (strcmp(name,"global")==0)
441  {
442    WerrorS("can not set attribut `global`");
443    return TRUE;
444  }
445  else
446  {
447    atKill((idhdl)a->data,name);
448  }
449  return FALSE;
450}
Note: See TracBrowser for help on using the repository browser.