$treeview $search $mathjax
Palabos  Version 1.1
$projectbrief
$projectbrief
$searchbox

processorIdentifiers2D.h

Go to the documentation of this file.
00001 /* This file is part of the Palabos library.
00002  *
00003  * Copyright (C) 2011 FlowKit Sarl
00004  * Avenue de Chailly 23
00005  * 1012 Lausanne, Switzerland
00006  * E-mail contact: contact@flowkit.com
00007  *
00008  * The most recent release of Palabos can be downloaded at 
00009  * <http://www.palabos.org/>
00010  *
00011  * The library Palabos is free software: you can redistribute it and/or
00012  * modify it under the terms of the GNU Affero General Public License as
00013  * published by the Free Software Foundation, either version 3 of the
00014  * License, or (at your option) any later version.
00015  *
00016  * The library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Affero General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Affero General Public License
00022  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00023 */
00024 
00025 
00026 #ifndef PROCESSOR_IDENTIFIERS_2D_H
00027 #define PROCESSOR_IDENTIFIERS_2D_H
00028 
00029 #include "core/globalDefs.h"
00030 #include "core/plbTypenames.h"
00031 #include "core/util.h"
00032 #include "atomicBlock/dataProcessingFunctional2D.h"
00033 #include <vector>
00034 #include <string>
00035 #include <map>
00036 
00037 namespace plb {
00038 
00039 namespace meta {
00040 
00041 struct ProcessorFactory2D {
00042     virtual ~ProcessorFactory2D() { }
00043     virtual BoxProcessingFunctional2D* create(std::string data) const =0;
00044 };
00045 
00046 class ProcessorRegistration2D {
00047 public:
00048     struct Entry {
00049         Entry(std::string name_, ProcessorFactory2D* factory_)
00050             : name(name_),
00051               factory(factory_)
00052         { }
00053         std::string name;
00054         ProcessorFactory2D* factory;
00055     };
00056     struct EntryLessThan {
00057         bool operator()(Entry const& entry1, Entry const& entry2) const {
00058             return entry1.name < entry2.name;
00059         }
00060     };
00061     typedef std::map<Entry,int,EntryLessThan> EntryMap;
00062 public:
00063     ProcessorRegistration2D() { }
00064     ~ProcessorRegistration2D();
00065     int announce(std::string nameOfProcessor, ProcessorFactory2D* factory_=0);
00066     int getId(std::string name) const;
00067     int getNumId() const;
00068     std::string getName(int id) const;
00069     BoxProcessingFunctional2D* create(std::string procName, std::string data);
00070     EntryMap::const_iterator begin() const;
00071     EntryMap::const_iterator end() const;
00072 private:
00073     ProcessorRegistration2D(ProcessorRegistration2D const& rhs) { }
00074     ProcessorRegistration2D& operator= (
00075             ProcessorRegistration2D const& rhs )
00076     { return *this; }
00077 private:
00078     EntryMap processorByName;
00079     std::vector<Entry> processorByNumber;
00080 };
00081 
00082 ProcessorRegistration2D& processorRegistration2D();
00083 
00084 template<class FunctionalT>
00085 class FunctionalFactory2D : public ProcessorFactory2D
00086 {
00087     virtual BoxProcessingFunctional2D* create(std::string data) const {
00088         BoxProcessingFunctional2D* functional = new FunctionalT;
00089         functional->unserialize(data);
00090         return functional;
00091     }
00092 };
00093 
00094 template<class FunctionalT>
00095 int registerProcessor2D(std::string name) {
00096     return processorRegistration2D().announce(name, new FunctionalFactory2D<FunctionalT>);
00097 }
00098 
00099 template <
00100     class FunctionalT, typename T >
00101 int registerProcessor2D(std::string name) {
00102     std::string fullName =
00103         name + "_" + std::string(NativeType<T>::getName());
00104     return processorRegistration2D().announce(fullName, new FunctionalFactory2D<FunctionalT>);
00105 }
00106 
00107 template <
00108     class FunctionalT,
00109     typename T1, typename T2 >
00110 int registerProcessor2D(std::string name) {
00111     std::string fullName =
00112         name + "_" + std::string(NativeType<T1>::getName())+ "_" + std::string(NativeType<T2>::getName());
00113     return processorRegistration2D().announce(fullName, new FunctionalFactory2D<FunctionalT>);
00114 }
00115 
00116 template <
00117     class FunctionalT,
00118     typename T, int val >
00119 int registerProcessor2D(std::string name) {
00120     std::string fullName =
00121         name + "_" + std::string(NativeType<T>::getName()) + "_" + util::val2str(val);
00122     return processorRegistration2D().announce(fullName, new FunctionalFactory2D<FunctionalT>);
00123 }
00124 
00125 template <
00126     class FunctionalT, typename T, template<typename U> class Descriptor >
00127 int registerProcessor2D(std::string name) {
00128     std::string fullName =
00129         name + "_" + std::string(NativeType<T>::getName()) + "_" + std::string(Descriptor<T>::name);
00130     return processorRegistration2D().announce(fullName, new FunctionalFactory2D<FunctionalT>);
00131 }
00132 
00133 template <
00134     class FunctionalT,
00135     typename T, template<typename U> class Descriptor, int val1, int val2 >
00136 int registerProcessor2D(std::string name) {
00137     std::string fullName =
00138         name + "_" + std::string(NativeType<T>::getName()) + "_" +
00139         std::string(Descriptor<T>::name) + "_" + util::val2str(val1) + "_" + util::val2str(val2);
00140     return processorRegistration2D().announce(fullName, new FunctionalFactory2D<FunctionalT>);
00141 }
00142 
00143 template <
00144     class FunctionalT,
00145     typename T, template<typename U> class Descriptor, int val1, int val2, int val3 >
00146 int registerProcessor2D(std::string name) {
00147     std::string fullName =
00148         name + "_" + std::string(NativeType<T>::getName()) + "_" +
00149         std::string(Descriptor<T>::name) + "_" + util::val2str(val1) + "_" + util::val2str(val2) + "_" + util::val2str(val3);
00150     return processorRegistration2D().announce(fullName, new FunctionalFactory2D<FunctionalT>);
00151 }
00152 
00153 }  // namespace meta
00154 
00155 }  // namespace plb
00156 
00157 #endif  // PROCESSOR_IDENTIFIERS_2D_H