17#ifndef INCLUDED_vrpn_EndpointContainer_h_GUID_DB073DE8_5BBC_46BF_255B_71264D47A639
18#define INCLUDED_vrpn_EndpointContainer_h_GUID_DB073DE8_5BBC_46BF_255B_71264D47A639
21#include "vrpn_Types.h"
22#include "vrpn_Configure.h"
23#include "vrpn_Shared.h"
38 class EndpointIterator;
66 typedef container_type::size_type size_type;
106 pointer get_by_index(size_type i)
const;
123 typedef container_type::iterator raw_iterator;
124 typedef container_type::const_iterator raw_const_iterator;
125 raw_iterator begin_() {
return container_.begin(); }
126 raw_const_iterator begin_()
const {
return container_.begin(); }
127 raw_iterator end_() {
return container_.end(); }
128 raw_const_iterator end_()
const {
return container_.end(); }
133 void acquire_(pointer endpoint);
138 container_type container_;
142#define VRPN_ECITERATOR_ASSERT_INVARIANT() \
143 VRPN_ASSERT_MSG(valid() != equal_to_default_(), \
144 "Class invariant for EndpointIterator")
169 typedef container_type::pointer pointer;
170 typedef container_type::reference reference;
171 typedef container_type::size_type size_type;
180 "Default constructed value should be equal to "
181 "default: verifies that 'equal_to_default_()' is "
182 "equivalent to '*this == EndpointIterator()'");
184 "Default constructed value should not be valid");
190 , container_(&container)
194 VRPN_ECITERATOR_ASSERT_INVARIANT();
200 , container_(&container)
204 VRPN_ECITERATOR_ASSERT_INVARIANT();
213 return container_ && container_->is_valid(index_);
222 return container_ ? (get_raw_()) : NULL;
226 operator pointer()
const
237 if (equal_to_default_()) {
247 VRPN_ECITERATOR_ASSERT_INVARIANT();
253 pointer operator->()
const
255 VRPN_ECITERATOR_ASSERT_INVARIANT();
259 reference operator*()
const
261 VRPN_ECITERATOR_ASSERT_INVARIANT();
268 bool operator==(type
const &other)
const
270 return (container_ == other.container_) && (index_ == other.index_);
272 bool operator!=(type
const &other)
const
274 return (container_ != other.container_) || (index_ != other.index_);
279 bool equal_to_default_()
const
281 return (NULL == container_) && (index_ == 0);
285 while (index_in_bounds_() && (get_raw_() == NULL)) {
289 enforce_invariant_();
293 void enforce_invariant_()
306 pointer get_raw_()
const {
return container_->get_by_index(index_); }
310 bool index_in_bounds_()
const
312 return index_ < container_->get_full_container_size();
316 container_type *container_;
318#undef VRPN_ECITERATOR_ASSERT_INVARIANT
329 EndpointContainer::get_by_index(size_type i)
const
334 return container_[i];
337 inline EndpointContainer::size_type
340 return container_.size();
Container for endpoints, held by pointer.
定义 vrpn_EndpointContainer.h:55
void compact()
Goes through and gets rid of the NULL entries.
定义 vrpn_EndpointContainer.h:345
iterator end() const
Get an iterator suitable only for testing to see if we're "done"
定义 vrpn_EndpointContainer.h:357
EndpointContainer()
Constructor of empty container.
pointer front() const
Shorthand for get_by_index(0)
定义 vrpn_EndpointContainer.h:81
T * acquire(T *endpoint)
Given the result of an endpoint allocator, if it's non-NULL, takes ownership of it.
定义 vrpn_EndpointContainer.h:86
bool is_valid(size_type i) const
Checks to see if an index is both in-range and pointing to a still-extant object
定义 vrpn_EndpointContainer.h:323
size_type get_full_container_size() const
Get size of container including NULL elements that haven't been compacted yet.
定义 vrpn_EndpointContainer.h:338
bool full() const
Can we no longer accommodate a new endpoint?
bool destroy(base_pointer endpoint)
Destroys the contained endpoint by address.
void clear()
Tells each held endpoint in turn to drop the connection then deletes it
iterator begin() const
Get an iterator to the beginning that skips nulls. Invalidated by compacting.
定义 vrpn_EndpointContainer.h:352
~EndpointContainer()
Destructor - includes a call to clear()
An iterator that goes forward in an EndpointContainer skipping the NULLs, that also acts a bit like a...
定义 vrpn_EndpointContainer.h:164
bool valid() const
Does this iterator refer to a valid element?
定义 vrpn_EndpointContainer.h:211
EndpointIterator(container_type &container)
Constructor with container, points to beginning of container.
定义 vrpn_EndpointContainer.h:188
EndpointIterator(container_type &container, size_type index)
Constructor with container and raw index into container.
定义 vrpn_EndpointContainer.h:198
EndpointIterator()
Default constructor, equal to all other default-constructed instances and all end()
定义 vrpn_EndpointContainer.h:175
pointer get_pointer() const
Extract the pointer (NULL if iterator is invalid)
定义 vrpn_EndpointContainer.h:217
type & operator++()
prefix ++ operator, increments (and skips any nulls)
定义 vrpn_EndpointContainer.h:233
Encapsulation of the data and methods for a single IP-based connection to take care of one part of ma...
定义 vrpn_Connection.h:423
Encapsulation of the data and methods for a single generic connection to take care of one part of man...
定义 vrpn_Connection.h:254
Header for assert macros.
#define VRPN_ASSERT_MSG(expr, msg)
Like VRPN_ASSERT(expr) but allows specification of a message to be included in the case of a failed a...
定义 vrpn_Assert.h:153