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 Member Functions

 ACE_Handle_Set_Iterator (const ACE_Handle_Set &hs)
 Constructor.

 ~ACE_Handle_Set_Iterator (void)
 Default dtor.

void reset_state (void)
ACE_HANDLE operator() (void)
void operator++ (void)
void dump (void) const
 Dump the state of an object.


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


Private Attributes

const ACE_Handle_Sethandles_
 The we are iterating through.

u_int handle_index_
 Index of the bit we're examining in the current word.

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


Detailed Description

Iterator for the ACE_Handle_Set abstraction.

Definition at line 176 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 445 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_, and word_num_.

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

ACE_INLINE ACE_Handle_Set_Iterator::~ACE_Handle_Set_Iterator void   ) 
 

Default dtor.

Definition at line 186 of file Handle_Set.inl.

00187 {
00188 }


Member Function Documentation

void ACE_Handle_Set_Iterator::dump void   )  const
 

Dump the state of an object.

Definition at line 265 of file Handle_Set.cpp.

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

00266 {
00267 #if defined (ACE_HAS_DUMP)
00268   ACE_TRACE ("ACE_Handle_Set_Iterator::dump");
00269 
00270   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00271 #if defined(ACE_WIN32) || !defined(ACE_HAS_BIG_FD_SET)
00272   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nhandle_index_ = %d"), this->handle_index_));
00273 #elif defined(ACE_HAS_BIG_FD_SET)
00274   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nword_max_ = %d"), this->word_max_));
00275   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nword_val_ = %d"), this->word_val_));
00276 #endif
00277   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nword_num_ = %d"), this->word_num_));
00278   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00279 #endif /* ACE_HAS_DUMP */
00280 }

ACE_HANDLE ACE_Handle_Set_Iterator::operator() void   ) 
 

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

Definition at line 283 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_, and word_num_.

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

void ACE_Handle_Set_Iterator::operator++ void   ) 
 

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

Deprecated:

Definition at line 438 of file Handle_Set.cpp.

References ACE_TRACE.

00439 {
00440   ACE_TRACE ("ACE_Handle_Set_Iterator::operator++");
00441 
00442   // This is now a no-op.
00443 }

void ACE_Handle_Set_Iterator::reset_state void   ) 
 

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

Definition at line 512 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_, and word_num_.

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


Member Data Documentation

ACE_Handle_Set_Iterator::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 207 of file Handle_Set.h.

u_int ACE_Handle_Set_Iterator::handle_index_ [private]
 

Index of the bit we're examining in the current word.

Definition at line 215 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 we are iterating through.

Definition at line 211 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 224 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 Thu Nov 9 11:22:42 2006 for ACE by doxygen 1.3.6