00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __PATTERN_HH
00018 # define __PATTERN_HH
00019
00020 # include <cassert>
00021 # include "../strategies/failure.hh"
00022 # include "../type_traits/has_model.hh"
00023
00024 namespace aurelia {
00025
00028 template <typename Model>
00029 struct pattern_concept {
00030 typedef typename Model::type type;
00031 typedef typename Model::build_type build_type;
00032 typedef decltype((std::declval<type&>() =
00033 std::declval<build_type>()))
00034 match_type;
00035
00036 typedef decltype(*(std::declval<type&>()))
00037 builder_type;
00038
00039 #ifdef DOC_GEN
00040 match_type operator=(type&, build_type) throw (failure);
00041 builder_type operator*(type) throw (failure);
00042 #else
00043 static_assert(std::is_convertible<builder_type, build_type>::value,
00044 "builder_type is not convertible to build_type.");
00045
00046 static_assert(std::is_convertible<match_type, build_type>::value,
00047 "builder_type is not convertible to build_type.");
00048 #endif
00049
00051 void match(type pattern) {
00052 try {
00053 pattern = *pattern;
00054 }
00055 catch (failure) {
00056 assert(false);
00057 }
00058 }
00059
00060 typedef void check;
00061 };
00062
00066 template <typename T>
00067 struct pattern_model {
00068 typedef void no_model;
00069 };
00070
00071 template <typename Pool, typename T>
00072 struct is_pattern_traits:
00073 public type_traits::has_model<pattern_model<T> > {
00074 };
00075
00076 }
00077
00078 #endif