Changeset 153 for cpp/frams


Ignore:
Timestamp:
03/01/14 22:20:08 (11 years ago)
Author:
sz
Message:

SList container iteration: FOREACH() macro now creates local variable for maintaining the loop, removed the obsolete SList iteration implementation, replaced some unnecessarily complex for() with FOREACH()

Location:
cpp/frams
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/model/model.cpp

    r121 r153  
    135135void Model::clear()
    136136{
    137 Part *p;
    138 for (parts.start();p=(Part*)parts();) delete p;
    139 Joint* j;
    140 for (joints.start();j=(Joint*)joints();) delete j;
    141 Neuro *n;
    142 for (neurons.start();n=(Neuro*)neurons();) delete n;
     137FOREACH(Part*,p,parts)
     138        delete p;
     139FOREACH(Joint*,j,joints)
     140        delete j;
     141FOREACH(Neuro*,n,neurons)
     142        delete n;
    143143parts.clear(); joints.clear(); neurons.clear();
    144144delMap();
  • cpp/frams/util/list.h

    r121 r153  
    8787        {return mem[i];}
    8888bool hasMore() {return pos<size();}
    89 T& operator()() ///< return next element
    90         { return mem[pos++];}
    9189int operator==(const SListTempl<T>& l) const ///< compare list
    9290 {
     
    9795int find(const T& e) const ///< return position of element, or -1 if not found
    9896        { for (int i=0;i<size();i++) if (mem[i]==e) return i;   return -1; }
    99 int start() {return pos=0;} ///< start iteration throgh list
    10097void append(const T& data) ///< add 1 element
    10198        {needSize(size()+1); mem[used++]=data;}
     
    128125        { needSize(s); used=s;}
    129126T& get(int i) const {return operator()(i);}
    130 T& get() {return operator()();}
    131127void clear() {used=0;} ///< remove all elements
    132128void hardclear() {resize(0); used=0;} ///< remove all elements and free mem
     
    148144};
    149145
    150 #define FOREACH(type,var,list) for(type var=(type)list.start();var=(type)list();)
     146#define FOREACH(type,var,list) for(int _ ## var ## _i_=0,_ ## var ## _tmp_=0; _ ## var ## _i_==0;_ ## var ## _i_++) \
     147                for(type var;((_ ## var ## _tmp_=(_ ## var ## _i_<list.size()))?(var=(type)list(_ ## var ## _i_)):0),_ ## var ## _tmp_;_ ## var ## _i_++)
    151148
    152149// usage example: FOREACH(char*,t,thelist) printf("t=%s\n",t);
     
    155152{
    156153   public:
    157 T operator()() ///< return next element
    158      {if (this->pos>=this->size()) return 0; else return
    159 this->mem[this->pos++];}
    160 
    161154T operator()(int i) const ///< return element at position i
    162155     {if (i>=this->size()) return 0; else return this->mem[i];}
    163156
    164157T get(int i) const {return operator()(i);}
    165 T get() {return operator()();}
    166158T& getref(int i) const {return SListTempl<T>::get(i);}
    167 T& getref() {return SListTempl<T>::get();}
    168159};
    169160
  • cpp/frams/vm/classes/collectionobj.cpp

    r127 r153  
    248248        {
    249249        VMVEComparator cmp(jto);
    250         ExtValue **first=(ExtValue**)&data.getref();
     250        ExtValue **first=(ExtValue**)&data.getref(0);
    251251        std::sort(first,first+data.size(),cmp);
    252252        }
     
    255255        {
    256256        VEComparator cmp;
    257         ExtValue **first=(ExtValue**)&data.getref();
     257        ExtValue **first=(ExtValue**)&data.getref(0);
    258258        std::sort(first,first+data.size(),cmp);
    259259        }
Note: See TracChangeset for help on using the changeset viewer.