[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / Handle_Set.inl
blob7e669d4fd2d812252d9b8960726a9fac2ea98611
1 // -*- C++ -*-
2 //
3 // $Id: Handle_Set.inl 80826 2008-03-04 14:51:23Z wotte $
5 #include "ace/Log_Msg.h"
7 // todo: This should be cleaned up a bit.
8 // memset for FD_ZERO on OpenBSD and Solaris w/ gcc 2.95.3
9 #include "ace/os_include/os_string.h"
11 // FreeBSD 4.8-RC? for bzero() used by FD_ZERO
12 #include "ace/os_include/os_strings.h"
14 // IRIX5 defines bzero() in this odd file... used by FD_ZERO
15 #if defined (ACE_HAS_BSTRING)
16 #  include /**/ <bstring.h>
17 #endif /* ACE_HAS_BSTRING */
19 // AIX defines bzero() in this odd file... used by FD_ZERO
20 #if defined (ACE_HAS_STRINGS)
21 #  include "ace/os_include/os_strings.h"
22 #endif /* ACE_HAS_STRINGS */
24 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
26 // Initialize the bitmask to all 0s and reset the associated fields.
28 ACE_INLINE void
29 ACE_Handle_Set::reset (void)
31   ACE_TRACE ("ACE_Handle_Set::reset");
32   this->max_handle_ =
33     ACE_INVALID_HANDLE;
34 #if defined (ACE_HAS_BIG_FD_SET)
35   this->min_handle_ =
36     NUM_WORDS * WORDSIZE;
37 #endif /* ACE_HAS_BIG_FD_SET */
38   this->size_ = 0;
39   // #if !defined (ACE_HAS_BIG_FD_SET)      Why is this here?  -Steve Huston
40   FD_ZERO (&this->mask_);
41   // #endif /* ACE_HAS_BIG_FD_SET */
44 #if defined (ACE_HAS_BIG_FD_SET)
45 ACE_INLINE ACE_Handle_Set &
46 ACE_Handle_Set::operator = (const ACE_Handle_Set &rhs)
48   ACE_TRACE ("ACE_Handle_Set::operator =");
50   if (rhs.size_ > 0)
51     {
52       this->size_ =
53         rhs.size_;
54       this->max_handle_ =
55         rhs.max_handle_;
56       this->min_handle_ =
57         rhs.min_handle_;
58       this->mask_ =
59         rhs.mask_;
60     }
61   else
62     this->reset ();
64   return *this;
66 #endif /* ACE_HAS_BIG_FD_SET */
68 // Returns the number of the large bit.
70 ACE_INLINE ACE_HANDLE
71 ACE_Handle_Set::max_set (void) const
73   ACE_TRACE ("ACE_Handle_Set::max_set");
74   return this->max_handle_;
77 // Checks whether handle is enabled.
79 ACE_INLINE int
80 ACE_Handle_Set::is_set (ACE_HANDLE handle) const
82   ACE_TRACE ("ACE_Handle_Set::is_set");
83 #if defined (ACE_HAS_BIG_FD_SET)
84   return FD_ISSET (handle,
85                    &this->mask_)
86     && this->size_ > 0;
87 #elif defined (ACE_HAS_NONCONST_FD_ISSET)
88   return FD_ISSET (handle,
89                    const_cast<fd_set*> (&this->mask_));
90 #else
91   return FD_ISSET (handle,
92                    &this->mask_);
93 #endif /* ACE_HAS_BIG_FD_SET */
96 // Enables the handle.
98 ACE_INLINE void
99 ACE_Handle_Set::set_bit (ACE_HANDLE handle)
101   ACE_TRACE ("ACE_Handle_Set::set_bit");
102   if ((handle != ACE_INVALID_HANDLE)
103       && (!this->is_set (handle)))
104     {
105 #if defined (ACE_WIN32)
106       FD_SET ((SOCKET) handle,
107               &this->mask_);
108       ++this->size_;
109 #else /* ACE_WIN32 */
110 #if defined (ACE_HAS_BIG_FD_SET)
111       if (this->size_ == 0)
112         FD_ZERO (&this->mask_);
114       if (handle < this->min_handle_)
115         this->min_handle_ = handle;
116 #endif /* ACE_HAS_BIG_FD_SET */
118       FD_SET (handle,
119               &this->mask_);
120       ++this->size_;
122       if (handle > this->max_handle_)
123         this->max_handle_ = handle;
124 #endif /* ACE_WIN32 */
125     }
128 // Disables the handle.
130 ACE_INLINE void
131 ACE_Handle_Set::clr_bit (ACE_HANDLE handle)
133   ACE_TRACE ("ACE_Handle_Set::clr_bit");
135   if ((handle != ACE_INVALID_HANDLE) &&
136       (this->is_set (handle)))
137     {
138       FD_CLR ((ACE_SOCKET) handle,
139               &this->mask_);
140       --this->size_;
142 #if !defined (ACE_WIN32)
143       if (handle == this->max_handle_)
144         this->set_max (this->max_handle_);
145 #endif /* !ACE_WIN32 */
146     }
149 // Returns a count of the number of enabled bits.
151 ACE_INLINE int
152 ACE_Handle_Set::num_set (void) const
154   ACE_TRACE ("ACE_Handle_Set::num_set");
155 #if defined (ACE_WIN32)
156   return this->mask_.fd_count;
157 #else /* !ACE_WIN32 */
158   return this->size_;
159 #endif /* ACE_WIN32 */
162 // Returns a pointer to the underlying fd_set.
164 ACE_INLINE
165 ACE_Handle_Set::operator fd_set *()
167   ACE_TRACE ("ACE_Handle_Set::operator fd_set *");
169   if (this->size_ > 0)
170     return (fd_set *) &this->mask_;
171   else
172     return (fd_set *) 0;
175 // Returns a pointer to the underlying fd_set.
177 ACE_INLINE fd_set *
178 ACE_Handle_Set::fdset (void)
180   ACE_TRACE ("ACE_Handle_Set::fdset");
182   if (this->size_ > 0)
183     return (fd_set *) &this->mask_;
184   else
185     return (fd_set *) 0;
188 ACE_INLINE
189 ACE_Handle_Set_Iterator::~ACE_Handle_Set_Iterator (void)
193 ACE_END_VERSIONED_NAMESPACE_DECL