source: git/Singular/attrib.cc @ 67555db

spielwiese
Last change on this file since 67555db was 67555db, checked in by Hans Schönemann <hannes@…>, 15 years ago
*hannes: show also attr. of rings git-svn-id: file:///usr/local/Singular/svn/trunk@11411 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 8.5 KB
RevLine 
[0e1846]1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
[67555db]4/* $Id: attrib.cc,v 1.32 2009-02-20 09:27:45 Singular Exp $ */
[74f19d]5
[0e1846]6/*
[e2f1c7]7* ABSTRACT: attributes to leftv and idhdl
[0e1846]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"
[512a2b]17#include "omalloc.h"
[0e1846]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"
[c232af]26
27static omBin sattr_bin = omGetSpecBin(sizeof(sattr));
[0e1846]28
29void sattr::Print()
30{
[c232af]31  omCheckAddrSize(this,sizeof(sattr));
[0e1846]32  ::Print("attr:%s, type %s \n",name,Tok2Cmdname(atyp));
33  if (next!=NULL) next->Print();
34}
35
36attr sattr::Copy()
37{
[c232af]38  omCheckAddrSize(this,sizeof(sattr));
39  attr n=(attr)omAlloc0Bin(sattr_bin);
[0e1846]40  n->atyp=atyp;
[c232af]41  if (name!=NULL) n->name=omStrDup(name);
[0e1846]42  n->data=CopyA();
43  if (next!=NULL)
44  {
45    n->next=next->Copy();
46  }
47  return n;
48}
49
[f71681]50// in subexr.cc:
51//void * sattr::CopyA()
52//{
53//  omCheckAddrSize(this,sizeof(sattr));
54//  return s_internalCopy(atyp,data);
55//}
[0e1846]56
[85e68dd]57attr sattr::set(const char * s, void * data, int t)
[0e1846]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:
[c232af]79      omFree((ADDRESS)h->data);
[0e1846]80      break;
81#ifdef TEST
82    default:
[714312]83      ::Print("at-set: unknown type(%d)\n",atyp);  /* DEBUG */
[0e1846]84#endif
85    } /* end switch: (atyp) */
[c232af]86    omFree((ADDRESS)s);
[0e1846]87  }
88  else
89  {
[c232af]90     h = (attr)omAlloc0Bin(sattr_bin);
[0e1846]91     h->name = s;
92     h->next = this;
[30acf16]93     h->data = data;
94     h->atyp = t;
95     return  h;
[0e1846]96  }
97  //::Print("set attr >>%s<< of type %d\n",h->name,t);
98  h->data = data;
99  h->atyp = t;
[30acf16]100  return  this;
[0e1846]101}
102
[85e68dd]103attr sattr::get(const char * s)
[0e1846]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
[85e68dd]114void * atGet(idhdl root,const char * name)
[0e1846]115{
116  attr temp = root->attribute->get(name);
117  if (temp!=NULL)
118    return temp->data;
119  else
120    return NULL;
121}
122
[85e68dd]123void * atGet(leftv root,const char * name)
[0e1846]124{
[71df1a]125  attr temp;
[54b460]126  if (root->e==NULL)
[71df1a]127    temp = root->attribute->get(name);
128  else
129    temp = (root->LData())->attribute->get(name);
[0e1846]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
[85e68dd]141void * atGet(idhdl root,const char * name, int t)
[242d8f]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
[85e68dd]150void * atGet(leftv root,const char * name, int t)
[242d8f]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
[85e68dd]164void atSet(idhdl root,const char * name,void * data,int typ)
[0e1846]165{
166  if (root!=NULL)
167  {
168    root->attribute=root->attribute->set(name,data,typ);
169  }
170}
171
[85e68dd]172void atSet(leftv root,const char * name,void * data,int typ)
[0e1846]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{
[c232af]198  omFree((ADDRESS)name);
[0e1846]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:
[c232af]217    omFree((ADDRESS)data);
[0e1846]218    break;
219#ifdef TEST
220  default:
[714312]221    ::Print("atKill: unknown type(%d)\n",atyp);  /* DEBUG */
[0e1846]222#endif
223  } /* end switch: (atyp) */
224  data=NULL;
[c232af]225  omFreeBin((ADDRESS)this, sattr_bin);
[0e1846]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
[85e68dd]240void atKill(idhdl root,const char * name)
[0e1846]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;
[242d8f]269  int t;
[0e1846]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  }
[242d8f]281  else if (((t=v->Typ())==RING_CMD)||(t==QRING_CMD))
282  {
283    PrintS("attr:global, type int\n");
[67555db]284    if (at!=NULL) at->Print();
[242d8f]285  }
[0e1846]286  else
287  {
288    if (at!=NULL) at->Print();
289    else          PrintS("no attributes\n");
290  }
291  return FALSE;
292}
293BOOLEAN atATTRIB2(leftv res,leftv a,leftv b)
294{
295  char *name=(char *)b->Data();
[242d8f]296  int t;
[0e1846]297  leftv v=a;
298  if (a->e!=NULL)
299  {
300    v=a->LData();
301    if (v==NULL) return TRUE;
302  }
303  if (strcmp(name,"isSB")==0)
304  {
305    res->rtyp=INT_CMD;
[09bbf5]306    res->data=(void *)(long)hasFlag(v,FLAG_STD);
[0e1846]307  }
308  else if ((strcmp(name,"rank")==0)&&(v->Typ()==MODUL_CMD))
309  {
310    res->rtyp=INT_CMD;
311    res->data=(void *)(((ideal)v->Data())->rank);
312  }
[242d8f]313  else if ((strcmp(name,"global")==0)
314  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
315  {
316    res->rtyp=INT_CMD;
317    res->data=(void *)(((ring)v->Data())->OrdSgn==1);
318  }
[b27003e]319#ifdef HAVE_SHIFTBBA
320  else if ((strcmp(name,"isLPring")==0)
321  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
322  {
323    res->rtyp=INT_CMD;
324    res->data=(void *)(((ring)v->Data())->isLPring);
325  }
326#endif
[0e1846]327  else
328  {
329    attr at=v->attribute->get(name);
330    if (at!=NULL)
331    {
332      res->rtyp=at->atyp;
333      res->data=at->CopyA();
334    }
335    else
336    {
337      res->rtyp=STRING_CMD;
[c232af]338      res->data=omStrDup("");
[0e1846]339    }
340  }
341  return FALSE;
342}
343BOOLEAN atATTRIB3(leftv res,leftv a,leftv b,leftv c)
344{
345  idhdl h=(idhdl)a->data;
[242d8f]346  int t;
[0e1846]347  leftv v=a;
348  if (a->e!=NULL)
349  {
350    v=a->LData();
351    if (v==NULL) return TRUE;
352    h=NULL;
353  }
354  attr *at=&(v->attribute);
355  char *name=(char *)b->Data();
356  if (strcmp(name,"isSB")==0)
357  {
358    if (c->Typ()!=INT_CMD)
359    {
[b27003e]360      WerrorS("attribute isSB must be int");
[0e1846]361      return TRUE;
362    }
[7447d8]363    if (((long)c->Data())!=0L)
[0e1846]364    {
365      if (h!=NULL) setFlag(h,FLAG_STD);
366      setFlag(v,FLAG_STD);
367    }
368    else
369    {
370      if (h!=NULL) resetFlag(h,FLAG_STD);
371      resetFlag(v,FLAG_STD);
372    }
373  }
374  else if ((strcmp(name,"rank")==0)&&(v->Typ()==MODUL_CMD))
375  {
376    if (c->Typ()!=INT_CMD)
377    {
[b27003e]378      WerrorS("attribute `rank` must be int");
[0e1846]379      return TRUE;
380    }
381    ideal I=(ideal)v->Data();
[7447d8]382    I->rank=si_max((int)I->rank,(int)((long)c->Data()));
[0e1846]383  }
[242d8f]384  else if ((strcmp(name,"global")==0)
385  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
386  {
[b27003e]387    WerrorS("can not set attribute `global`");
[242d8f]388    return TRUE;
389  }
[b27003e]390#ifdef HAVE_SHIFTBBA
391  else if ((strcmp(name,"isLPring")==0)
392  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
393  {
394    if (c->Typ()==INT_CMD)
395      ((ring)v->Data())->isLPring=(int)(long)c->Data();
396    else
397    {
398      WerrorS("attribute `isLPring` must be int");
399      return TRUE;
400    }
401  }
402#endif
[0e1846]403  else
404  {
[2166ad3]405    int typ=c->Typ();
[c232af]406    atSet(v,omStrDup(name),c->CopyD(typ),typ/*c->T(yp()*/);
[0e1846]407    if (h!=NULL) IDATTR(h)=v->attribute;
408  }
409  return FALSE;
410}
411
412BOOLEAN atKILLATTR1(leftv res,leftv a)
413{
414  if ((a->rtyp!=IDHDL)||(a->e!=NULL))
415  {
[da97958]416    WerrorS("object must have a name");
[0e1846]417    return TRUE;
418  }
419  resetFlag(a,FLAG_STD);
420  resetFlag((idhdl)a->data,FLAG_STD);
421  if (a->attribute!=NULL)
422  {
423    atKillAll((idhdl)a->data);
424    a->attribute=NULL;
425  }
426  return FALSE;
427}
428BOOLEAN atKILLATTR2(leftv res,leftv a,leftv b)
429{
430  if ((a->rtyp!=IDHDL)||(a->e!=NULL))
431  {
[da97958]432    WerrorS("object must have a name");
[0e1846]433    return TRUE;
434  }
435  char *name=(char *)b->Data();
436  if (strcmp(name,"isSB")==0)
437  {
438    resetFlag(a,FLAG_STD);
439    resetFlag((idhdl)a->data,FLAG_STD);
440  }
[242d8f]441  else if (strcmp(name,"global")==0)
442  {
443    WerrorS("can not set attribut `global`");
444    return TRUE;
445  }
[0e1846]446  else
447  {
448    atKill((idhdl)a->data,name);
449  }
450  return FALSE;
451}
Note: See TracBrowser for help on using the repository browser.