Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Handle_Set_Iterator Class Reference

Iterator for the <ACE_Handle_Set> abstraction. More...

#include <Handle_Set.h>

Collaboration diagram for ACE_Handle_Set_Iterator:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_Handle_Set_Iterator (const ACE_Handle_Set &hs)
 Constructor. More...

 ~ACE_Handle_Set_Iterator (void)
 Default dtor. More...

void reset_state (void)
 Reset the state of the iterator by reinitializing the state that we maintain. More...

ACE_HANDLE operator() (void)
void operator++ (void)
 This is a no-op and no longer does anything. It's only here for backwards compatibility. More...

void dump (void) const
 Dump the state of an object. More...


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...


Private Attributes

const ACE_Handle_Sethandles_
 The <Handle_Set> we are iterating through. More...

u_int handle_index_
int word_num_
 Number of the word we're iterating over (typically between 0..7). More...


Detailed Description

Iterator for the <ACE_Handle_Set> abstraction.

Definition at line 156 of file Handle_Set.h.


Constructor & Destructor Documentation

ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator const ACE_Handle_Set   hs
 

Constructor.

Definition at line 428 of file Handle_Set.cpp.

References ACE_BIT_DISABLED, ACE_DIV_BY_WORDSIZE, ACE_MSB_MASK, ACE_TRACE, handle_index_, handles_, ACE_Handle_Set::mask_, ACE_Handle_Set::max_handle_, word_num_, and ACE_Handle_Set::WORDSIZE.

00429   : handles_ (hs),
00430 #if !defined (ACE_HAS_BIG_FD_SET) || defined (ACE_WIN32)
00431     handle_index_ (0),
00432     word_num_ (-1)
00433 #elif defined (ACE_HAS_BIG_FD_SET)
00434     oldlsb_ (0),
00435     word_max_ (hs.max_handle_ == ACE_INVALID_HANDLE
00436                ? 0
00437                : ((ACE_DIV_BY_WORDSIZE (hs.max_handle_)) + 1))
00438 #endif /* ACE_HAS_BIG_FD_SET */
00439 {
00440   ACE_TRACE ("ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator");
00441 #if !defined (ACE_WIN32) && !defined (ACE_HAS_BIG_FD_SET)
00442   // No sense searching further than the max_handle_ + 1;
00443   ACE_HANDLE maxhandlep1 =
00444     this->handles_.max_handle_ + 1;
00445 
00446   fd_mask *maskp =
00447     (fd_mask *)(this->handles_.mask_.fds_bits);
00448 
00449   // Loop until we've found the first non-zero bit or we run past the
00450   // <maxhandlep1> of the bitset.
00451   while (this->handle_index_ < maxhandlep1
00452          && maskp[++this->word_num_] == 0)
00453     this->handle_index_ += ACE_Handle_Set::WORDSIZE;
00454 
00455   // If the bit index becomes >= the maxhandlep1 that means there
00456   // weren't any bits set.  Therefore, we'll just store the
00457   // maxhandlep1, which will cause <operator()> to return
00458   // <ACE_INVALID_HANDLE> immediately.
00459   if (this->handle_index_ >= maxhandlep1)
00460     this->handle_index_ = maxhandlep1;
00461   else
00462     // Loop until we get <word_val_> to have its least significant bit
00463     // enabled, keeping track of which <handle_index> this represents
00464     // (this information is used by <operator()>).
00465 #  if defined (ACE_PSOS) // bits are in reverse order, MSB (sign bit) = bit 0.
00466     for (this->word_val_ = maskp[this->word_num_];
00467          this->word_val_ > 0;
00468          this->word_val_ = (this->word_val_ << 1))
00469       this->handle_index_++;
00470 #  else
00471     for (this->word_val_ = maskp[this->word_num_];
00472          ACE_BIT_DISABLED (this->word_val_, 1)
00473            && this->handle_index_ < maxhandlep1;
00474          this->handle_index_++)
00475       this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK;
00476 #  endif /* ACE_PSOS */
00477 #elif !defined (ACE_WIN32) && defined (ACE_HAS_BIG_FD_SET)
00478     if (this->word_max_==0)
00479       {
00480         this->word_num_ = -1;
00481         this->word_val_ = 0;
00482       }
00483     else
00484       {
00485         this->word_num_ =
00486           ACE_DIV_BY_WORDSIZE (this->handles_.min_handle_) - 1;
00487         this->word_val_ = 0;
00488       }
00489 #endif /* !ACE_WIN32 && !ACE_HAS_BIG_FD_SET */
00490 }

