12 #ifndef ECL_CONTAINERS_ARRAY_DYNAMIC_NO_MEM_CHECK_HPP_
13 #define ECL_CONTAINERS_ARRAY_DYNAMIC_NO_MEM_CHECK_HPP_
22 #include "../definitions.hpp"
23 #include "../initialiser.hpp"
24 #include "../stencil.hpp"
39 namespace blueprints {
41 template <
typename Type>
class ConstantDynamicArray;
45 namespace formatters {
47 template <
typename Type,
size_t N>
class ArrayFormatter;
62 template<
typename Type>
73 static blueprints::ConstantDynamicArray<Type> Constant(
size_t size,
const Type &value) {
74 return blueprints::ConstantDynamicArray<Type>(size,value);
76 virtual ~BluePrintFactory() {};
128 template<
typename Type>
134 typedef Type value_type;
135 typedef Type* iterator;
136 typedef const Type* const_iterator;
137 typedef Type& reference;
138 typedef const Type& const_reference;
139 typedef std::size_t size_type;
140 typedef std::ptrdiff_t difference_type;
141 typedef std::reverse_iterator<iterator> reverse_iterator;
156 explicit Array() : buffer_size(0), buffer(NULL) {}
165 explicit Array(
const unsigned int reserve_size) : buffer_size(reserve_size), buffer(NULL) {
166 buffer =
new Type[reserve_size];
175 Array(
const Array<Type,DynamicStorage>& array) :
180 if ( array.size() != 0 ) {
181 resize(array.size());
182 std::copy(array.begin(),array.end(),begin());
206 Array(
const blueprints::ArrayBluePrint< T > &blueprint) : buffer_size(0), buffer(NULL) {
212 blueprint.implementApply(*
this);
220 if ( buffer != NULL ) {
240 containers::BoundedListInitialiser<value_type,iterator,DynamicStorage>
operator<<(
const Type &value) {
241 return containers::BoundedListInitialiser<value_type,iterator,DynamicStorage>(value,buffer,buffer_size);
244 void operator=(
const Array<Type,DynamicStorage>& array) {
245 if ( array.size() == 0 ) {
248 resize(array.size());
249 std::copy(array.begin(),array.end(),begin());
272 const_iterator begin()
const {
284 return buffer+buffer_size;
292 const_iterator end()
const {
294 return buffer+buffer_size;
302 reverse_iterator rbegin() {
304 return reverse_iterator(end());
312 const_reverse_iterator rbegin()
const {
314 return const_reverse_iterator(end());
322 reverse_iterator rend() {
324 return reverse_iterator(begin());
332 const_reverse_iterator rend()
const {
334 return const_reverse_iterator(begin());
356 const_reference front()
const {
368 return buffer[buffer_size-1];
376 const_reference back()
const {
378 return buffer[buffer_size-1];
395 Stencil< Array<Type,DynamicStorage> > stencil(
const unsigned int& start_index,
const unsigned int& n) {
398 return Stencil< Array<Type,DynamicStorage> >(*
this, begin()+start_index, begin()+start_index+n);
409 reference operator[](size_type i) {
424 const_reference operator[](size_type i)
const {
438 reference at(size_type i) {
439 if ( i>=buffer_size ) {
456 const_reference at(size_type i)
const {
457 if ( i>=buffer_size ) {
473 size_type size()
const {
return buffer_size; }
483 void resize(
size_t n ) {
484 if ( buffer != NULL ) {
487 buffer =
new Type[n];
496 if ( buffer != NULL ) {
513 template <
typename OutputStream,
typename ElementType>
517 unsigned int buffer_size;
526 template <
typename OutputStream,
typename ElementType>
530 for(
size_t i = 0; i < array.buffer_size; ++i )
532 ostream << array[i] <<
" ";
544 namespace blueprints {
557 template <
typename Type>
558 class ConstantDynamicArray:
public ArrayBluePrint< ConstantDynamicArray<Type> > {