12 #ifndef ECL_CONTAINERS_ARRAY_DYNAMIC_MEM_CHECK_HPP_ 13 #define ECL_CONTAINERS_ARRAY_DYNAMIC_MEM_CHECK_HPP_ 24 #include "../definitions.hpp" 25 #include "../initialiser.hpp" 26 #include "../stencil.hpp" 41 namespace blueprints {
47 namespace formatters {
61 template<
typename Type>
127 template<
typename Type>
155 explicit Array() : buffer_size(0), underrun(NULL), buffer(NULL), overrun(NULL) {}
164 explicit Array(
const unsigned int reserve_size) :
165 buffer_size(reserve_size),
170 underrun = (
char*) malloc(buffer_size*
sizeof(Type)+bufferUnderrunLength()+bufferOverrunLength());
172 buffer = (Type*) (underrun+bufferUnderrunLength());
173 overrun = (
char*) underrun+bufferUnderrunLength()+buffer_size*
sizeof(Type);
178 initialiseMagicSections();
188 if ( array.
size() != 0 ) {
189 resize(array.
size());
190 std::copy(array.
begin(),array.
end(),begin());
221 initialiseMagicSections();
230 if ( underrun != NULL ) {
258 if ( array.
size() == 0 ) {
261 resize(array.
size());
262 std::copy(array.
begin(),array.
end(),begin());
297 return buffer+buffer_size;
305 const_iterator
end()
const {
307 return buffer+buffer_size;
317 return reverse_iterator(end());
327 return const_reverse_iterator(end());
337 return reverse_iterator(begin());
345 const_reverse_iterator
rend()
const {
347 return const_reverse_iterator(begin());
381 return buffer[buffer_size-1];
391 return buffer[buffer_size-1];
452 if ( i>=buffer_size ) {
470 if ( i>=buffer_size ) {
486 size_type
size()
const {
return buffer_size; }
497 if ( underrun != NULL ) {
501 underrun = (
char*) malloc(buffer_size*
sizeof(Type)+bufferUnderrunLength()+bufferOverrunLength());
503 buffer = (Type*) (underrun+bufferUnderrunLength());
504 overrun = (
char*) underrun+bufferUnderrunLength()+buffer_size*
sizeof(Type);
509 initialiseMagicSections();
517 if ( underrun != NULL ) {
536 template <
typename OutputStream,
typename ElementType>
537 friend OutputStream& operator<<(OutputStream &ostream , const Array<ElementType,DynamicStorage> &array);
542 bool bufferUnderRun();
543 bool bufferOverRun();
544 bool bufferOverFlow();
547 void initialiseMagicSections();
550 static const unsigned int buffer_overrun_length = 4;
551 return buffer_overrun_length;
554 static const unsigned int buffer_underrun_length = 4;
555 return buffer_underrun_length;
558 static const char magic_char = 0xCC;
576 template<
typename Type>
580 for (
unsigned int i = 0; i < bufferUnderrunLength(); ++i ) {
581 *(underrun+i) = magicChar();
583 for (
unsigned int i = 0; i < bufferOverrunLength(); ++i ) {
584 *(overrun+i) = magicChar();
595 template<
typename Type>
597 if ( underrun != NULL ) {
598 for (
unsigned int i = 0; i < bufferUnderrunLength(); ++i ) {
599 if ( *(underrun+i) != magicChar() ) {
615 template<
typename Type>
618 if ( overrun != NULL ) {
619 for (
unsigned int i = 0; i < bufferOverrunLength(); ++i ) {
620 if ( *(overrun+i) != magicChar() ) {
637 template<
typename Type>
639 return ( bufferOverRun() || bufferUnderRun() );
647 template <
typename OutputStream,
typename ElementType>
648 OutputStream& operator<<(OutputStream &ostream , const Array<ElementType,DynamicStorage> &array) {
651 for(
size_t i = 0; i < array.buffer_size; ++i )
653 ostream << array[i] <<
" ";
665 namespace blueprints {
678 template <
typename Type>
679 class ConstantDynamicArray:
public ArrayBluePrint< ConstantDynamicArray<Type> > {
720 std::fill_n(array.
begin(),reserve_size,val);
732 void apply(base_type& array)
const {
733 array.resize(reserve_size);
734 std::fill_n(array.
begin(),reserve_size,val);
Fixed size container with a few bells and whistles.
static const unsigned int & bufferOverrunLength()
virtual ~ConstantDynamicArray()
Embedded control libraries.
Parent class for array blueprints.
Array(const blueprints::ArrayBluePrint< T > &blueprint)
Blueprint constructor.
static const char & magicChar()
const_reference at(size_type i) const
OutputStream & operator<<(OutputStream &ostream, Format< std::string > &formatter)
ConstantDynamicArray(size_t size, const Type &value)
Constructor that properly configures/initialises the blueprint.
virtual ~BluePrintFactory()
const Type & const_reference
const_iterator begin() const
const_reverse_iterator rend() const
void apply(base_type &array) const
Apply the blueprint to configure an existing object.
formatters::ArrayFormatter< Type, DynamicStorage > Formatter
Formatter for this class.
Array(const unsigned int reserve_size)
Reserves storage for the array.
void operator=(const Array< Type, DynamicStorage > &array)
const_reverse_iterator rbegin() const
~Array()
Default destructor.
Array()
Default constructor.
#define ecl_assert_throw(expression, exception)
std::ptrdiff_t difference_type
const_reference back() const
void clear()
Clear the array, deleting all storage space previously allocated.
reverse_iterator rbegin()
ConstantDynamicArray()
Default constructor.
const_reference operator[](size_type i) const
void resize(size_t n)
Resize the array, clearing whatever was in there before.
base_type instantiate()
Instantiate a copy of the object that is blueprinted.
size_type size() const
The size of the array.
std::reverse_iterator< iterator > reverse_iterator
Convenience initialiser with bounds checking for fixed size containers.
A safe windowing class that opens onto array-like containers.
#define ecl_compile_time_concept_check(Model)
const Type * const_iterator
Blueprint for generating a cubic spline satisfying C2 constraints.
std::reverse_iterator< const_iterator > const_reverse_iterator
static const unsigned int & bufferUnderrunLength()
reference at(size_type i)
static blueprints::ConstantDynamicArray< Type > Constant(size_t size, const Type &value)
Generates a constant array of the specified size.
Stencil< Array< Type, DynamicStorage > > stencil(const unsigned int &start_index, const unsigned int &n)
Open a window (stencil) onto the array.
Fixed size containers with a few bells and whistles.
Array(const Array< Type, DynamicStorage > &array)
Copy constructor.
reference operator[](size_type i)
const_iterator end() const
Dynamic size container with a few bells and whistles.
void implementApply(BaseType &array) const
const_reference front() const
BluePrintFactory< Array< Type, DynamicStorage > > Factory
Generates blueprints for this class.
ecl::Array< Type, ecl::DynamicStorage > base_type
Abstract representation of the class to be instantiated/configured.