ACE_INLINE ACE_Handle_Set_Iterator::~ACE_Handle_Set_Iterator void   
 

Default dtor.

Definition at line 166 of file Handle_Set.i.

00167 {
00168 }


Member Function Documentation

void ACE_Handle_Set_Iterator::dump void    const
 

Dump the state of an object.

Definition at line 252 of file Handle_Set.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, and LM_DEBUG.

00253 {
00254   ACE_TRACE ("ACE_Handle_Set_Iterator::dump");
00255 
00256   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00257 #if defined(ACE_WIN32) || !defined(ACE_HAS_BIG_FD_SET)
00258   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nhandle_index_ = %d"), this->handle_index_));
00259 #elif defined(ACE_HAS_BIG_FD_SET)
00260   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nword_max_ = %d"), this->word_max_));
00261   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nword_val_ = %d"), this->word_val_));
00262 #endif
00263   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nword_num_ = %d"), this->word_num_));
00264   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00265 }

ACE_HANDLE ACE_Handle_Set_Iterator::operator() void   
 

"Next" operator. Returns the next unseen <ACE_HANDLE> in the <Handle_Set> up to <handle_set_.max_handle_>). When all the handles have been seen returns <ACE_INVALID_HANDLE>. Advances the iterator automatically, so you need not call <operator++> (which is now obsolete).

Definition at line 268 of file Handle_Set.cpp.

References ACE_BIT_DISABLED, ACE_MSB_MASK, ACE_MULT_BY_WORDSIZE, ACE_TRACE, handle_index_, handles_, ACE_Handle_Set::mask_, ACE_Handle_Set::max_handle_, word_num_, and ACE_Handle_Set::WORDSIZE.

