Changeset 101927 in vbox
- Timestamp:
- Nov 7, 2023 11:00:14 AM (15 months ago)
- Location:
- trunk/src/libs/xpcom18a4
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/ipc/ipcd/extensions/dconnect/src/ipcDConnectService.cpp
r101924 r101927 1525 1525 , mPeerID(aPeerID) 1526 1526 , mCachedISupports(0) 1527 , mRefCntLevels( 0)1527 , mRefCntLevels() 1528 1528 {} 1529 1529 -
trunk/src/libs/xpcom18a4/xpcom/ds/nsDeque.cpp
r58038 r101927 78 78 /** 79 79 * Standard constructor 80 * @param deallocator, called by Erase and ~nsDeque 81 */ 82 nsDeque::nsDeque(nsDequeFunctor* aDeallocator) { 80 */ 81 nsDeque::nsDeque() { 83 82 MOZ_COUNT_CTOR(nsDeque); 84 mDeallocator=aDeallocator;85 83 mOrigin=mSize=0; 86 84 mData=mBuffer; // don't allocate space until you must … … 95 93 MOZ_COUNT_DTOR(nsDeque); 96 94 97 #ifdef DEBUG_rickg98 char buffer[30];99 printf("Capacity: %i\n", mCapacity);100 101 static int mCaps[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};102 switch(mCapacity) {103 case 4: mCaps[0]++; break;104 case 8: mCaps[1]++; break;105 case 16: mCaps[2]++; break;106 case 32: mCaps[3]++; break;107 case 64: mCaps[4]++; break;108 case 128: mCaps[5]++; break;109 case 256: mCaps[6]++; break;110 case 512: mCaps[7]++; break;111 case 1024: mCaps[8]++; break;112 case 2048: mCaps[9]++; break;113 case 4096: mCaps[10]++; break;114 default:115 break;116 }117 #endif118 119 95 Erase(); 120 96 if (mData && (mData!=mBuffer)) { … … 122 98 } 123 99 mData=0; 124 SetDeallocator(0);125 }126 127 /**128 * Set the functor to be called by Erase()129 * The deque owns the functor.130 *131 * @param aDeallocator functor object for use by Erase()132 */133 void nsDeque::SetDeallocator(nsDequeFunctor* aDeallocator){134 if (mDeallocator) {135 delete mDeallocator;136 }137 mDeallocator=aDeallocator;138 100 } 139 101 … … 158 120 */ 159 121 nsDeque& nsDeque::Erase() { 160 if (mDeallocator && mSize) {161 ForEach(*mDeallocator);162 }163 122 return Empty(); 164 123 } … … 358 317 } 359 318 360 /**361 * Create and return an iterator pointing to362 * the beginning of the queue. Note that this363 * takes the circular buffer semantics into account.364 *365 * @return new deque iterator, init'ed to 1st item366 */367 nsDequeIterator nsDeque::Begin() const{368 return nsDequeIterator(*this, 0);369 }370 371 /**372 * Create and return an iterator pointing to373 * the last item in the deque.374 * Note that this takes the circular buffer semantics375 * into account.376 *377 * @return new deque iterator, init'ed to the last item378 */379 nsDequeIterator nsDeque::End() const{380 return nsDequeIterator(*this, mSize - 1);381 }382 383 void* nsDeque::Last() const {384 return End().GetCurrent();385 }386 387 /**388 * Call this method when you want to iterate all the389 * members of the container, passing a functor along390 * to call your code.391 *392 * @param aFunctor object to call for each member393 * @return *this394 */395 void nsDeque::ForEach(nsDequeFunctor& aFunctor) const{396 for (PRInt32 i=0; i<mSize; i++) {397 aFunctor(ObjectAt(i));398 }399 }400 401 /**402 * Call this method when you want to iterate all the403 * members of the container, calling the functor you404 * passed with each member. This process will interrupt405 * if your function returns non 0 to this method.406 *407 * @param aFunctor object to call for each member408 * @return first nonzero result of aFunctor or 0.409 */410 const void* nsDeque::FirstThat(nsDequeFunctor& aFunctor) const{411 for (PRInt32 i=0; i<mSize; i++) {412 void* obj=aFunctor(ObjectAt(i));413 if (obj) {414 return obj;415 }416 }417 return 0;418 }419 420 /******************************************************421 * Here comes the nsDequeIterator class...422 ******************************************************/423 424 /**425 * DequeIterator is an object that knows how to iterate (forward and backward)426 * through a Deque. Normally, you don't need to do this, but there are some special427 * cases where it is pretty handy, so here you go.428 *429 * This is a standard dequeiterator constructor430 *431 * @param aQueue is the deque object to be iterated432 * @param aIndex is the starting position for your iteration433 */434 nsDequeIterator::nsDequeIterator(const nsDeque& aQueue, int aIndex)435 : mIndex(aIndex),436 mDeque(aQueue)437 {438 }439 440 /**441 * Create a copy of a DequeIterator442 *443 * @param aCopy is another iterator to copy from444 */445 nsDequeIterator::nsDequeIterator(const nsDequeIterator& aCopy)446 : mIndex(aCopy.mIndex),447 mDeque(aCopy.mDeque)448 {449 }450 451 /**452 * Moves iterator to first element in deque453 * @return *this454 */455 nsDequeIterator& nsDequeIterator::First(){456 mIndex=0;457 return *this;458 }459 460 /**461 * Standard assignment operator for dequeiterator462 *463 * @param aCopy is an iterator to be copied from464 * @return *this465 */466 nsDequeIterator& nsDequeIterator::operator=(const nsDequeIterator& aCopy) {467 NS_ASSERTION(&mDeque==&aCopy.mDeque,"you can't change the deque that an interator is iterating over, sorry.");468 mIndex=aCopy.mIndex;469 return *this;470 }471 472 /**473 * preform ! operation against to iterators to test for equivalence474 * (or lack thereof)!475 *476 * @param aIter is the object to be compared to477 * @return TRUE if NOT equal.478 */479 PRBool nsDequeIterator::operator!=(nsDequeIterator& aIter) {480 return PRBool(!this->operator==(aIter));481 }482 483 /**484 * Compare two iterators for increasing order.485 *486 * @param aIter is the other iterator to be compared to487 * @return TRUE if this object points to an element before488 * the element pointed to by aIter.489 * FALSE if this and aIter are not iterating over the same deque.490 */491 PRBool nsDequeIterator::operator<(nsDequeIterator& aIter) {492 return PRBool(((mIndex<aIter.mIndex) && (&mDeque==&aIter.mDeque)));493 }494 495 /**496 * Compare two iterators for equivalence.497 *498 * @param aIter is the other iterator to be compared to499 * @return TRUE if EQUAL500 */501 PRBool nsDequeIterator::operator==(nsDequeIterator& aIter) {502 return PRBool(((mIndex==aIter.mIndex) && (&mDeque==&aIter.mDeque)));503 }504 505 /**506 * Compare two iterators for non strict decreasing order.507 *508 * @param aIter is the other iterator to be compared to509 * @return TRUE if this object points to the same element, or510 * an element after the element pointed to by aIter.511 * FALSE if this and aIter are not iterating over the same deque.512 */513 PRBool nsDequeIterator::operator>=(nsDequeIterator& aIter) {514 return PRBool(((mIndex>=aIter.mIndex) && (&mDeque==&aIter.mDeque)));515 }516 517 /**518 * Pre-increment operator519 *520 * @return object at post-incremented index521 */522 void* nsDequeIterator::operator++() {523 NS_ASSERTION(mIndex<mDeque.mSize,524 "You have reached the end of the Internet."\525 "You have seen everything there is to see. Please go back. Now."526 );527 #ifndef TIMELESS_LIGHTWEIGHT528 if (mIndex>=mDeque.mSize) return 0;529 #endif530 return mDeque.ObjectAt(++mIndex);531 }532 533 /**534 * Post-increment operator535 *536 * @param param is ignored537 * @return object at pre-incremented index538 */539 void* nsDequeIterator::operator++(int) {540 NS_ASSERTION(mIndex<=mDeque.mSize,541 "You have already reached the end of the Internet."\542 "You have seen everything there is to see. Please go back. Now."543 );544 #ifndef TIMELESS_LIGHTWEIGHT545 if (mIndex>mDeque.mSize) return 0;546 #endif547 return mDeque.ObjectAt(mIndex++);548 }549 550 /**551 * Pre-decrement operator552 *553 * @return object at pre-decremented index554 */555 void* nsDequeIterator::operator--() {556 NS_ASSERTION(mIndex>=0,557 "You have reached the beginning of the Internet."\558 "You have seen everything there is to see. Please go forward. Now."559 );560 #ifndef TIMELESS_LIGHTWEIGHT561 if (mIndex<0) return 0;562 #endif563 return mDeque.ObjectAt(--mIndex);564 }565 566 /**567 * Post-decrement operator568 *569 * @param param is ignored570 * @return object at post-decremented index571 */572 void* nsDequeIterator::operator--(int) {573 NS_ASSERTION(mIndex>=0,574 "You have already reached the beginning of the Internet."\575 "You have seen everything there is to see. Please go forward. Now."576 );577 #ifndef TIMELESS_LIGHTWEIGHT578 if (mIndex<0) return 0;579 #endif580 return mDeque.ObjectAt(mIndex--);581 }582 583 /**584 * Dereference operator585 * Note that the iterator floats, so you don't need to do:586 * <code>++iter; aDeque.PopFront();</code>587 * Unless you actually want your iterator to jump 2 spaces.588 *589 * Picture: [1 2I 3 4]590 * PopFront()591 * Picture: [2 3I 4]592 * Note that I still happily points to object at the second index593 *594 * @return object at ith index595 */596 void* nsDequeIterator::GetCurrent() {597 NS_ASSERTION(mIndex<mDeque.mSize&&mIndex>=0,"Current is out of bounds");598 #ifndef TIMELESS_LIGHTWEIGHT599 if (mIndex>=mDeque.mSize||mIndex<0) return 0;600 #endif601 return mDeque.ObjectAt(mIndex);602 }603 604 /**605 * Call this method when you want to iterate all the606 * members of the container, passing a functor along607 * to call your code.608 *609 * @param aFunctor object to call for each member610 * @return *this611 */612 void nsDequeIterator::ForEach(nsDequeFunctor& aFunctor) const{613 mDeque.ForEach(aFunctor);614 }615 616 /**617 * Call this method when you want to iterate all the618 * members of the container, calling the functor you619 * passed with each member. This process will interrupt620 * if your function returns non 0 to this method.621 *622 * @param aFunctor object to call for each member623 * @return first nonzero result of aFunctor or 0.624 */625 const void* nsDequeIterator::FirstThat(nsDequeFunctor& aFunctor) const{626 return mDeque.FirstThat(aFunctor);627 } -
trunk/src/libs/xpcom18a4/xpcom/ds/nsDeque.h
r62266 r101927 59 59 #include "nscore.h" 60 60 61 /**62 * The nsDequeFunctor class is used when you want to create63 * callbacks between the deque and your generic code.64 * Use these objects in a call to ForEach();65 *66 */67 68 class nsDequeFunctor{69 public:70 virtual void* operator()(void* anObject)=0;71 };72 73 61 /****************************************************** 74 62 * Here comes the nsDeque class itself... … … 84 72 * The deque stores pointers to items. 85 73 */ 86 87 class nsDequeIterator;88 89 74 class NS_COM nsDeque { 90 friend class nsDequeIterator;91 75 public: 92 nsDeque( nsDequeFunctor* aDeallocator);76 nsDeque(); 93 77 ~nsDeque(); 94 78 … … 169 153 nsDeque& Erase(); 170 154 171 /**172 * Creates a new iterator, pointing to the first173 * item in the deque.174 *175 * @return new dequeIterator176 */177 nsDequeIterator Begin() const;178 179 /**180 * Creates a new iterator, pointing to the last181 * item in the deque.182 *183 * @return new dequeIterator184 */185 nsDequeIterator End() const;186 187 void* Last() const;188 /**189 * Call this method when you want to iterate all the190 * members of the container, passing a functor along191 * to call your code.192 *193 * @param aFunctor object to call for each member194 * @return *this195 */196 void ForEach(nsDequeFunctor& aFunctor) const;197 198 /**199 * Call this method when you want to iterate all the200 * members of the container, calling the functor you201 * passed with each member. This process will interrupt202 * if your function returns non 0 to this method.203 *204 * @param aFunctor object to call for each member205 * @return first nonzero result of aFunctor or 0.206 */207 const void* FirstThat(nsDequeFunctor& aFunctor) const;208 209 void SetDeallocator(nsDequeFunctor* aDeallocator);210 211 155 protected: 212 156 PRInt32 mSize; 213 157 PRInt32 mCapacity; 214 158 PRInt32 mOrigin; 215 nsDequeFunctor* mDeallocator;216 159 void* mBuffer[8]; 217 160 void** mData; 218 161 219 162 private: 220 221 /**222 * Simple default constructor (PRIVATE)223 */224 nsDeque();225 163 226 164 /** … … 242 180 }; 243 181 244 /******************************************************245 * Here comes the nsDequeIterator class...246 ******************************************************/247 248 class nsDequeIterator {249 public:250 /**251 * DequeIterator is an object that knows how to iterate252 * (forward and backward) through a Deque. Normally,253 * you don't need to do this, but there are some special254 * cases where it is pretty handy.255 *256 * One warning: the iterator is not bound to an item,257 * it is bound to an index, so if you insert or remove258 * from the beginning while using an iterator259 * (which is not recommended) then the iterator will260 * point to a different item. @see GetCurrent()261 *262 * Here you go.263 *264 * @param aQueue is the deque object to be iterated265 * @param aIndex is the starting position for your iteration266 */267 nsDequeIterator(const nsDeque& aQueue, int aIndex=0);268 269 /**270 * Create a copy of a DequeIterator271 *272 * @param aCopy is another iterator to copy from273 */274 nsDequeIterator(const nsDequeIterator& aCopy);275 276 /**277 * Moves iterator to first element in the deque278 * @return *this279 */280 nsDequeIterator& First();281 282 /**283 * Standard assignment operator for dequeiterator284 * @param aCopy is another iterator to copy from285 * @return *this286 */287 nsDequeIterator& operator=(const nsDequeIterator& aCopy);288 289 /**290 * preform ! operation against two iterators to test for equivalence291 * (or lack thereof)!292 *293 * @param aIter is the object to be compared to294 * @return TRUE if NOT equal.295 */296 PRBool operator!=(nsDequeIterator& aIter);297 298 /**299 * Compare two iterators for increasing order.300 *301 * @param aIter is the other iterator to be compared to302 * @return TRUE if this object points to an element before303 * the element pointed to by aIter.304 * FALSE if this and aIter are not iterating over305 * the same deque.306 */307 PRBool operator<(nsDequeIterator& aIter);308 309 /**310 * Compare two iterators for equivalence.311 *312 * @param aIter is the other iterator to be compared to313 * @return TRUE if EQUAL314 */315 PRBool operator==(nsDequeIterator& aIter);316 317 /**318 * Compare two iterators for non strict decreasing order.319 *320 * @param aIter is the other iterator to be compared to321 * @return TRUE if this object points to the same element, or322 * an element after the element pointed to by aIter.323 * FALSE if this and aIter are not iterating over324 * the same deque.325 */326 PRBool operator>=(nsDequeIterator& aIter);327 328 /**329 * Pre-increment operator330 * Iterator will advance one index towards the end.331 *332 * @return object_at(++index)333 */334 void* operator++();335 336 /**337 * Post-increment operator338 * Iterator will advance one index towards the end.339 *340 * @param param is ignored341 * @return object_at(mIndex++)342 */343 void* operator++(int);344 345 /**346 * Pre-decrement operator347 * Iterator will advance one index towards the beginning.348 *349 * @return object_at(--index)350 */351 void* operator--();352 353 /**354 * Post-decrement operator355 * Iterator will advance one index towards the beginning.356 *357 * @param param is ignored358 * @return object_at(index--)359 */360 void* operator--(int);361 362 /**363 * Retrieve the the iterator's notion of current node.364 *365 * Note that the iterator floats, so you don't need to do:366 * <code>++iter; aDeque.PopFront();</code>367 * Unless you actually want your iterator to jump 2 positions368 * relative to its origin.369 *370 * Picture: [1 2i 3 4]371 * PopFront()372 * Picture: [2 3i 4]373 * Note that I still happily points to object at the second index.374 *375 * @return object at i'th index376 */377 void* GetCurrent();378 379 /**380 * Call this method when you want to iterate all the381 * members of the container, passing a functor along382 * to call your code.383 *384 * @param aFunctor object to call for each member385 * @return *this386 */387 void ForEach(nsDequeFunctor& aFunctor) const;388 389 /**390 * Call this method when you want to iterate all the391 * members of the container, calling the functor you392 * passed with each member. This process will interrupt393 * if your function returns non 0 to this method.394 *395 * @param aFunctor object to call for each member396 * @return first nonzero result of aFunctor or 0.397 */398 const void* FirstThat(nsDequeFunctor& aFunctor) const;399 400 protected:401 402 PRInt32 mIndex;403 const nsDeque& mDeque;404 };405 182 #endif -
trunk/src/libs/xpcom18a4/xpcom/tests/TestDeque.cpp
r1 r101927 40 40 #include <stdio.h> 41 41 42 /**************************************************************43 Now define the token deallocator class...44 **************************************************************/45 42 class _TestDeque { 46 43 public: … … 54 51 }; 55 52 static _TestDeque sTestDeque; 56 57 class _Dealloc: public nsDequeFunctor {58 virtual void* operator()(void* aObject) {59 return 0;60 }61 };62 53 63 54 /** … … 81 72 int i=0; 82 73 int* temp; 83 nsDeque theDeque (new _Dealloc); //construct a simple one...74 nsDeque theDeque; //construct a simple one... 84 75 85 76 for (i=0;i<count;i++) { //initialize'em … … 111 102 int i=0; 112 103 int* temp; 113 nsDeque secondDeque (new _Dealloc);104 nsDeque secondDeque; 114 105 /** 115 106 * Test 1. Origin near end, semi full, call Peek(). … … 146 137 147 138 nsresult _TestDeque::AssignFlaw() { 148 nsDeque src (new _Dealloc),dest(new _Dealloc);139 nsDeque src, dest; 149 140 return NS_OK; 150 141 }
Note:
See TracChangeset
for help on using the changeset viewer.