Changeset 2049435a in tol


Ignore:
Timestamp:
Nov 4, 2009, 5:39:43 PM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
99b1a94
Parents:
11cb1142
Message:

Fixes #773

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1600 be4846ae-f051-483a-831f-b64e7d08527f

Location:
tol/btol/set_type
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tol/btol/set_type/set.cpp

    r11cb1142 r2049435a  
    130130
    131131//--------------------------------------------------------------------
    132 void    BSet::Copy(const BSet& set)
     132void BSet::Copy(const BSet& set)
    133133//--------------------------------------------------------------------
    134134{
    … …  
    136136  Delete();
    137137  array_.ReallocBuffer(set.Card());
    138   bool hasIdx = set.HasIndexByName();
     138  bool hasIdx = set.HasIndexByName()!=0;
    139139  for(n=0; n<array_.Size(); n++)
    140140  {
    … …  
    331331
    332332//--------------------------------------------------------------------
    333 void BSet::Append(const BSet& set)
    334 //--------------------------------------------------------------------
    335 {
     333static bool DoIndexElement(BObjByIdxNameHash** indexByName,
     334                           BSyntaxObject* obj,
     335                           int i)
     336//--------------------------------------------------------------------
     337{
     338  bool ok = true;
     339  if(indexByName && *indexByName && obj)
     340  {
     341    const BText& name = obj->Name();
     342    if(name.HasName())
     343    {
     344      BObjByIdxNameHash::const_iterator found = (*indexByName)->find(name);
     345      if(found!=(*indexByName)->end())
     346      {
     347        Error(I2("Duplicated index name ",
     348                 "Nombre de ᅵndice duplicado ")+
     349              name);
     350        ok = false;
     351      }
     352      (**indexByName)[name] = BIndexedSyntaxObject(i,obj);
     353    }
     354    else
     355    {
     356      Error(I2("A indexed by name set cannot have elements without a valid name ",
     357               "Un conjunto indexado por nombres no puede tener elementos sin un nombre vᅵlido ")
     358            +"'"+name+"'");
     359      ok = false;
     360    }
     361   if(!ok) { delete *indexByName; *indexByName = NULL; }
     362  }
     363  return(ok);
     364}
     365
     366//--------------------------------------------------------------------
     367void BSet::Append(const BSet& set, bool incrementalIndex)
     368//--------------------------------------------------------------------
     369{
     370  if(!incrementalIndex && indexByName_)
     371  { delete indexByName_; indexByName_ = NULL; }
     372  if(incrementalIndex && !array_.Size())
     373  {
     374    indexByName_ = new BObjByIdxNameHash;
     375    SetEmptyKey((*indexByName_), NULL);
     376  }
    336377  int m=Card(), n=set.Card(), i, j=m;
    337378  array_.ReallocBuffer(m+n);
    … …  
    340381    array_[j]=set[i];
    341382    array_[j]->IncNRefs();
     383    DoIndexElement(&indexByName_,array_[j],j);
    342384  }
    343385}
    … …  
    393435  SetEmptyKey((*indexByName_), NULL);
    394436
    395   BSyntaxObject* obj;
    396   int i, j;
     437  int i;
    397438  if(!array_.Size())
    398439  {
    … …  
    401442    return(false);
    402443  }
    403   for(i=j=0; i<array_.Size(); i++)
    404   {
    405     obj = array_[i];
    406     assert(obj);
    407     const BText& name = obj->Name();
    408     if(name.HasName())
    409     {
    410       if(operator[](name))
    411       {
    412         Error(I2("Duplicated index name ",
    413                  "Nombre de ᅵndice duplicado ")+
    414               name);
    415         return(false);
    416       }
    417       (*indexByName_)[name] = BIndexedSyntaxObject(i,obj);
    418     }
    419     else
    420     {
    421       Error(I2("A indexed by name set cannot have elements without a valid name ",
    422                "Un conjunto indexado por nombres no puede tener elementos sin un nombre vᅵlido ")
    423             +"'"+name+"'");
    424       return(false);
    425     }
     444  for(i=0; i<array_.Size(); i++)
     445  {
     446    assert(array_[i]);
     447    if(!DoIndexElement(&indexByName_,array_[i],i)) { return(false); }
    426448  }
    427449  return(true);
  • tol/btol/set_type/setgra.cpp

    r11cb1142 r2049435a  
    106106  : BExternalOperator
    107107    (
    108       "Append", GraSet(), "Set Set", NIL, 2, 2,
    109       "(Set set1, Set set2)",
     108      "Append", GraSet(), "Set Set Real", NIL, 2, 3,
     109      "(Set set1, Set set2, [Real incrementalIndexByName=False])",
    110110                  I2("Attaches the elements of set2 to the end of set1 without "
    111        "eliminating repeated elements and preserving the order.",
     111       "eliminating repeated elements and preserving the order.\n"
     112       "If incrementalIndexByName is true then the index of names "
     113       "will be incremented if original set had an index, or created i"  ,
    112114             "Concatena los elementos del conjunto set1 al final de set2 "
    113        "sin eliminar elementos repetidos y conservando el orden."),
     115       "sin eliminar elementos repetidos y conservando el orden.\n"
     116       "Si incrementalIndexByName es cierto entonces el índice de "
     117       "nombres, se mantendrá incrementalmente, siempre y cuando "
     118       "ya existiera previamente y los nuevos elementos sean "
     119       "compatibles, o bien se creará un índice nuevo si se parte "
     120       "del conjunto vacío."),
    114121                  BOperClassify::SetAlgebra_
    115122    )
    … …  
    122129  {
    123130    BList* lst = arg;
     131    bool incrementalIndexByName = false;
    124132    BUserSet* uSet1 = USet(lst->Car()); lst = lst->Cdr();
    125133    BUserSet* uSet2 = USet(lst->Car()); lst = lst->Cdr();
    126     uSet1->Contens().Append(uSet2->Contens());
     134    if(lst && lst->Car())
     135    {
     136      BUserDat* uDat3 = UDat(lst->Car());
     137      incrementalIndexByName = uDat3->Contens()!=0.0;
     138    }
     139    uSet1->Contens().Append(uSet2->Contens(),incrementalIndexByName);
    127140    SAFE_DESTROY(arg, uSet1);
    128141    return(uSet1);
  • tol/btol/set_type/tol_bset.h

    r11cb1142 r2049435a  
    134134  void   Delete  ();
    135135  void   PrepareStore(int n) { Alloc(n); Alloc(0); }
    136   void   Append(const BSet& set);
     136  void   Append(const BSet& set, bool incrementalIndex);
    137137  void   AddElement(BSyntaxObject*);
    138138  void   PutElement(BList* element = NIL);
Note: See TracChangeset for help on using the changeset viewer.