00269 {
00270   ACE_TRACE ("ACE_Handle_Set_Iterator::operator");
00271 #if defined (ACE_WIN32)
00272   if (this->handle_index_ < this->handles_.mask_.fd_count)
00273     // Return the handle and advance the iterator.
00274     return (ACE_HANDLE) this->handles_.mask_.fd_array[this->handle_index_++];
00275   else
00276     return ACE_INVALID_HANDLE;
00277 
00278 #elif !defined (ACE_HAS_BIG_FD_SET) /* !ACE_WIN32 */
00279   // No sense searching further than the max_handle_ + 1;
00280   ACE_HANDLE maxhandlep1 = this->handles_.max_handle_ + 1;
00281 
00282   // HP-UX 11 plays some games with the fd_mask type - fd_mask is
00283   // defined as an int_32t, but the fds_bits is an array of longs.
00284   // This makes plainly indexing through the array by hand tricky,
00285   // since the FD_* macros treat the array as int32_t.  So the bits
00286   // are in the right place for int32_t, even though the array is
00287   // long.  This, they say, is to preserve the same in-memory layout
00288   // for 32-bit and 64-bit processes.  So, we play the same game as
00289   // the FD_* macros to get the bits right.  On all other systems,
00290   // this amounts to practically a NOP, since this is what would have
00291   // been done anyway, without all this type jazz.
00292   fd_mask * maskp = (fd_mask *)(this->handles_.mask_.fds_bits);
00293 
00294   if (this->handle_index_ >= maxhandlep1)
00295     // We've seen all the handles we're interested in seeing for this
00296     // iterator.
00297     return ACE_INVALID_HANDLE;
00298   else
00299     {
00300       ACE_HANDLE result = this->handle_index_;
00301 
00302       // Increment the iterator and advance to the next bit in this
00303       // word.
00304       this->handle_index_++;
00305 #  if defined (ACE_PSOS)
00306       this->word_val_ = (this->word_val_ << 1);
00307 #  else
00308       this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK;
00309 #  endif /* ACE_PSOS */
00310 
00311       // If we've examined all the bits in this word, we'll go onto
00312       // the next word.
00313 
00314       if (this->word_val_ == 0)
00315         {
00316           // Start the handle_index_ at the beginning of the next word
00317           // and then loop until we've found the first non-zero bit or
00318           // we run past the <maxhandlep1> of the bitset.
00319 
00320           for (this->handle_index_ = ACE_MULT_BY_WORDSIZE(++this->word_num_);
00321                this->handle_index_ < maxhandlep1
00322                  && maskp[this->word_num_] == 0;
00323                this->word_num_++)
00324             this->handle_index_ += ACE_Handle_Set::WORDSIZE;
00325 
00326           // If the bit index becomes >= the maxhandlep1 that means
00327           // there weren't any more bits set that we want to consider.
00328           // Therefore, we'll just store the maxhandlep1, which will
00329           // cause <operator()> to return <ACE_INVALID_HANDLE>
00330           // immediately next time it's called.
00331           if (this->handle_index_ >= maxhandlep1)
00332             {
00333               this->handle_index_ = maxhandlep1;
00334               return result;
00335             }
00336           else
00337             // Load the bits of the next word.
00338             this->word_val_ = maskp[this->word_num_];
00339         }
00340 
00341       // Loop until we get <word_val_> to have its least significant
00342       // bit enabled, keeping track of which <handle_index> this
00343       // represents (this information is used by subsequent calls to
00344       // <operator()>).
00345 
00346 #  if defined (ACE_PSOS) // bits are in reverse order, MSB (sign bit) = bit 0.
00347       for (;
00348            this->word_val_ > 0;
00349            this->word_val_ = (this->word_val_ << 1))
00350         this->handle_index_++;
00351 #  else
00352       for (;
00353            ACE_BIT_DISABLED (this->word_val_, 1);
00354            this->handle_index_++)
00355         this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK;
00356 #  endif /* ACE_PSOS */
00357 
00358       return result;
00359     }
00360 #else /* !ACE_HAS_BIG_FD_SET */
00361    // Find the first word in fds_bits with bit on
00362    register u_long lsb = this->word_val_;
00363 
00364    if (lsb == 0)
00365      {
00366        do
00367          {
00368            // We have exceeded the word count in Handle_Set?
00369            if (++this->word_num_ >= this->word_max_)
00370              return ACE_INVALID_HANDLE;
00371 
00372            lsb = this->handles_.mask_.fds_bits[this->word_num_];
00373          }
00374        while (lsb == 0);
00375 
00376        // Set index to word boundary.
00377        this->handle_index_ = ACE_MULT_BY_WORDSIZE(this->word_num_);
00378 
00379        // Put new word_val.
00380        this->word_val_ = lsb;
00381 
00382        // Find the least significative bit.
00383        lsb &= ~(lsb - 1);
00384 
00385        // Remove least significative bit.
00386        this->word_val_ ^= lsb;
00387 
00388        // Save to calculate bit distance.
00389        this->oldlsb_ = lsb;
00390 
00391        // Move index to least significative bit.
00392        while (lsb >>= 1)
00393          this->handle_index_++;
00394      }
00395    else
00396      {
00397         // Find the least significative bit.
00398         lsb &= ~(lsb - 1);
00399 
00400         // Remove least significative bit.
00401         this->word_val_ ^= lsb;
00402 
00403         register u_long n = lsb - this->oldlsb_;
00404 
00405         // Move index to bit distance between new lsb and old lsb.
00406         do
00407           {
00408             this->handle_index_++;
00409             n &= n >> 1;
00410           }
00411         while (n != 0);
00412 
00413         this->oldlsb_ = lsb;
00414       }
00415 
00416    return this->handle_index_;
00417 #endif /* ACE_WIN32 */
00418 }

void ACE_Handle_Set_Iterator::operator++ void   
 

This is a no-op and no longer does anything. It's only here for backwards compatibility.

Definition at line 421 of file Handle_Set.cpp.

References ACE_TRACE.

00422 {
00423   ACE_TRACE ("ACE_Handle_Set_Iterator::operator++");
00424 
00425   // This is now a no-op.
00426 }

void ACE_Handle_Set_Iterator::reset_state void   
 

Reset the state of the iterator by reinitializing the state that we maintain.

Definition at line 494 of file Handle_Set.cpp.

