|
libpsynth 0.2.1
|
00001 00011 /* 00012 * Copyright (C) 2010 Juan Pedro Bolivar Puente 00013 * 00014 * This file is part of Psychosynth. 00015 * 00016 * Psychosynth is free software: you can redistribute it and/or modify 00017 * it under the terms of the GNU General Public License as published by 00018 * the Free Software Foundation, either version 3 of the License, or 00019 * (at your option) any later version. 00020 * 00021 * Psychosynth is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00024 * GNU General Public License for more details. 00025 * 00026 * You should have received a copy of the GNU General Public License 00027 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00028 * 00029 */ 00030 00031 #ifndef PSYNTH_BASE_CONCEPT_H_ 00032 #define PSYNTH_BASE_CONCEPT_H_ 00033 00034 #include <boost/concept_check.hpp> 00035 00036 namespace psynth 00037 { 00038 namespace base 00039 { 00040 00041 #ifdef BOOST_GIL_USE_CONCEPT_CHECK 00042 #define PSYNTH_CLASS_REQUIRE(type_var, ns, concept) \ 00043 BOOST_CLASS_REQUIRE(type_var, ns, concept); 00044 template <typename C> void psynth_function_requires () 00045 { 00046 boost::function_requires<C>(); 00047 } 00048 #else 00049 #define PSYNTH_CLASS_REQUIRE(T, NS, C) 00050 template <typename C> void psynth_function_requires() {} 00051 #endif 00052 00061 template <typename T> 00062 struct DefaultConstructible 00063 { 00064 void constraints () { 00065 boost::function_requires <boost::DefaultConstructibleConcept<T> >(); 00066 } 00067 }; 00068 00078 template <typename T> 00079 struct CopyConstructible 00080 { 00081 void constraints () { 00082 boost::function_requires<boost::CopyConstructibleConcept<T> >(); 00083 } 00084 }; 00085 00095 template <typename T> 00096 struct Assignable 00097 { 00098 void constraints() { 00099 boost::function_requires<boost::AssignableConcept<T> >(); 00100 } 00101 }; 00102 00112 template <typename T> 00113 struct EqualityComparable 00114 { 00115 void constraints() { 00116 boost::function_requires<boost::EqualityComparableConcept<T> >(); 00117 } 00118 }; 00119 00127 template <typename T, typename U> 00128 struct SameType 00129 { 00130 void constraints() { 00131 BOOST_STATIC_ASSERT((boost::is_same<T,U>::value_core)); 00132 } 00133 }; 00134 00143 template <typename T> 00144 struct Swappable 00145 { 00146 void constraints() { 00147 using std::swap; 00148 swap (x, y); 00149 } 00150 T x, y; 00151 }; 00152 00161 template <typename T> 00162 struct Regular 00163 { 00164 void constraints() { 00165 psynth_function_requires< boost::DefaultConstructibleConcept<T> >(); 00166 psynth_function_requires< boost::CopyConstructibleConcept<T> >(); 00167 // ==, != 00168 psynth_function_requires< boost::EqualityComparableConcept<T> >(); 00169 psynth_function_requires< boost::AssignableConcept<T> >(); 00170 psynth_function_requires< Swappable<T> >(); 00171 } 00172 }; 00173 00182 template <typename T> 00183 struct Metafunction 00184 { 00185 void constraints() { 00186 typedef typename T::type type; 00187 } 00188 }; 00189 00190 } /* namespace base */ 00191 } /* namespace psynth */ 00192 00193 #endif /* PSYNTH_BASE_CONCEPT_H_ */ 00194
1.7.4