00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <list>
00041
00042 #ifdef SCV_USE_IOSTREAM_H
00043 # include <iostream.h>
00044 #else
00045 # include <iostream>
00046 #endif
00047
00048
00049
00050 #if defined(__SUNPRO_CC)
00051 # define _SCV_ANGLES()
00052 using std::list;
00053 #else
00054 # define _SCV_ANGLES() <>
00055 #endif
00056
00057
00058
00059
00060
00061 template <class T>
00062 class scv_bag_iter {
00063 typedef typename list<_scv_bag_record<T> >::const_iterator literBRCT ;
00064 typedef typename list<_scv_bag_record<T> >::iterator literBRT ;
00065 private:
00066 literBRT _current;
00067 int _objectCount;
00068 public:
00069
00070 scv_bag_iter() {}
00071
00072 scv_bag_iter(literBRT iter) :
00073 _current(iter), _objectCount(1) {}
00074
00075 scv_bag_iter(const scv_bag_iter& other) :
00076 _current(other._current), _objectCount(other._objectCount) { }
00077
00078
00079 scv_bag_iter& operator=(const scv_bag_iter& other) {
00080 if (this != &other) {
00081 _current = other._current;
00082 _objectCount = other._objectCount;
00083 }
00084 return *this;
00085 }
00086
00087
00088 scv_bag_iter& operator=(const literBRT& other) {
00089 if ((*this)._current != other) {
00090 _current = other;
00091 }
00092 return *this;
00093 }
00094
00095
00096 scv_bag_iter& operator=(int count){
00097 (*this)._objectCount = count;
00098 return *this;
00099 }
00100
00101
00102 _scv_bag_record<T>& operator*() { return (*_current); }
00103
00104 friend bool operator== _SCV_ANGLES()(const scv_bag_iter<T>& first,const scv_bag_iter<T>& second);
00105
00106 scv_bag_iter& operator++() {
00107 if (++_objectCount > (*_current).count()) {
00108 ++_current;
00109 _objectCount = 1;
00110 }
00111 return (*this);
00112 }
00113
00114 scv_bag_iter operator++(int) {
00115 scv_bag_iter tmp = *this;
00116 ++(*this);
00117 return tmp;
00118 }
00119
00120 scv_bag_iter& dInc() {
00121 ++_current;
00122 _objectCount = 1;
00123 return (*this);
00124 }
00125
00126 scv_bag_iter& operator--() {
00127 if (--_objectCount == 0) {
00128 --_current;
00129 _objectCount = (*_current).count();
00130 }
00131 return (*this);
00132 }
00133
00134 scv_bag_iter operator--(int) {
00135 scv_bag_iter tmp = *this;
00136 --(*this);
00137 return tmp;
00138 }
00139
00140 scv_bag_iter& dDec() {
00141 --_current;
00142 _objectCount = (*_current).count();
00143 return (*this);
00144 }
00145
00146
00147 const T* operator->() {
00148 return &(*_current).element();
00149 }
00150
00151 #ifndef _USE_FRIEND_FOR_EQUAL
00152 bool operator==(literBRT& l){
00153 return (*this)._current == l;
00154 }
00155 #else
00156 friend bool operator== _SCV_ANGLES()(const scv_bag_iter<T>& l1, literBRT& l);
00157 #endif
00158
00159 literBRT& current() {return _current; };
00160
00161 int& objCount() {
00162 return _objectCount ;
00163 };
00164
00165 };
00166
00167 #ifdef __linux__
00168 template <class T>
00169 bool operator==(const scv_bag_iter<T> & l1, typename scv_bag_iter<T>::literBRT& l){
00170 return l1._current == l;
00171 }
00172 #endif
00173
00174 template <class T>
00175 bool operator==(const scv_bag_iter<T>& first, const scv_bag_iter<T>& second) {
00176 return (first._current == second._current)
00177 && (first._objectCount == second._objectCount);
00178 }
00179
00180
00181
00182
00183 template <class T>
00184 class scv_bag_const_iter {
00185 typedef typename list<_scv_bag_record<T> >::const_iterator literBRCT ;
00186 typedef typename list<_scv_bag_record<T> >::iterator literBRT ;
00187 private:
00188 literBRCT _current;
00189 int _objectCount;
00190 public:
00191 scv_bag_const_iter() {}
00192 scv_bag_const_iter(literBRCT iter):
00193 _current(iter), _objectCount(1) { }
00194
00195 scv_bag_const_iter(const scv_bag_const_iter& other) :
00196 _current(other._current), _objectCount(other._objectCount) { }
00197
00198
00199
00200 scv_bag_const_iter& operator=(const scv_bag_const_iter& other) {
00201 if (this != &other) {
00202 _current = other._current;
00203 _objectCount = other._objectCount;
00204 }
00205 return *this;
00206 }
00207
00208
00209 scv_bag_const_iter& operator=(const literBRCT& other) {
00210 if ((*this)._current != other) {
00211 _current = other;
00212 }
00213 return *this;
00214 }
00215
00216
00217 scv_bag_const_iter& operator=(int count){
00218 (*this)._objectCount = count;
00219 return *this;
00220 }
00221
00222
00223
00224 const _scv_bag_record<T>& operator*() { return (*_current); }
00225
00226
00227 friend bool operator== _SCV_ANGLES()(const scv_bag_const_iter<T>& first,const scv_bag_const_iter<T>& second);
00228
00229 scv_bag_const_iter& operator++() {
00230 if (++_objectCount > (*_current).count()) {
00231 ++_current;
00232 _objectCount = 1;
00233 }
00234 return (*this);
00235 }
00236
00237 scv_bag_const_iter operator++(int) {
00238 scv_bag_const_iter tmp = *this;
00239 ++(*this);
00240 return tmp;
00241 }
00242
00243
00244 scv_bag_const_iter& dInc() {
00245 ++_current;
00246 _objectCount = 1;
00247 return (*this);
00248 }
00249
00250
00251 scv_bag_const_iter& operator--() {
00252 if (--_objectCount == 0) {
00253 --_current;
00254 _objectCount = (*_current).count();
00255 }
00256 return (*this);
00257 }
00258
00259 scv_bag_const_iter operator--(int) {
00260 scv_bag_const_iter tmp = *this;
00261 --(*this);
00262 return tmp;
00263 }
00264
00265 scv_bag_const_iter& dDec() {
00266 --_current;
00267 _objectCount = (*_current).count();
00268 return (*this);
00269 }
00270
00271
00272 const T* operator->() {
00273 return &(*_current).element();
00274 }
00275
00276
00277 #ifndef _USE_FRIEND_FOR_EQUAL
00278 bool operator==(literBRCT& l){
00279 return (*this)._current == l;
00280 }
00281 #else
00282 friend bool operator== _SCV_ANGLES()(const scv_bag_const_iter<T>& first,literBRCT& second);
00283 #endif
00284
00285 literBRCT& current() { return _current ;}
00286
00287 int& objCount() {
00288 return _objectCount ;
00289 }
00290 };
00291
00292 #ifdef __linux__
00293 template <class T>
00294 bool operator==(const scv_bag_const_iter<T>& first, typename scv_bag_const_iter<T>::literBRCT& second)
00295 {
00296 return first._current == second;
00297 }
00298 #endif
00299
00300 template <class T>
00301 bool operator==(const scv_bag_const_iter<T>& first, const scv_bag_const_iter<T>& second) {
00302 return (first._current == second._current)
00303 && (first._objectCount == second._objectCount);
00304 }
00305
00306
00307
00308
00309 template <class T>
00310 class scv_peek_bag_iter {
00311 typedef typename list<_scv_bag_record<T> >::const_iterator lbrIterCT ;
00312 typedef typename list<_scv_bag_record<T> >::iterator lbrIterT ;
00313 private:
00314
00315
00316
00317
00318 lbrIterT _peek ;
00319 int _mObjectCount, _uObjectCount;
00320 bool _mflag;
00321 public:
00322
00323 scv_peek_bag_iter() {} ;
00324 scv_peek_bag_iter(lbrIterT iter):
00325 _peek(iter), _mObjectCount(0), _uObjectCount(1), _mflag(false) { } ;
00326
00327
00328 scv_peek_bag_iter(const scv_peek_bag_iter& other) :
00329 _peek(other._peek)
00330 , _mObjectCount(other._mObjectCount), _uObjectCount(other._uObjectCount) { }
00331
00332
00333 scv_peek_bag_iter& operator=(const scv_peek_bag_iter& other) {
00334 if (this != &other) {
00335 _peek = other._peek;
00336 _mObjectCount = other._mObjectCount;
00337 _uObjectCount = other._uObjectCount;
00338 _mflag = other._mflag;
00339 }
00340 return *this;
00341 }
00342
00343
00344 scv_peek_bag_iter& operator=(const lbrIterT& other) {
00345 if ((*this)._peek != other) {
00346 _peek = other;
00347 }
00348 return *this;
00349 }
00350
00351
00352
00353 const _scv_bag_record<T>& operator*() { return (*_peek); }
00354
00355
00356
00357
00358
00359
00360
00361 inline void lInitCount() {
00362 _uObjectCount = 0 ;
00363 _mObjectCount = 0 ;
00364 }
00365
00366 inline void mInitCount() {
00367 _mObjectCount = (*_peek).mCount();
00368 _uObjectCount = (*_peek).uCount();
00369 _mflag = ((*_peek).mCount() ? true : false) ;
00370 }
00371
00372
00373
00374 bool incCountAny(){
00375 if (_uObjectCount < (*_peek).uCount()) {
00376 _uObjectCount++ ;
00377 _mflag = false;
00378 return true;
00379 }
00380 if (_mObjectCount < (*_peek).mCount()) {
00381 _mObjectCount++ ;
00382 _mflag = true ;
00383 return true ;
00384 }
00385 return false;
00386 }
00387
00388 scv_peek_bag_iter& operator++() {
00389 if (!incCountAny()) {
00390 ++_peek;
00391 lInitCount();
00392 incCountAny();
00393 }
00394 return (*this);
00395 }
00396
00397
00398 scv_peek_bag_iter operator++(int) {
00399 scv_peek_bag_iter tmp = *this;
00400 ++(*this);
00401 return tmp;
00402 }
00403
00404
00405
00406 scv_peek_bag_iter& dInc() {
00407 ++_peek;
00408 lInitCount();
00409 return (*this);
00410 }
00411
00412
00413 scv_peek_bag_iter& operator--() {
00414 if (_mObjectCount > 0 ) {
00415 --_mObjectCount ;
00416 _mflag = true ;
00417 }
00418 else if (_uObjectCount > 0 ) {
00419 --_uObjectCount ;
00420 _mflag = false ;
00421 }
00422 else {
00423 --_peek;
00424 mInitCount();
00425 } ;
00426 return (*this);
00427 }
00428
00429 scv_peek_bag_iter operator--(int) {
00430 scv_peek_bag_iter tmp = *this;
00431 --(*this);
00432 return tmp;
00433 }
00434
00435 scv_peek_bag_iter& dDec() {
00436 --_peek;
00437 mInitCount();
00438 return (*this);
00439 }
00440
00441
00442 const T* operator->() {
00443 return &(*_peek).element();
00444 }
00445
00446
00447 bool operator==(lbrIterT& l){
00448 return (*this)._peek == l;
00449 }
00450
00451 lbrIterT& modify() { return _peek ; }
00452 lbrIterT& peek() { return _peek ;}
00453
00454 int objCount() {
00455 return _uObjectCount + _mObjectCount ;
00456 }
00457
00458 int& uObjCount() {
00459 return _uObjectCount ;
00460 }
00461
00462 int& mObjCount() {
00463 return _mObjectCount ;
00464 }
00465
00466 bool mflag() {
00467 return _mflag ;
00468 }
00469 };