References ACE_BIT_DISABLED, ACE_DIV_BY_WORDSIZE, ACE_MSB_MASK, ACE_TRACE, handle_index_, handles_, ACE_Handle_Set::mask_, ACE_Handle_Set::max_handle_, word_num_, and ACE_Handle_Set::WORDSIZE.

00495 {
00496   ACE_TRACE ("ACE_Handle_Set_Iterator::reset_state");
00497 
00498 #if !defined (ACE_HAS_BIG_FD_SET) || defined (ACE_WIN32)
00499   this->handle_index_  = 0;
00500   this->word_num_ = -1;
00501 #elif defined (ACE_HAS_BIG_FD_SET)
00502   this->oldlsb_ = 0;
00503   this->word_max_  =
00504     this->handles_.max_handle_ == ACE_INVALID_HANDLE  ? 0
00505     : ((ACE_DIV_BY_WORDSIZE (this->handles_.max_handle_)) + 1);
00506 #endif /* ACE_HAS_BIG_FD_SET */
00507 
00508 #if !defined (ACE_WIN32) && !defined (ACE_HAS_BIG_FD_SET)
00509   // No sense searching further than the max_handle_ + 1;
00510   ACE_HANDLE maxhandlep1 =
00511     this->handles_.max_handle_ + 1;
00512 
00513   fd_mask *maskp =
00514     (fd_mask *)(this->handles_.mask_.fds_bits);
00515 
00516   // Loop until we've found the first non-zero bit or we run past the
00517   // <maxhandlep1> of the bitset.
00518   while (this->handle_index_ < maxhandlep1
00519          && maskp[++this->word_num_] == 0)
00520     this->handle_index_ += ACE_Handle_Set::WORDSIZE;
00521 
00522   // If the bit index becomes >= the maxhandlep1 that means there
00523   // weren't any bits set.  Therefore, we'll just store the
00524   // maxhandlep1, which will cause <operator()> to return
00525   // <ACE_INVALID_HANDLE> immediately.
00526   if (this->handle_index_ >= maxhandlep1)
00527     this->handle_index_ = maxhandlep1;
00528   else
00529     // Loop until we get <word_val_> to have its least significant bit
00530     // enabled, keeping track of which <handle_index> this represents
00531     // (this information is used by <operator()>).
00532 #  if defined (ACE_PSOS) // bits are in reverse order, MSB (sign bit) = bit 0.
00533     for (this->word_val_ = maskp[this->word_num_];
00534          this->word_val_ > 0;
00535          this->word_val_ = (this->word_val_ << 1))
00536       this->handle_index_++;
00537 #  else
00538     for (this->word_val_ = maskp[this->word_num_];
00539          ACE_BIT_DISABLED (this->word_val_, 1)
00540            && this->handle_index_ < maxhandlep1;
00541          this->handle_index_++)
00542       this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK;
00543 #  endif /* ACE_PSOS */
00544 #elif !defined (ACE_WIN32) && defined (ACE_HAS_BIG_FD_SET)
00545     if (this->word_max_==0)
00546       {
00547         this->word_num_ = -1;
00548         this->word_val_ = 0;
00549       }
00550     else
00551       {
00552         this->word_num_ =
00553           ACE_DIV_BY_WORDSIZE (this->handles_.min_handle_) - 1;
00554         this->word_val_ = 0;
00555       }
00556 #endif /* !ACE_WIN32 && !ACE_HAS_BIG_FD_SET */
00557 }


Member Data Documentation

ACE_Handle_Set_Iterator::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 186 of file Handle_Set.h.

u_int ACE_Handle_Set_Iterator::handle_index_ [private]
 

Definition at line 193 of file Handle_Set.h.

Referenced by ACE_Handle_Set_Iterator, operator(), and reset_state.

const ACE_Handle_Set& ACE_Handle_Set_Iterator::handles_ [private]
 

The <Handle_Set> we are iterating through.

Definition at line 190 of file Handle_Set.h.

Referenced by ACE_Handle_Set_Iterator, operator(), and reset_state.

int ACE_Handle_Set_Iterator::word_num_ [private]
 

Number of the word we're iterating over (typically between 0..7).

Definition at line 203 of file Handle_Set.h.

Referenced by ACE_Handle_Set_Iterator, operator(), and reset_state.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:48:19 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002