20 #ifndef AUTO_BLOCK_IMPL_H 21 #define AUTO_BLOCK_IMPL_H 23 #ifndef SHEAF_DLL_SPEC_H 24 #include "SheafSystem/sheaf_dll_spec.h" 28 #include "SheafSystem/auto_block.h" 31 #ifndef ASSERT_CONTRACT_H 32 #include "SheafSystem/assert_contract.h" 36 #include "SheafSystem/deep_size.h" 39 #ifndef INDEX_TRAITS_H 40 #include "SheafSystem/index_traits.h" 78 for(T* i=xbegin; i<xend; ++i)
103 for(T* i=xbegin; i<xend; ++i)
110 template <
typename T>
121 template <
typename T,
typename S>
135 ensure((result != 0) == (ub() > 0));
143 template <
typename T,
typename S>
165 template <
typename T,
typename S>
178 result = result && ( _ub >= 0 );
179 result = result && ( _ct >= 0 );
180 result = result && ( _ct <= _ub );
181 result = result && ((_ub > 0) == (_base != 0));
189 template <
typename T,
typename S>
197 require(xindex >= 0 && xindex < ub());
201 T & result = *(_base+xindex);
213 template <
typename T,
typename S>
221 require(xindex >= 0 && xindex < ub());
225 T & result = *(_base+xindex);
237 template <
typename T,
typename S>
257 template <
typename T,
typename S>
277 ensure((xub > 0) == (base() != 0));
282 template <
typename T,
typename S>
290 require((0 <= xct) && (xct <= xub));
291 require((xct > 0) == (xitems != 0));
292 require(unexecutable(
"xitems != 0 implies xitems points to array of length >= xct"));
303 _base[i] = xitems[i];
311 ensure((xub > 0) == (base() != 0));
314 ensure_for_all(i, 0, ct(), unexecutable(item(i) == xitems[i]));
318 template <
typename T,
typename S>
340 template <
typename T,
typename S>
350 reserve(xother.
ub());
355 _base[i] = xother.
_base[i];
361 ensure(unexecutable(*
this == xother));
369 template <
typename T,
typename S>
382 template <
typename T,
typename S>
390 require(0 <= xindex);
396 index_type new_ub = _ub*2 > xindex ? _ub*2 : xindex + 1;
403 set_item(xindex, xitem);
411 ensure(unexecutable(item(xindex) == xitem));
415 template <
typename T,
typename S>
427 define_old_variable(
size_type old_ct = _ct);
444 newbase[i] = _base[i];
457 initialization_policy::initialize(_base+old_ub, _base+_ub);
463 ensure(ct() == old_ct);
464 ensure(ub() >= old_ub);
466 ensure((ub() > 0) == (base() != 0));
470 template <
typename T,
typename S>
478 require(0 <= xct && xct <= ub());
490 template <
typename T,
typename S>
498 require(0 <= xindex && xindex < ub());
502 *(_base+xindex) = xitem;
510 ensure(unexecutable(item(xindex)==xitem));
514 template <
typename T,
typename S>
523 define_old_variable(
size_type old_ct = ct());
533 ensure(ct() == old_ct);
537 ensure(unexecutable(ensure_for_all(i, 0, ct(), item(i) == xitem)));
542 template <
typename T,
typename S>
549 require(xbegin >= 0);
550 require(xend >= xbegin);
568 ensure(ct() >= xend);
572 ensure(unexecutable(ensure_for_all(i, xbegin, xend, item(i) == xitem)));
577 template <
typename T,
typename S>
594 ensure(unexecutable(result == item(ct() - 1)));
602 template <
typename T,
typename S>
611 force_item(_ct, item);
617 ensure(unexecutable(ct() == old ct()+1));
621 ensure(unexecutable(back() == item));
628 template <
typename T,
typename S>
637 define_old_variable(
size_type old_ct = this->ct());
642 push_back(xother[i]);
647 ensure(this->ct() == old_ct + xother.
ct());
656 template <
typename T,
typename S>
667 define_old_variable(
size_type old_ct = ct() );
670 initialization_policy::initialize(_base[_ct]);
675 ensure(ct() == old_ct-1);
683 template <
typename T,
typename S>
693 initialization_policy::initialize(_base, _base+_ub);
706 template <
typename T,
typename S>
713 require(0 <= xindex && xindex < ub());
717 initialization_policy::initialize(_base[xindex]);
729 template <
typename T,
typename S>
736 require(0 <= xbegin);
737 require(xbegin <= xend);
738 require(xend <= ub());
742 initialization_policy::initialize(_base+xbegin, _base+xend);
757 template <
typename T,
typename S>
767 result = (xblk1.
ub() >= xblk2.
ub());
768 result = result && (xblk1.
ct() == xblk2.
ct());
772 result = (xblk1[i] == xblk2[i]);
782 template <
typename T,
typename S>
784 operator << (std::ostream& xos, const auto_block<T, S>& xblk)
787 for(
long int i=0; i<xblk.ct(); ++i)
789 xos <<
" " << xblk[i];
795 template <
typename T,
typename S>
805 result = xinclude_shallow ?
sizeof(xblk) : 0;
807 for(
int i=0; i<xblk.
ub(); ++i)
819 template <
typename T,
typename S>
829 result = xinclude_shallow ?
sizeof(xblk) : 0;
831 result += xblk.
ub()*
sizeof(T*);
833 for(
int i=0; i<xblk.
ub(); ++i)
850 #endif // AUTO_BLOCK_IMPL_H static T invalid()
The invalid index value.
static void initialize(T *xbegin, T *xend)
Initializes the range [xbegin, xend) to invalid().
index_type ub() const
The upper bound on the storage array. The number of items current allocated in the storage array...
size_type ct() const
The number of items currently in use.
const pod_type & const_reference_type
A type that behaves as a const reference to the container's value type.
auto_block(index_type xub=0)
Creates an instance with ub() == xub; storage is uninitialized.
bool invariant() const
The class invariant.
static void initialize(T *xbegin, T *xend)
Initializes the range [xbegin, xend) to invalid().
unsigned long int size_type
An unsigned integral type used to represent sizes and capacities.
reference_type back() const
The last item in the auto_block.
void force_item(index_type xindex, const_reference_type xitem)
Puts the item xitem at index xindex, resizing if necessary; any other new storage allocated is uninit...
void reserve(index_type xub)
Makes ub() at least xub; if new storage is allocated, it is uninitialized.
A contiguously allocated array of items of type T with size information and automatic resizing...
void initialize(index_type xindex)
Invokes the initialization policy on the item at xindex.
auto_block & operator=(const auto_block &xother)
Assignment operator.
pod_type * pointer_type
A type that behaves as a pointer to the container's value type.
reference_type item(index_type xindex) const
The item at index xindex.
void push_back(const_reference_type item)
Insert item at the end of the items in the auto_block.
void assign(const_reference_type xitem)
Sets the values of all items to xitem.
void pop_back()
Remove item at the back.
pointer_type base() const
The underlying storage array.
void set_ct(size_type xct)
Sets ct() == xct.
SHEAF_DLL_SPEC size_t deep_size(const dof_descriptor_array &xp, bool xinclude_shallow=true)
The deep size of the referenced object of type dof_descriptor_array.
void set_item(index_type xindex, const_reference_type xitem)
Puts the item xitem at index xindex, but will not resize.
reference_type operator[](index_type xindex) const
The item at index xindex.
size_type _ct
The number of items currently stored.
bool operator==(const singly_linked_list< T, Alloc > &lhs, const singly_linked_list< T, Alloc > &rhs)
Checks if the contents of lhs and rhs are equal, that is, whether lhs.size() == rhs.size() and each element in lhs compares equal with the element in rhs at the same position.
sheaf::pod_index_type index_type
The containers index type.
virtual ~auto_block()
Destructor.
int_type pod_index_type
The plain old data index type.
Namespace for the sheaves component of the sheaf system.
pointer_type _base
Start of storage for this.
pod_type & reference_type
A type that behaves as a reference to the container's value type.
void clear()
Remove all items.
static void initialize(T *xbegin, T *xend)
Initializes the range [xbegin, xend).