Changeset 7667:460a67ca7a5a in orange


Ignore:
Timestamp:
02/14/11 13:04:28 (3 years ago)
Author:
markotoplak
Branch:
default
Convert:
e01664d37d27c923de329403d86d85126486c07e
Message:

Replaced allVariables (a list) with allVariablesMap.

Location:
source/orange
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • source/orange/vars.cpp

    r7665 r7667  
    4949#include "vars.ppp" 
    5050 
     51typedef multimap<string, TVariable *> MMV; 
    5152 
    5253DEFINE_TOrangeVector_classDescription(PVariable, "TVarList", true, ORANGE_API) 
    5354DEFINE_TOrangeVector_classDescription(PVarList, "TVarListList", true, ORANGE_API) 
    5455 
    55 list<TVariable *> TVariable::allVariables; 
    56  
     56MMV TVariable::allVariablesMap; 
    5757 
    5858const char *sortedDaNe[] = {"da", "ne", 0 }; 
     
    7979  TStringList::const_iterator vvi, vve; 
    8080 
    81   ITERATE(list<TVariable *>, vi, TVariable::allVariables) { 
    82     if (((*vi)->varType == varType) && ((*vi)->get_name() == name)) { 
     81   pair<MMV::iterator,MMV::iterator> rp = allVariablesMap.equal_range(name); 
     82   MMV::iterator it; 
     83  
     84   for (it=rp.first; it!=rp.second; ++it) { 
     85  
     86     if ((it->second)->varType == varType) { 
     87 
    8388      int tempStat = TVariable::OK; 
    8489 
    8590      // non-discrete attributes are always ok, 
    8691      // discrete ones need further checking if they have any defined values 
    87       TEnumVariable *evar = dynamic_cast<TEnumVariable *>(*vi); 
     92      TEnumVariable *evar = dynamic_cast<TEnumVariable *>(it->second); 
    8893      if (evar && evar->values->size()) { 
    8994 
     
    118123       } 
    119124 
    120       candidates.push_back(make_pair(*vi, tempStat)); 
     125      candidates.push_back(make_pair(it->second, tempStat)); 
    121126      if (tempStat == TVariable::OK) 
    122127        break; 
     
    216221 
    217222 
     223void TVariable::registerVariable() { 
     224  allVariablesMap.insert(pair<string, TVariable *>(name, this)); 
     225} 
     226 
     227void TVariable::removeVariable() { 
     228      pair<MMV::iterator,MMV::iterator> rp = allVariablesMap.equal_range(name); 
     229      MMV::iterator it; 
     230 
     231      for (it=rp.first; it!=rp.second; ++it) { 
     232          if (it->second == this) { 
     233              allVariablesMap.erase(it); 
     234              break; 
     235          } 
     236      } 
     237} 
     238 
     239void TVariable::operator delete(void *t) 
     240{ 
     241    /* When the program shuts down, it may happen that the list is destroyed before 
     242       the variables. We do nothing in this case. */ 
     243    if (allVariablesMap.size()) { 
     244        ((TVariable *)t)->removeVariable(); 
     245    } 
     246       
     247    ::operator delete(t); 
     248} 
     249 
    218250TVariable::TVariable(const int &avarType, const bool &ord) 
    219251: varType(avarType), 
     
    224256  DK_value(varType, valueDK), 
    225257  defaultMetaId(0) 
    226 {} 
     258{ 
     259  registerVariable(); 
     260} 
    227261 
    228262 
     
    235269  DK_value(varType, valueDK), 
    236270  defaultMetaId(0) 
    237 { name = aname; }; 
     271{ name = aname;  
     272  registerVariable(); 
     273}; 
    238274 
    239275 
  • source/orange/vars.hpp

    r7665 r7667  
    2626#include <list> 
    2727#include <set> 
     28#include <map> 
    2829#include "orvector.hpp" 
    2930 
     
    7980  string name; 
    8081 
     82  void registerVariable(); 
     83  void removeVariable(); 
     84 
    8185public: 
    8286 
     
    8791  void set_name(const string &a) { 
    8892    //update the map 
     93    removeVariable(); 
    8994    name = a; 
     95    registerVariable(); 
    9096  } 
    9197 
    92   static list<TVariable *> allVariables; 
    93  
    94   void *operator new(size_t s) throw(bad_alloc) 
    95   { 
    96     void *t = ::operator new(s); 
    97     TVariable::allVariables.push_back((TVariable *)t); 
    98     return t; 
    99   } 
    100  
    101   void operator delete(void *t) 
    102   { 
    103     /* When the program shuts down, it may happen that the list is destroyed before 
    104        the variables. We do nothing in this case. */ 
    105     if (allVariables.size()) 
    106       allVariables.remove((TVariable *)t); 
    107        
    108     ::operator delete(t); 
    109   } 
     98  static multimap<string, TVariable *> allVariablesMap; 
     99 
     100  void operator delete(void *t); 
    110101 
    111102  /* Status codes for getExisting and make. The codes refer to the difference between 
Note: See TracChangeset for help on using the changeset viewer.