Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #ifndef MLN_WIN_LINE_HH 00027 # define MLN_WIN_LINE_HH 00028 00032 00033 # include <mln/core/internal/classical_window_base.hh> 00034 # include <mln/core/dpoint.hh> 00035 00036 00037 namespace mln 00038 { 00039 00040 // Forward declaration. 00041 namespace win { template <typename M, unsigned i, typename C> struct line; } 00042 00043 00044 namespace trait 00045 { 00046 00047 template <typename M, unsigned i, typename C> 00048 struct window_< mln::win::line<M,i,C> > : classical_window_ 00049 { 00050 }; 00051 00052 } // end of namespace trait 00053 00054 00055 00056 namespace win 00057 { 00058 00072 template <typename M, unsigned i, typename C> 00073 struct line : public internal::classical_window_base< dpoint<M, C>, line<M,i,C> > 00074 { 00076 enum { dir = i }; 00077 00081 line(unsigned length); 00082 00084 unsigned length() const; 00085 00087 unsigned size() const; 00088 00091 unsigned delta_() const; 00092 00093 void print_(std::ostream& ostr) const; 00094 00095 protected: 00096 unsigned length_; 00097 }; 00098 00099 00100 00101 # ifndef MLN_INCLUDE_ONLY 00102 00103 00104 template <typename M, unsigned i, typename C> 00105 inline 00106 line<M,i,C>::line(unsigned length) 00107 : length_(length) 00108 { 00109 metal::bool_< i < M::dim >::check(); 00110 mln_precondition(length % 2 == 1); 00111 dpoint<M,C> n; 00112 n.set_all(0); 00113 const def::coord 00114 dc = static_cast<def::coord>(length / 2), 00115 minus_dc = static_cast<def::coord>(- dc); 00116 for (def::coord c = minus_dc; c <= dc; ++c) 00117 { 00118 n[i] = c; 00119 this->insert(n); 00120 } 00121 } 00122 00123 template <typename M, unsigned i, typename C> 00124 inline 00125 unsigned line<M,i,C>::length() const 00126 { 00127 return length_; 00128 } 00129 00130 template <typename M, unsigned i, typename C> 00131 inline 00132 unsigned line<M,i,C>::size() const 00133 { 00134 return length_; 00135 } 00136 00137 template <typename M, unsigned i, typename C> 00138 inline 00139 unsigned line<M,i,C>::delta_() const 00140 { 00141 return length_ / 2; 00142 } 00143 00144 template <typename M, unsigned i, typename C> 00145 inline 00146 void 00147 line<M,i,C>::print_(std::ostream& ostr) const 00148 { 00149 ostr << "[line: length=" << length_ << ']'; 00150 } 00151 00152 # endif // ! MLN_INCLUDE_ONLY 00153 00154 } // end of namespace mln::win 00155 00156 } // end of namespace mln 00157 00158 00159 00160 #endif // ! MLN_WIN_LINE_HH