00001 // Copyright (C) 2001, 2003, 2004 EPITA Research and Development Laboratory 00002 // 00003 // This file is part of the Olena Library. This library is free 00004 // software; you can redistribute it and/or modify it under the terms 00005 // of the GNU General Public License version 2 as published by the 00006 // Free Software Foundation. 00007 // 00008 // This library is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 // General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this library; see the file COPYING. If not, write to 00015 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 // Boston, MA 02110-1301, USA. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software library without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to 00022 // produce an executable, this file does not by itself cause the 00023 // resulting executable to be covered by the GNU General Public 00024 // License. This exception does not however invalidate any other 00025 // reasons why the executable file might be covered by the GNU General 00026 // Public License. 00027 00028 #ifndef OLENA_CORE_IMPL_IMAGE_IMPL_HH 00029 # define OLENA_CORE_IMPL_IMAGE_IMPL_HH 00030 00031 # include <oln/core/internal/fake.hh> 00032 # include <oln/core/coord.hh> 00033 # include <oln/core/abstract/image.hh> 00034 # include <mlc/contract.hh> 00035 # include <mlc/type.hh> 00036 00037 # include <iostream> 00038 00039 namespace oln { 00040 00041 namespace impl { 00042 00043 template<class Exact> 00044 class image_impl; 00045 00046 } // end of impl 00047 00048 template<class Impl> 00049 struct impl_traits; 00050 00057 template<class Exact> 00058 struct impl_traits<impl::image_impl<Exact> > 00059 { 00060 00061 }; 00062 00063 namespace impl { 00064 00070 template<class Exact> 00071 class image_impl : public mlc_hierarchy::any<Exact> 00072 { 00073 00074 public: 00075 00076 typedef typename impl_traits<Exact>::point_type point_type; 00077 typedef typename impl_traits<Exact>::value_type value_type; 00078 typedef typename impl_traits<Exact>::size_type size_type; 00079 00080 typedef Exact exact_type; 00081 00082 image_impl(const size_type s): refcount_(0), size_(s) {} 00083 00084 image_impl() {} 00085 00087 00088 void 00089 ref() const 00090 { 00091 ++refcount_; 00092 } 00093 00098 void 00099 unref() const 00100 { 00101 invariant(refcount_ > 0); 00102 --refcount_; 00103 if (refcount_ == 0) 00104 delete mlc::to_exact(this); 00105 } 00106 00108 00109 const value_type& 00110 at(const point_type& p) const 00111 { 00112 return this->exact().at_(p); 00113 } 00114 00116 00117 value_type& 00118 at(const point_type& p) 00119 { 00120 return this->exact().at_(p); 00121 } 00122 00124 00125 bool 00126 hold(const point_type& p) const 00127 { 00128 return this->exact().hold_(p); 00129 } 00130 00132 00133 bool 00134 hold_large(const point_type& p) const 00135 { 00136 return this->exact().hold_large_(p); 00137 } 00138 00140 00141 void 00142 precondition_hold_large(const point_type& p) const 00143 { 00144 # ifndef NDEBUG 00145 if (! hold_large(p)) 00146 std::cerr << "image overflow at (" << p << ")" << std::endl; 00147 # else 00148 (void) p; 00149 # endif 00150 } 00151 00152 00154 00155 void 00156 clone_to(exact_type* output_data) const 00157 { 00158 return this->exact().clone_to_(output_data); 00159 } 00160 00162 00163 const 00164 size_type& size() const 00165 { 00166 return size_; 00167 } 00168 00169 size_type& 00170 size() 00171 { 00172 return size_; 00173 } 00174 00175 // borders 00176 00181 void 00182 border_reallocate_and_copy(coord new_border, bool 00183 copy_border) 00184 { 00185 this->exact().border_reallocate_and_copy_(new_border, copy_border); 00186 } 00187 00192 void 00193 border_replicate(void) 00194 { 00195 this->exact().border_replicate_(); 00196 } 00197 00202 void 00203 border_mirror(void) 00204 { 00205 this->exact().border_mirror_(); 00206 } 00207 00209 00210 void 00211 border_assign(value_type val) 00212 { 00213 this->exact().border_assign_(val); 00214 } 00215 00216 private: 00217 00218 mutable unsigned refcount_; 00219 00220 protected: 00221 00222 size_type size_; 00223 00224 }; 00225 00226 } // end of namespace impl 00227 00228 } // end of namespace oln 00229 00230 #endif // ! OLENA_CORE_IMPL_IMAGE_IMPL_HH