build.hh

00001 // This file is a part of Aurelia.
00002 // Copyright (C) 2010  Valentin David
00003 // Copyright (C) 2010  University of Bergen
00004 //
00005 // This program is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 #ifndef __BUILD_HH
00018 # define __BUILD_HH
00019 
00020 # include "../../patterns/pattern.hh"
00021 # include "../strategies.hh"
00022 
00023 namespace aurelia {
00024 
00028   template <typename T>
00029   struct build_strategy {
00030     typedef typename pattern_model<T>::model pat_mod;
00031     typedef typename pattern_concept<pat_mod>::check require;
00032     T pat;
00033   public:
00034     build_strategy(const T& pat): pat(pat) {
00035     }
00036 
00037     template <typename Y>
00038     typename pat_mod::build_type operator()(const Y&) const {
00039       return *pat;
00040     }
00041   };
00042 
00043   template <typename Pool>
00044   struct build_strategy<untyped_term<Pool> > {
00045   private:
00046     untyped_term<Pool> t;
00047   public:
00048     build_strategy(const untyped_term<Pool>& t): t(t) {
00049     }
00050 
00051     template <typename T>
00052     untyped_term<Pool> operator()(const T&) const {
00053       return t;
00054     }
00055   };
00056   /* @} */
00057 
00061   template <typename Pool, typename List>
00062   build_strategy<untyped_pattern<Pool, List> >
00063   operator!(const untyped_pattern<Pool, List>& p) {
00064     return build_strategy<untyped_pattern<Pool, List> >(p);
00065   }
00066 
00070   template <typename T>
00071   build_strategy<variable<T> > operator!(const variable<T>& v) {
00072     return build_strategy<variable<T> >(v);
00073   }
00074 
00075   template <typename Pattern,
00076             typename PattermModel = typename pattern_model<Pattern>::model>
00077   build_strategy<Pattern> operator!(const Pattern& pattern) {
00078     return build_strategy<Pattern>(pattern);
00079   }
00080 }
00081 
00082 #endif