Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

_scv_list_iter.h

Go to the documentation of this file.
00001 //  -*- C++ -*- <this line is for emacs to recognize it as C++ code>
00002 /*****************************************************************************
00003 
00004   The following code is derived, directly or indirectly, from the SystemC
00005   source code Copyright (c) 1996-2002 by all Contributors.
00006   All Rights reserved.
00007 
00008   The contents of this file are subject to the restrictions and limitations
00009   set forth in the SystemC Open Source License Version 2.3 (the "License");
00010   You may not use this file except in compliance with such restrictions and
00011   limitations. You may obtain instructions on how to receive a copy of the
00012   License at http://www.systemc.org/. Software distributed by Contributors
00013   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00014   ANY KIND, either express or implied. See the License for the specific
00015   language governing rights and limitations under the License.
00016 
00017  *****************************************************************************/
00018 
00019 /*****************************************************************************
00020 
00021   _scv_list_iter.h -- 
00022 
00023   Original Authors (Cadence Design Systems, Inc):
00024   Norris Ip, Dean Shea, John Rose, Jasvinder Singh, William Paulsen,
00025   John Pierce, Rachida Kebichi, Ted Elkind, David Bailey
00026   2002-09-23
00027 
00028  *****************************************************************************/
00029 
00030 /*****************************************************************************
00031 
00032   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00033   changes you are making here.
00034 
00035       Name, Affiliation, Date:
00036   Description of Modification:
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 // The following accommodates differences between compilers concerning
00049 // declaration of friend functions in template classes.
00050 #if defined(__SUNPRO_CC)
00051 # define _SCV_ANGLES()
00052   using std::list;
00053 #else
00054 # define _SCV_ANGLES() <>
00055 #endif
00056 
00057 //
00058 // scv_bag_iter class: STL-like iteratorT class to iterate on the bag 
00059 // elements. Used by scv_bag. Should not be used directly.
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; // Keeps track of no. of object copies.
00068 public:
00069   // Constructors...
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   // Assign listIterator to BagIterator leaving the count field untouched
00088   scv_bag_iter& operator=(const literBRT& other) { 
00089     if ((*this)._current != other) { 
00090       _current = other;
00091     } 
00092     return *this;
00093   } 
00094 
00095   //Assign count field to BagIterator
00096   scv_bag_iter&  operator=(int count){
00097     (*this)._objectCount = count;
00098     return *this;
00099   }
00100 
00101   // Dereference
00102   _scv_bag_record<T>& operator*() { return (*_current); } 
00103   // Test for equality
00104   friend bool operator== _SCV_ANGLES()(const scv_bag_iter<T>& first,const scv_bag_iter<T>& second);
00105   // prefix ++
00106   scv_bag_iter& operator++() { 
00107     if (++_objectCount > (*_current).count()) {  //should advance
00108       ++_current;
00109       _objectCount = 1;
00110     } 
00111     return (*this);
00112   }
00113   // postfix ++
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) {  //should decrement main iteratorT
00128       --_current;
00129       _objectCount = (*_current).count();
00130     } 
00131     return (*this);
00132   }
00133   // postfix ++
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   // pointer dereference
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 // Const version of the above....
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   // Assign list const_iterator to Bag const iterator leaving count unassigned
00209   scv_bag_const_iter& operator=(const literBRCT& other) { 
00210     if ((*this)._current != other) { 
00211       _current = other;
00212     } 
00213     return *this;
00214   } 
00215 
00216   // Assign an integerto objectCount leave the const_iterator untouched
00217   scv_bag_const_iter&  operator=(int count){
00218     (*this)._objectCount = count;
00219     return *this;
00220   }
00221 
00222 
00223   // Dereference
00224   const _scv_bag_record<T>& operator*() { return (*_current); } 
00225 
00226   // Test for equality
00227   friend bool operator== _SCV_ANGLES()(const scv_bag_const_iter<T>& first,const scv_bag_const_iter<T>& second);
00228   // prefix ++
00229   scv_bag_const_iter& operator++() { 
00230     if (++_objectCount > (*_current).count()) {  //should advance
00231       ++_current;
00232       _objectCount = 1;
00233     } 
00234     return (*this);
00235   }
00236   // postfix ++
00237   scv_bag_const_iter operator++(int) { 
00238     scv_bag_const_iter tmp = *this;
00239     ++(*this);
00240     return tmp;
00241   }
00242 
00243   // Distinct increment
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) {  //should decrement main iteratorT
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   // pointer dereference
00272   const T* operator->() { 
00273     return &(*_current).element();
00274   } 
00275 
00276   // compare list constant iterator with bag constant iterator
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 // Peek Iterator
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   /*  lbrIterCT& _peek;
00315   lbrIterT& _modify;
00316   literBRCT _lpeek;
00317   literBRT _lmodify; */
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   // Assign list const_iterator to Bag const iterator leaving count unassigned
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   // Dereference
00353   const _scv_bag_record<T>& operator*() { return (*_peek); } 
00354   /*
00355   // Test for equality
00356   friend bool operator== _SCV_ANGLES()(const scv_peek_bag_iter<T>& first,const scv_peek_bag_iter<T>& second);
00357   */ //commented by dsb Apr 05, 2000 As it is not used and seems to be giving
00358   //  hp 2.95 compile problems
00359   // init counters during increment and decrement
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   // prefix ++
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()) {  //should advance
00390       ++_peek;
00391       lInitCount();
00392       incCountAny();
00393     }
00394     return (*this);
00395   }
00396 
00397   // postfix ++
00398   scv_peek_bag_iter operator++(int) { 
00399     scv_peek_bag_iter tmp = *this;
00400     ++(*this);
00401     return tmp;
00402   }
00403 
00404   // Distinct increment
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 {  //should decrement main iteratorT
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   // pointer dereference
00442   const T* operator->() { 
00443     return &(*_peek).element();
00444   } 
00445 
00446   // compare list iterator with bag peek iterator
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 };

Generated on Fri Jan 14 08:28:56 2005 for SystemC2.1beta11(excludingMSLib)(IncludingSCV)\nProvidedby:www.openverificationfoundation.org by doxygen1.2.18