Changeset f529e3c in tol


Ignore:
Timestamp:
Mar 29, 2010, 10:08:23 AM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
8e8520b
Parents:
5a3449c
Message:

New class @Glossary

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol_pkg/HashMap/HashMap.tol

    r5a3449c rf529e3c  
    1616Set _.autodoc.authors = [[
    1717   "vdebuen@tol-project.org"]];
     18
     19//////////////////////////////////////////////////////////////////////////////
     20Text _.autodoc.member.Glossary = "Implements a glossary of unique terms";
     21Class @Glossary
     22//////////////////////////////////////////////////////////////////////////////
     23{
     24  Text _.name;
     25  Set  _.terms = Copy(Empty);
     26  Real _.card  = 0;
     27
     28  ////////////////////////////////////////////////////////////////////////////
     29  Text _.autodoc.member.search = "Searchs for an existent term and returns "
     30  "the position in the glossary if exists or 0 if not.";
     31  Real search(Text text)
     32  ////////////////////////////////////////////////////////////////////////////
     33  {
     34    FindIndexByName(_.terms, text)
     35  };
     36  ////////////////////////////////////////////////////////////////////////////
     37  Text _.autodoc.member.findOrAppend = "Searchs for an existent term and "
     38  "returns the position in the glossary if exists or append it to the "
     39  "glossary and returns the cardinal that is the position for the last "
     40  "added element.";
     41  Real findOrAppend(Text text)
     42  ////////////////////////////////////////////////////////////////////////////
     43  {
     44    Real found = search(text);
     45    If(found>0, found,
     46    {
     47      Real c = _.card+1;
     48      Set s = [[c]];
     49      Real PutName(text, s[1]);
     50      Set Append(_.terms,s,True);
     51      Real _.card := _.card+1;
     52      s[1]
     53    })
     54  };
     55  ////////////////////////////////////////////////////////////////////////////
     56  Text _.autodoc.member.New = "Creates a new glossary";
     57  Static @Glossary New(Text name)
     58  ////////////////////////////////////////////////////////////////////////////
     59  {
     60    @Glossary new =
     61    [[
     62      Text _.name = name
     63    ]]
     64  }
     65};
     66
     67//////////////////////////////////////////////////////////////////////////////
     68Text _.autodoc.member.Glossary = "Implements a glossary of unique terms "
     69"that refers to arbitrary objects";
     70Class @Glossary :
     71//////////////////////////////////////////////////////////////////////////////
     72{
     73  Text _.name;
     74  Set  _.terms = Copy(Empty);
     75  Real _.card  = 0;
     76  Anything _.noFound;
     77
     78  ////////////////////////////////////////////////////////////////////////////
     79  Text _.autodoc.member.search = "Searchs for an existent term and returns "
     80  "the position in the glossary if exists or 0 if not.";
     81  Real search(Text text)
     82  ////////////////////////////////////////////////////////////////////////////
     83  {
     84    If(!Card(_.terms), 0, FindIndexByName(_.terms, text))
     85  };
     86  ////////////////////////////////////////////////////////////////////////////
     87  Text _.autodoc.member.searchObj = "Searchs for an existent term and returns "
     88  "it object if exists or _.noFound if not.";
     89  Anything searchObj(Text text)
     90  ////////////////////////////////////////////////////////////////////////////
     91  {
     92    Real idx = find(text);
     93    If(idx, _.terms[idx], _.noFound)
     94  };
     95  ////////////////////////////////////////////////////////////////////////////
     96  Text _.autodoc.member.findOrAppend = "Searchs for an existent term and "
     97  "returns the position in the glossary if exists or append it to the "
     98  "glossary and returns the cardinal that is the position for the last "
     99  "added element.";
     100  Real findOrAppend(Text text, Anything obj)
     101  ////////////////////////////////////////////////////////////////////////////
     102  {
     103    Real found = search(text);
     104    If(found>0, found,
     105    {
     106      Set s = [[obj]];
     107      Real PutName(text, s[1]);
     108      Set Append(_.terms,s,True);
     109      Real _.card := _.card+1;
     110      Copy(_.card)
     111    })
     112  };
     113  ////////////////////////////////////////////////////////////////////////////
     114  Text _.autodoc.member.New = "Creates a new glossary of arbitrary objects";
     115  Static @Glossary New(Text name, Anything noFound)
     116  ////////////////////////////////////////////////////////////////////////////
     117  {
     118    @Glossary new =
     119    [[
     120      Text _.name = name;
     121      Anything _.noFound = noFound
     122    ]]
     123  }
     124};
     125
    18126
    19127//////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.