• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

sign.hh

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     inline
00112     sign::sign()
00113     {
00114     }
00115 
00116     inline
00117     sign::operator int() const
00118     {
00119       return this->v_;
00120     }
00121 
00122     inline
00123     int
00124     sign::val_() const
00125     {
00126       return this->v_;
00127     }
00128 
00129     inline
00130     sign::sign(int i)
00131     {
00132       mln_precondition(i >= -1);
00133       mln_precondition(i <= 1);
00134       this->v_ = i;
00135     }
00136 
00137     inline
00138     sign&
00139     sign::operator=(int i)
00140     {
00141       mln_precondition(i >= -1);
00142       mln_precondition(i <= 1);
00143       this->v_ = i;
00144       return *this;
00145     }
00146 
00147     inline
00148     sign::sign(const mln::literal::zero_t&)
00149     {
00150       this->v_ = 0;
00151     }
00152 
00153     inline
00154     sign&
00155     sign::operator=(const mln::literal::zero_t&)
00156     {
00157       this->v_ = 0;
00158       return *this;
00159     }
00160 
00161     inline
00162     sign::sign(const mln::literal::one_t&)
00163     {
00164       this->v_ = 1;
00165     }
00166 
00167     inline
00168     sign&
00169     sign::operator=(const mln::literal::one_t&)
00170     {
00171       this->v_ = 1;
00172       return *this;
00173     }
00174 
00175     const sign sign::zero = 0;
00176 
00177     const sign sign::one = 1;
00178 
00179     inline
00180     std::ostream& operator<<(std::ostream& ostr, const sign& i)
00181     {
00182       return ostr << debug::format(i.val_());
00183     }
00184 
00185     inline
00186     bool operator==(const sign& lhs, const sign& rhs)
00187     {
00188       return lhs.val_() == rhs.val_();
00189     }
00190 
00191     inline
00192     bool operator<(const sign& lhs, const sign& rhs)
00193     {
00194       return lhs.val_() == rhs.val_();
00195     }
00196 
00197 # endif // ! MLN_INCLUDE_ONLY
00198 
00199   } // end of namespace value
00200 
00201   namespace trait
00202   {
00203 
00204     template <>
00205     struct value_<mln::value::sign>
00206     {
00207 
00208       enum {
00209         dim = 1,
00210         nbits = 2,
00211         card  = 3
00212       };
00213 
00214       typedef trait::value::nature::integer nature;
00215       typedef trait::value::kind::gray      kind;
00216       typedef trait::value::quant::low   quant;
00217 
00218       static mln::value::sign min() { return -1; }
00219       static mln::value::sign max() { return 1; }
00220       static mln::value::sign epsilon() { return 0; }
00221 
00222       typedef int comp;
00223 
00224       typedef int sum;
00225     };
00226 
00227   } // end of namespace trait
00228 
00229 } // end of namespace mln
00230 
00231 
00232 #endif // ! MLN_VALUE_SIGN_HH

Generated on Thu Sep 8 2011 18:32:26 for Milena (Olena) by  doxygen 1.7.1