00001 // Copyright (C) 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_VALUE_SIGN_HH 00027 # define MLN_VALUE_SIGN_HH 00028 00033 # include <mln/value/internal/integer.hh> 00034 # include <mln/trait/value_.hh> 00035 # include <mln/literal/zero.hh> 00036 # include <mln/literal/one.hh> 00037 # include <mln/debug/format.hh> 00038 00039 namespace mln 00040 { 00041 00042 namespace value 00043 { 00049 class sign : public internal::Integer<sign> 00050 { 00051 public: 00053 00055 typedef int enc; 00056 00058 typedef int equiv; 00059 00060 00062 sign(); 00063 00065 sign(int i); 00066 00068 sign(const mln::literal::zero_t&); 00069 sign& operator=(const mln::literal::zero_t&); 00070 sign(const mln::literal::one_t&); 00071 sign& operator=(const mln::literal::one_t&); 00073 00075 operator int() const; 00076 00078 int val_() const; 00079 00081 sign& operator=(int i); 00082 00083 00085 static const sign zero; 00086 00088 static const sign one; 00089 00090 protected: 00091 00093 int v_; 00094 }; 00095 00103 std::ostream& operator<<(std::ostream& ostr, const sign& i); 00104 00106 bool operator==(const sign& lhs, const sign& rhs); 00107 bool operator<(const sign& lhs, const sign& rhs); 00108 00109 # ifndef MLN_INCLUDE_ONLY 00110 00111 # ifndef MLN_WO_GLOBAL_VARS 00112 00113 const sign sign::zero = 0; 00114 const sign sign::one = 1; 00115 00116 # endif // !MLN_WO_GLOBAL_VARS 00117 00118 inline 00119 sign::sign() 00120 { 00121 } 00122 00123 inline 00124 sign::operator int() const 00125 { 00126 return this->v_; 00127 } 00128 00129 inline 00130 int 00131 sign::val_() const 00132 { 00133 return this->v_; 00134 } 00135 00136 inline 00137 sign::sign(int i) 00138 { 00139 mln_precondition(i >= -1); 00140 mln_precondition(i <= 1); 00141 this->v_ = i; 00142 } 00143 00144 inline 00145 sign& 00146 sign::operator=(int i) 00147 { 00148 mln_precondition(i >= -1); 00149 mln_precondition(i <= 1); 00150 this->v_ = i; 00151 return *this; 00152 } 00153 00154 inline 00155 sign::sign(const mln::literal::zero_t&) 00156 { 00157 this->v_ = 0; 00158 } 00159 00160 inline 00161 sign& 00162 sign::operator=(const mln::literal::zero_t&) 00163 { 00164 this->v_ = 0; 00165 return *this; 00166 } 00167 00168 inline 00169 sign::sign(const mln::literal::one_t&) 00170 { 00171 this->v_ = 1; 00172 } 00173 00174 inline 00175 sign& 00176 sign::operator=(const mln::literal::one_t&) 00177 { 00178 this->v_ = 1; 00179 return *this; 00180 } 00181 00182 00183 inline 00184 std::ostream& operator<<(std::ostream& ostr, const sign& i) 00185 { 00186 return ostr << debug::format(i.val_()); 00187 } 00188 00189 inline 00190 bool operator==(const sign& lhs, const sign& rhs) 00191 { 00192 return lhs.val_() == rhs.val_(); 00193 } 00194 00195 inline 00196 bool operator<(const sign& lhs, const sign& rhs) 00197 { 00198 return lhs.val_() == rhs.val_(); 00199 } 00200 00201 # endif // ! MLN_INCLUDE_ONLY 00202 00203 } // end of namespace value 00204 00205 namespace trait 00206 { 00207 00208 template <> 00209 struct value_<mln::value::sign> 00210 { 00211 00212 enum { 00213 dim = 1, 00214 nbits = 2, 00215 card = 3 00216 }; 00217 00218 typedef trait::value::nature::integer nature; 00219 typedef trait::value::kind::gray kind; 00220 typedef trait::value::quant::low quant; 00221 00222 static mln::value::sign min() { return -1; } 00223 static mln::value::sign max() { return 1; } 00224 static mln::value::sign epsilon() { return 0; } 00225 00226 typedef int comp; 00227 00228 typedef int sum; 00229 }; 00230 00231 } // end of namespace trait 00232 00233 } // end of namespace mln 00234 00235 00236 #endif // ! MLN_VALUE_SIGN_HH