OKlibrary  0.2.1.6
TrivialLiterals.hpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 9.12.2006 (Swansea)
00002 /* Copyright 2006 - 2007, 2009 Oliver Kullmann
00003 This file is part of the OKlibrary. OKlibrary is free software; you can redistribute
00004 it and/or modify it under the terms of the GNU General Public License as published by
00005 the Free Software Foundation and included in this library; either version 3 of the
00006 License, or any later version. */
00007 
00015 #ifndef TRIVIALLITERALS_jdjNNqpqoh7u5
00016 #define TRIVIALLITERALS_jdjNNqpqoh7u5
00017 
00018 #include <cstdlib>
00019 
00020 #include <OKlib/Concepts/traits/concept_tag.hpp>
00021 
00022 #include <OKlib/Concepts/Variables.hpp>
00023 #include <OKlib/Concepts/Literals.hpp>
00024 #include <OKlib/Concepts/JoinedConceptTags.hpp>
00025 
00026 #include <OKlib/Satisfiability/ProblemInstances/Variables/TrivialVariables.hpp>
00027 #include <OKlib/Satisfiability/ProblemInstances/Conditions/AtomicConditions/TrivialAtomicConditions.hpp>
00028 
00029 #include <OKlib/Satisfiability/ProblemInstances/Literals/traits/var_type.hpp>
00030 #include <OKlib/Satisfiability/ProblemInstances/Literals/traits/cond_type.hpp>
00031 #include <OKlib/Satisfiability/ProblemInstances/Literals/var.hpp>
00032 #include <OKlib/Satisfiability/ProblemInstances/Literals/cond.hpp>
00033 
00034 
00035 namespace OKlib {
00036   namespace Literals {
00037 
00038     typedef signed char Literals_signed_char;
00039     typedef short int Literals_short_int;
00040     typedef int Literals_int;
00041     typedef long int Literals_long_int;
00042 
00043     namespace traits {
00044 
00045       template <>
00046       struct var_type<Literals_signed_char> { typedef OKlib::Variables::Variables_signed_char type; };
00047       template <>
00048       struct var_type<Literals_short_int> { typedef OKlib::Variables::Variables_short_int type; };
00049       template <>
00050       struct var_type<Literals_int> { typedef OKlib::Variables::Variables_int type; };
00051       template <>
00052       struct var_type<Literals_long_int> { typedef OKlib::Variables::Variables_long_int type; };
00053 
00054       template <>
00055       struct cond_type<Literals_signed_char> { typedef OKlib::AtomicConditions::AC_bool type; };
00056       template <>
00057       struct cond_type<Literals_short_int> { typedef OKlib::AtomicConditions::AC_bool type; };
00058       template <>
00059       struct cond_type<Literals_int> { typedef OKlib::AtomicConditions::AC_bool type; };
00060       template <>
00061       struct cond_type<Literals_long_int> { typedef OKlib::AtomicConditions::AC_bool type; };
00062 
00063     }
00064 
00065     template <>
00066     inline traits::var_type<Literals_signed_char>::type var(const Literals_signed_char& x) { return std::abs(x); }
00067     template <>
00068     inline traits::var_type<Literals_short_int>::type var(const Literals_short_int& x) { return std::abs(x); }
00069     template <>
00070     inline traits::var_type<Literals_int>::type var(const Literals_int& x) { return std::abs(x); }
00071     template <>
00072     inline traits::var_type<Literals_long_int>::type var(const Literals_long_int& x) { return std::abs(x); }
00073 
00074     template <>
00075     inline traits::cond_type<Literals_signed_char>::type cond(const Literals_signed_char& x) { return x > 0; }
00076     template <>
00077     inline traits::cond_type<Literals_short_int>::type cond(const Literals_short_int& x) { return x > 0; }
00078     template <>
00079     inline traits::cond_type<Literals_int>::type cond(const Literals_int& x) { return x > 0; }
00080     template <>
00081     inline traits::cond_type<Literals_long_int>::type cond(const Literals_long_int& x) { return x > 0; }
00082 
00083     template <>
00084     inline void set_cond(Literals_signed_char& x, const traits::cond_type<Literals_signed_char>::type& cond) {
00085       if (cond) x = std::abs(x);
00086       else x = - std::abs(x);
00087     }
00088     template <>
00089     inline void set_cond(Literals_short_int& x, const traits::cond_type<Literals_short_int>::type& cond) {
00090       if (cond) x = std::abs(x);
00091       else x = - std::abs(x);
00092     }
00093     template <>
00094     inline void set_cond(Literals_int& x, const traits::cond_type<Literals_int>::type& cond) {
00095       if (cond) x = std::abs(x);
00096       else x = - std::abs(x);
00097     }
00098     template <>
00099     inline void set_cond(Literals_long_int& x, const traits::cond_type<Literals_long_int>::type& cond) {
00100       if (cond) x = std::abs(x);
00101       else x = - std::abs(x);
00102     }
00103 
00104   }
00105 
00106   namespace Concepts {
00107     namespace traits {
00108       
00109       // Since Literals::Literals_signed_char is the same type as Variables::Variables_signed_char, the definitions from Variables/TrivialVariables.hpp must be used here.
00110 
00111     }
00112   }
00113 }
00114 
00115 #endif