Changeset 153 for cpp/frams/util
- Timestamp:
- 03/01/14 22:20:08 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/util/list.h
r121 r153 87 87 {return mem[i];} 88 88 bool hasMore() {return pos<size();} 89 T& operator()() ///< return next element90 { return mem[pos++];}91 89 int operator==(const SListTempl<T>& l) const ///< compare list 92 90 { … … 97 95 int find(const T& e) const ///< return position of element, or -1 if not found 98 96 { for (int i=0;i<size();i++) if (mem[i]==e) return i; return -1; } 99 int start() {return pos=0;} ///< start iteration throgh list100 97 void append(const T& data) ///< add 1 element 101 98 {needSize(size()+1); mem[used++]=data;} … … 128 125 { needSize(s); used=s;} 129 126 T& get(int i) const {return operator()(i);} 130 T& get() {return operator()();}131 127 void clear() {used=0;} ///< remove all elements 132 128 void hardclear() {resize(0); used=0;} ///< remove all elements and free mem … … 148 144 }; 149 145 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_++) 151 148 152 149 // usage example: FOREACH(char*,t,thelist) printf("t=%s\n",t); … … 155 152 { 156 153 public: 157 T operator()() ///< return next element158 {if (this->pos>=this->size()) return 0; else return159 this->mem[this->pos++];}160 161 154 T operator()(int i) const ///< return element at position i 162 155 {if (i>=this->size()) return 0; else return this->mem[i];} 163 156 164 157 T get(int i) const {return operator()(i);} 165 T get() {return operator()();}166 158 T& getref(int i) const {return SListTempl<T>::get(i);} 167 T& getref() {return SListTempl<T>::get();}168 159 }; 169 160
Note: See TracChangeset
for help on using the changeset viewer.