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) {}
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;
307 return buffer+buffer_size;
317 return reverse_iterator(end());
327 return const_reverse_iterator(end());
337 return reverse_iterator(begin());
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()
iterator end() ecl_assert_throw_decl(StandardException)
virtual ~ConstantDynamicArray()
const_reverse_iterator rend() const ecl_assert_throw_decl(StandardException)
Embedded control libraries.
Parent class for array blueprints.
Array(const blueprints::ArrayBluePrint< T > &blueprint)
Blueprint constructor.
static const char & magicChar()
reference back() ecl_assert_throw_decl(StandardException)
ConstantDynamicArray(size_t size, const Type &value)
Constructor that properly configures/initialises the blueprint.
virtual ~BluePrintFactory()
const Type & const_reference
formatters::ArrayFormatter< Type, DynamicStorage > Formatter
Formatter for this class.
void resize(size_t n) ecl_assert_throw_decl(StandardException)
Resize the array, clearing whatever was in there before.
void implementApply(BaseType &array) const
Array(const unsigned int reserve_size) ecl_assert_throw_decl(StandardException)
Reserves storage for the array.
const_iterator end() const ecl_assert_throw_decl(StandardException)
void operator=(const Array< Type, DynamicStorage > &array)
iterator begin() ecl_assert_throw_decl(StandardException)
size_type size() const
The size of the array.
reverse_iterator rbegin() ecl_assert_throw_decl(StandardException)
const_iterator begin() const ecl_assert_throw_decl(StandardException)
Array()
Default constructor.
#define ecl_assert_throw(expression, exception)
std::ptrdiff_t difference_type
const_reference operator[](size_type i) const ecl_assert_throw_decl(StandardException)
void clear()
Clear the array, deleting all storage space previously allocated.
const_reverse_iterator rbegin() const ecl_assert_throw_decl(StandardException)
ConstantDynamicArray()
Default constructor.
const_reference front() const ecl_assert_throw_decl(StandardException)
const_reference back() const ecl_assert_throw_decl(StandardException)
base_type instantiate()
Instantiate a copy of the object that is blueprinted.
std::reverse_iterator< iterator > reverse_iterator
reference front() ecl_assert_throw_decl(StandardException)
Convenience initialiser with bounds checking for fixed size containers.
#define ecl_assert_throw_decl(exception)
const_reference at(size_type i) const
A safe windowing class that opens onto array-like containers.
#define ecl_compile_time_concept_check(Model)
const Type * const_iterator
OutputStream & operator<<(OutputStream &ostream, Format< std::string > &formatter) ecl_assert_throw_decl(StandardException)
Blueprint for generating a cubic spline satisfying C2 constraints.
std::reverse_iterator< const_iterator > const_reverse_iterator
reverse_iterator rend() ecl_assert_throw_decl(StandardException)
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.
Fixed size containers with a few bells and whistles.
Array(const Array< Type, DynamicStorage > &array)
Copy constructor.
~Array() ecl_assert_throw_decl(StandardException)
Default destructor.
void apply(base_type &array) const
Apply the blueprint to configure an existing object.
Dynamic size container with a few bells and whistles.
Stencil< Array< Type, DynamicStorage > > stencil(const unsigned int &start_index, const unsigned int &n) ecl_assert_throw_decl(StandardException)
Open a window (stencil) onto the array.
reference operator[](size_type i) ecl_assert_throw_decl(StandardException)
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.