OKlibrary  0.2.1.6
Variables.hpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 26.5.2005 (Swansea)
00002 /* Copyright 2005 - 2007, 2011 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 
00013 #ifndef VARIABLES_095tYb
00014 #define VARIABLES_095tYb
00015 
00016 #include <OKlib/traits/TypeTraits.hpp>
00017 
00018 #include <OKlib/Concepts/LibraryBasics.hpp>
00019 #include <OKlib/Satisfiability/ProblemInstances/Variables/traits/index_type.hpp>
00020 
00021 namespace OKlib {
00022   namespace Concepts {
00023 
00024     struct Variables_tag : virtual BasicRequirements_tag, virtual FullyConstructible_tag,  virtual EqualitySubstitutable_tag, virtual LinearOrder_tag {};
00025 
00049     template <typename Var>
00050     struct Variables {
00051       void constraints() {
00052         OKLIB_MODELS_CONCEPT_TAG(Var, Variables);
00053 
00054         OKLIB_MODELS_CONCEPT_REQUIRES(Var, BasicRequirements);
00055         OKLIB_MODELS_CONCEPT_TAG(Var, BasicRequirements);
00056         OKLIB_MODELS_CONCEPT_REQUIRES(Var, FullyConstructible);
00057         OKLIB_MODELS_CONCEPT_TAG(Var, FullyConstructible);
00058         OKLIB_MODELS_CONCEPT_REQUIRES(Var, EqualitySubstitutable);
00059         OKLIB_MODELS_CONCEPT_TAG(Var, EqualitySubstitutable);
00060         OKLIB_MODELS_CONCEPT_REQUIRES(Var, LinearOrder);
00061         OKLIB_MODELS_CONCEPT_TAG(Var, LinearOrder);
00062 
00063         bool b;
00064         b = static_cast<bool>(v);
00065         b = static_cast<bool>(vc);
00066       }
00067 
00068       Var v;
00069       const Var vc;
00070     };
00071 
00072     class Variables_Archetype {
00073       typedef OKlib::Concepts::convertible_to_bool convertible_to_bool;
00074     public :
00075       typedef Variables_tag concept_tag;
00076       convertible_to_bool operator ==(const Variables_Archetype&) const { return convertible_to_bool(); }
00077       convertible_to_bool operator !=(const Variables_Archetype&) const { return convertible_to_bool(); }
00078       convertible_to_bool operator <(const Variables_Archetype&) const { return convertible_to_bool(); }
00079       convertible_to_bool operator >(const Variables_Archetype&) const { return convertible_to_bool(); }
00080       convertible_to_bool operator <=(const Variables_Archetype&) const { return convertible_to_bool(); }
00081       convertible_to_bool operator >=(const Variables_Archetype&) const { return convertible_to_bool(); }
00082       operator bool() const { return bool(); }
00083     };
00084     
00085     // --------------------------------------------------------------------------------------------------------------------------------------
00086 
00087     struct VariablesWithIndex_tag : virtual Variables_tag {};
00088     
00095     template <typename Var>
00096     struct VariablesWithIndex {
00097 
00098       typedef typename OKlib::Variables::traits::index_type<Var>::type index_type;
00099       BOOST_STATIC_ASSERT(::OKlib::traits::is_unqualified_signedunsigned_integral<index_type>::value);
00100 
00101       void constraints() {
00102         OKLIB_MODELS_CONCEPT_TAG(Var, VariablesWithIndex);
00103 
00104         OKLIB_MODELS_CONCEPT_REQUIRES(Var, Variables);
00105         OKLIB_MODELS_CONCEPT_TAG(Var, Variables);
00106 
00107         index_type ind;
00108         ind = static_cast<index_type>(v);
00109         ind = static_cast<index_type>(vc);
00110       }
00111 
00112       Var v;
00113       const Var vc;
00114     };
00115 
00116     struct VariablesWithIndex_Archetype : Variables_Archetype {
00117       typedef VariablesWithIndex_tag concept_tag;
00118       typedef int index_type; // ToDo: Can this be made more generic?
00119       operator index_type() const { return index_type(); }
00120     };
00121 
00122     // --------------------------------------------------------------------------------------------------------------------------------------
00123 
00124     struct VariablesAsIndex_tag : virtual VariablesWithIndex_tag {};
00125     
00132     template <typename Var>
00133     struct VariablesAsIndex {
00134 
00135       typedef typename OKlib::Variables::traits::index_type<Var>::type index_type;
00136 
00137       void constraints() {
00138         OKLIB_MODELS_CONCEPT_TAG(Var, VariablesAsIndex);
00139 
00140         OKLIB_MODELS_CONCEPT_REQUIRES(Var, VariablesWithIndex);
00141         OKLIB_MODELS_CONCEPT_TAG(Var, VariablesWithIndex);
00142 
00143         dummy_use_v(Var(i));
00144         dummy_use_v(Var(ic));
00145       }
00146 
00147       index_type i; const index_type ic;
00148       void dummy_use_v(const Var& v) {}
00149     };
00150 
00151     struct VariablesAsIndex_Archetype : VariablesWithIndex_Archetype {
00152       typedef VariablesAsIndex_tag concept_tag;
00153       VariablesAsIndex_Archetype() {}
00154       explicit VariablesAsIndex_Archetype(index_type) {}
00155     };
00156   }
00157 
00158 }
00159 
00160 #endif