17#ifndef INCLUDED_vrpn_EndpointContainer_h_GUID_DB073DE8_5BBC_46BF_255B_71264D47A639
18#define INCLUDED_vrpn_EndpointContainer_h_GUID_DB073DE8_5BBC_46BF_255B_71264D47A639
38 class EndpointIterator;
63 typedef std::vector<pointer> container_type;
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")
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)
200 , container_(&container)
213 return container_ && container_->is_valid(index_);
222 return container_ ? (get_raw_()) : NULL;
237 if (equal_to_default_()) {
270 return (container_ == other.container_) && (index_ == other.index_);
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();
318#undef VRPN_ECITERATOR_ASSERT_INVARIANT
334 return container_[i];
340 return container_.size();
Container for endpoints, held by pointer.
size_type get_full_container_size() const
Get size of container including NULL elements that haven't been compacted yet.
pointer front() const
Shorthand for get_by_index(0)
EndpointIterator const_iterator
bool full() const
Can we no longer accommodate a new endpoint?
iterator end() const
Get an iterator suitable only for testing to see if we're "done".
bool is_valid(size_type i) const
Checks to see if an index is both in-range and pointing to a still-extant object.
pointer get_by_index(size_type i) const
T * acquire(T *endpoint)
Given the result of an endpoint allocator, if it's non-NULL, takes ownership of it.
EndpointIterator iterator
void compact()
Goes through and gets rid of the NULL entries.
vrpn_Endpoint * base_pointer
bool destroy(base_pointer endpoint)
Destroys the contained endpoint by address.
container_type::size_type size_type
void clear()
Tells each held endpoint in turn to drop the connection then deletes it.
~EndpointContainer()
Destructor - includes a call to clear()
EndpointContainer()
Constructor of empty container.
iterator begin() const
Get an iterator to the beginning that skips nulls. Invalidated by compacting.
An iterator that goes forward in an EndpointContainer skipping the NULLs, that also acts a bit like a...
bool valid() const
Does this iterator refer to a valid element?
pointer operator->() const
container_type::size_type size_type
bool operator==(type const &other) const
EndpointIterator(container_type &container, size_type index)
Constructor with container and raw index into container.
type & operator++()
prefix ++ operator, increments (and skips any nulls)
container_type::pointer pointer
EndpointIterator(container_type &container)
Constructor with container, points to beginning of container.
container_type::reference reference
bool operator!=(type const &other) const
EndpointIterator()
Default constructor, equal to all other default-constructed instances and all end()
pointer get_pointer() const
Extract the pointer (NULL if iterator is invalid)
EndpointContainer const container_type
reference operator*() const
Encapsulation of the data and methods for a single IP-based connection to take care of one part of ma...
Encapsulation of the data and methods for a single generic connection to take care of one part of man...
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...
#define VRPN_ECITERATOR_ASSERT_INVARIANT()