21 #ifndef IMPLICIT_ENTRY_MAP_IMPL_H 22 #define IMPLICIT_ENTRY_MAP_IMPL_H 24 #ifndef IMPLICIT_ENTRY_MAP_H 25 #include "SheafSystem/implicit_entry_map.h" 28 #ifndef ASSERT_CONTRACT_H 29 #include "SheafSystem/assert_contract.h" 33 #include "SheafSystem/deep_size.h" 36 #ifndef IMPLICIT_ENTRY_MAP_ITERATOR_H 37 #include "SheafSystem/implicit_entry_map_iterator.h" 41 #include "SheafSystem/rc_ptr.h" 53 template <
typename E,
typename I>
73 template <
typename E,
typename I>
83 typename explicit_value_map_type::iterator lexplicit_value_itr =
84 _explicit_value_map.begin();
85 while(lexplicit_value_itr != _explicit_value_map.end())
89 if(lexplicit_value_itr->second != 0)
91 delete lexplicit_value_itr->second;
96 lexplicit_value_itr++;
101 typename interval_map_type::iterator linterval_itr = _interval_map.begin();
102 while(linterval_itr != _interval_map.end())
106 if(linterval_itr->second != 0)
108 delete linterval_itr->second;
123 template <
typename E,
typename I>
132 typename explicit_value_map_type::const_iterator litr =
133 _explicit_value_map.find(xid);
135 bool result = (litr != _explicit_value_map.end());
144 template <
typename E,
typename I>
153 typename interval_map_type::const_iterator litr =
154 _interval_map.upper_bound(xid);
156 bool result = (litr != _interval_map.end()) && (litr->second != 0);
165 template <
typename E,
typename I>
184 template <
typename E,
typename I>
210 result = &*lexplicit_value;
220 template <
typename E,
typename I>
231 E& result =
value(xid);
240 template <
typename E,
typename I>
261 update_extrema_for_insert(xid, xid+1);
266 ensure(
ct() == old_ct+1);
267 ensure(
begin() <= xid);
268 ensure(
end() >= xid+1);
275 template <
typename E,
typename I>
283 require(unexecutable(
"interval is empty"));
289 pod_type lbegin = xinterval.begin();
294 if(_interval_map.find(lbegin) == _interval_map.end())
299 _interval_map[lbegin] = 0;
304 _ct += xinterval.ct();
308 update_extrema_for_insert(lbegin, lend);
313 ensure(unexecutable(
"interval is full"));
314 ensure(
ct() == old_ct + xinterval.ct());
315 ensure(
begin() <= xinterval.begin());
316 ensure(
end() >= xinterval.end());
323 template <
typename E,
typename I>
342 _explicit_value_map.erase(xid);
354 update_extrema_for_remove(xid, xid+1);
359 ensure(
ct() == old_ct - 1);
362 ensure(((
ct() > 0) && (xid == old_begin)) ?
begin() > xid :
true);
363 ensure(((
ct() > 0) && ((xid + 1) == old_end)) ?
end() <= xid :
true);
370 template <
typename E,
typename I>
381 typename interval_map_type::iterator litr = _interval_map.upper_bound(xid);
384 typename interval_map_type::iterator lprevious = litr;
388 typename interval_map_type::iterator lnext = litr;
391 if(lprevious->second == 0)
393 if((lnext == _interval_map.end()) || (lnext->second == 0))
398 _interval_map.erase(litr);
399 if(litr->second != 0)
402 _interval_map.erase(lprevious);
408 _interval_map[lend] = 0;
409 _interval_map.erase(lprevious);
414 if((lnext == _interval_map.end()) || (lnext->second == 0))
418 _interval_map.erase(litr);
419 if(litr->second != 0)
426 _interval_map[lend] = 0;
432 _ct -= (lend-lbegin);
436 update_extrema_for_remove(lbegin, lend);
451 template <
typename E,
typename I>
485 typename interval_map_type::iterator litr = _interval_map.upper_bound(xid);
488 typename interval_map_type::iterator lprevious = litr;
504 else if(xid == lbegin)
508 if(lprevious->second == 0)
512 _interval_map.erase(lprevious);
517 _interval_map[xid+1] = 0;
528 else if(xid == lend-1)
532 typename interval_map_type::iterator lnext = litr;
537 _interval_map.erase(litr);
538 _interval_map[xid] = linterval;
540 if((lnext != _interval_map.end()) && (lnext->second != 0))
544 _interval_map[lend] = 0;
561 _interval_map[xid+1] = 0;
581 template <
typename E,
typename I>
601 template <
typename E,
typename I>
609 template <
typename E,
typename I>
617 template <
typename E,
typename I>
627 template <
typename E,
typename I>
636 template <
typename E,
typename I>
645 template <
typename E,
typename I>
654 typename explicit_value_map_type::const_iterator litr =
655 _explicit_value_map.find(xid);
667 template <
typename E,
typename I>
676 typename interval_map_type::const_iterator litr =
677 _interval_map.upper_bound(xid);
680 (((litr != _interval_map.end()) && (litr->second != 0)) ?
692 template <
typename E,
typename I>
703 if(!
is_valid(_begin) || (xbegin < _begin))
710 if(!
is_valid(_end) || (xend > _end))
717 ensure(
begin() <= xbegin);
718 ensure(
end() >= xend);
725 template <
typename E,
typename I>
732 require(unexecutable(
"containers have been updated."));
733 require(unexecutable(
"ct() has been updated."));
747 else if(xbegin == _begin)
751 for(
pod_type i = _begin; i < _end; i++)
760 else if(xend == _end)
764 for(
pod_type i = xend - 1; i >= _begin; i--)
778 ensure(((
ct() > 0) && (xbegin == old_begin)) ?
begin() > xbegin :
true);
779 ensure(((
ct() > 0) && (xend == old_end)) ?
end() < xend :
true);
792 template <
typename E,
typename I>
812 template <
typename E,
typename I>
833 template <
typename E,
typename I>
874 template <
typename E,
typename I>
882 size_t result = xinclude_shallow ?
sizeof(xmap) : 0;
910 #endif // ifndef IMPLICIT_ENTRY_MAP_IMPL_H virtual bool invariant() const
Class invariant, intended to be redefined in each descendant. See below for template for invariant in...
static const interval_type & null_interval()
Null implicit interval.
void insert_explicit_entry(pod_type xid, E &xvalue)
Insert the explicit value xvalue at xid.
const explicit_value_type & explicit_value(pod_type xid) const
The explicit value at xid.
rc_ptr< E > explicit_value_type
The type of an explicit value.
bool contains_entry(pod_type xid) const
True if and only if contains_explicit_entry(xid) or contains_implicit_entry(xid). ...
void remove_implicit_interval(pod_type xid)
Remove the entire interval that contains xid.
pod_type begin() const
The beginning id of this.
void remove_explicit_entry(pod_type xid)
Remove the explicit entry at xid.
E & operator[](pod_type xid) const
The value at xid. If this map contains an explicit entry at xid, the explicit value is returned...
Abstract base class with useful features for all objects.
A map in which the entries may be implicit.
An iterator over the entries in an implicit_entry_map. This iteration is NOT order preserving...
~implicit_entry_map()
Destructor.
void remove_entry(pod_type xid, bool xremove_interval)
Remove the entry at xid. If xremove_interval remove the entire interval at xid otherwise only remove ...
void insert_implicit_interval(I &xinterval)
Insert the implicit interval xinterval.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
size_type ct() const
The number of entries in this.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
bool contains_implicit_entry(pod_type xid) const
True if and only if this map contains an implicit entry for xid.
E & value(pod_type xid) const
The value at xid. If this map contains an explicit entry at xid, the explicit value is returned...
implicit_entry_map()
Default Constructor.
virtual bool invariant() const
Class invariant.
const interval_type & implicit_interval(pod_type xid) const
The implicit interval that contains xid.
virtual implicit_entry_map< E, I > * clone() const
Virtual constructor, makes a new instance of the same type as this.
bool contains_explicit_entry(pod_type xid) const
True if and only if this map contains an explicit entry for xid.
bool invariant_check() const
True if invariant checking is enabled.
int_type pod_index_type
The plain old data index type.
pod_type end() const
The ending id of this.
Namespace for the sheaves component of the sheaf system.
static const explicit_value_type & null_explicit_value()
Null explicit value.
implicit_entry_map_iterator< E, I > iterator_type
The type of iterator for this map.
friend size_t deep_size(const implicit_entry_map< E, I > &xmap, bool xinclude_shallow)
The deep size of the referenced object of type implicit_entry_map<E, I>; if xinclude_shallow, add the sizeof xvalue to the result.
rc_ptr< I > interval_type
The type of an interval.
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
SHEAF_DLL_SPEC pod_index_type invalid_pod_index()
The invalid pod index value.
bool is_same_type(const any *other) const
True if other is the same type as this.
pod_index_type pod_type
The "plain old data" index type for this.
void enable_invariant_check() const
Enable invariant checking.
implicit_entry_map_iterator< E, I > * iterator() const
An iterator for the entries of this map.
Reference-counted pointer to object of type T. T must be an implementation of concept class rc_any...