00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef OLENA_CORE_IMPL_IMAGE_ARRAY_HH
00029 # define OLENA_CORE_IMPL_IMAGE_ARRAY_HH
00030
00031 # include <oln/core/internal/fake.hh>
00032 # include <mlc/contract.hh>
00033 # include <oln/core/coord.hh>
00034 # include <oln/core/impl/image_impl.hh>
00035 # include <iostream>
00036 # include <ntg/all.hh>
00037
00038 namespace oln {
00039
00046 template<class T>
00047 void
00048 allocate_data_(T*& buffer, size_t s)
00049 {
00050 precondition(s > 0);
00051 buffer = new T[s];
00052 }
00053
00059 template<class T>
00060 void
00061 desallocate_data_(T*& buffer)
00062 {
00063 precondition(buffer != 0);
00064 delete[] buffer;
00065 buffer = 0;
00066 }
00067
00068 namespace impl {
00069 template<class T, class Exact>
00070 class image_array;
00071 }
00072
00073
00079 template<class T, class Exact>
00080 struct impl_traits<impl::image_array<T, Exact> >: public impl_traits<impl::image_impl<Exact> >
00081 {
00082
00083 };
00084
00087 namespace impl {
00088
00094 template<class T, class Exact>
00095 class image_array: public image_impl<Exact>
00096 {
00097
00098 public:
00099
00100 typedef typename impl_traits<Exact>::point_type point_type;
00101 typedef typename impl_traits<Exact>::value_type value_type;
00102 typedef typename impl_traits<Exact>::size_type size_type;
00103 typedef Exact exact_type;
00104
00105
00106 typedef image_impl<Exact> super_type;
00107 typedef image_array<T, Exact> self_type;
00108
00109 enum { dim = impl_traits<Exact>::dim };
00110
00111 friend class image_impl<Exact>;
00112
00119 image_array(const size_type& s): super_type(s), buffer_(0)
00120 {
00121 allocate_data_(buffer_, len(s));
00122 }
00123
00124 image_array() : buffer_(0)
00125 {}
00126
00127 image_array(const self_type&);
00128
00129 void
00130 operator=(const self_type&);
00131
00137 const T*
00138 buffer() const
00139 {
00140 invariant(buffer_ != 0);
00141 return buffer_;
00142 }
00143
00149 T*
00150 buffer()
00151 {
00152 invariant(buffer_ != 0);
00153 return buffer_;
00154 }
00155
00157 size_t
00158 len() const
00159 {
00160 return len(this->size());
00161 }
00162
00164 size_t
00165 len(const size_type& s) const
00166 {
00167 return this->exact().len_(s);
00168 }
00169
00170 protected:
00171
00172
00173 ~image_array()
00174 {
00175 if (buffer_)
00176 desallocate_data_(buffer_);
00177 }
00178
00187 void
00188 clone_to_(exact_type* output_data) const
00189 {
00190 precondition(output_data != 0);
00191 precondition(output_data->len() == len());
00192 memcpy(output_data->buffer(),
00193 buffer_,
00194 len() * sizeof(T));
00195 }
00196
00197 T* buffer_;
00198
00199 };
00200
00201 }
00202
00203 }
00204
00205 #endif // ! OLENA_CORE_IMPL_IMAGE_ARRAY_HH