PFUNC 1.0
pfunc/generator.hpp
Go to the documentation of this file.
00001 #ifndef PFUNC_GENERATOR_S_HPP
00002 #define PFUNC_GENERATOR_S_HPP
00003 
00004 /***************************************************************************
00005  * \file generator.hpp Generate the library instance description.
00006  * \author Prabhanjan Kambadur
00007  */
00008  
00009 #include <pfunc/attribute.hpp>
00010 #include <pfunc/group.hpp>
00011 #include <pfunc/task.hpp>
00012 #include <pfunc/taskmgr.hpp>
00013 #include <pfunc/task_queue_set.hpp>
00014 #include <pfunc/trampolines.hpp>
00015 #include <functional>
00016 
00017 
00018 namespace pfunc {
00019 
00021   struct default_tag {};
00022 
00024   struct sched_tag : public default_tag {};
00025 
00027   struct comp_tag : public default_tag {};
00028 
00030   struct func_tag : public default_tag {};
00031   
00036   template <typename T> struct default_type {};
00037 
00039   template <> struct default_type <sched_tag> { 
00040     typedef cilkS type; 
00041   };
00042 
00044   template <> struct default_type <comp_tag> { 
00045     typedef std::less<int> type; 
00046   };
00047 
00049   template <> struct default_type <func_tag> { 
00050     typedef virtual_functor type; 
00051   };
00052 
00057 #define GENERATE_PFUNC_TYPES() \
00058     typedef detail::attribute<priority_type, compare_type>  attribute; \
00059     typedef detail::task <attribute, functor> task; \
00060     typedef detail::taskmgr <task_queue_set, task> taskmgr; \
00061     typedef detail::group group;
00062 
00076   template <typename SchedPolicyName,
00077             typename Compare,
00078             typename Functor>
00079   struct generator {
00080     typedef SchedPolicyName task_queue_set; 
00081     typedef Compare compare_type; 
00082     typedef typename compare_type::first_argument_type priority_type; /* typedef for the priority_type */
00083     typedef Functor functor; 
00085     GENERATE_PFUNC_TYPES()
00086   };
00087 
00093   struct use_default {};
00094 
00096   template <> 
00097   struct generator <use_default, use_default, use_default> {
00098     typedef default_type<sched_tag>::type task_queue_set;
00099     typedef default_type<comp_tag>::type compare_type;
00100     typedef compare_type::first_argument_type priority_type;/* typedef for the priority_type */
00101     typedef default_type<func_tag>::type functor;
00103     GENERATE_PFUNC_TYPES()
00104   };
00105 
00107   template <typename SchedPolicyName>
00108   struct generator <SchedPolicyName, use_default, use_default> {
00109     typedef SchedPolicyName task_queue_set;
00110     typedef typename default_type<comp_tag>::type compare_type;
00111     typedef typename compare_type::first_argument_type priority_type;/* typedef for the priority_type */
00112     typedef typename default_type<func_tag>::type functor;
00114     GENERATE_PFUNC_TYPES()
00115   };
00116 
00117 
00119   template <typename Compare>
00120   struct generator <use_default, Compare, use_default> {
00121     typedef default_type<sched_tag>::type task_queue_set;
00122     typedef Compare compare_type;
00123     typedef typename compare_type::first_argument_type priority_type;/* typedef for the priority_type */
00124     typedef default_type<func_tag>::type functor;
00126     GENERATE_PFUNC_TYPES()
00127   };
00128 
00129 
00131   template <typename Functor>
00132   struct generator <use_default, use_default, Functor> {
00133     typedef default_type<sched_tag>::type task_queue_set;
00134     typedef default_type<comp_tag>::type compare_type;
00135     typedef compare_type::first_argument_type priority_type;/* typedef for the priority_type */
00136     typedef Functor functor;
00138     GENERATE_PFUNC_TYPES()
00139   };
00140 
00141 
00143   template <typename SchedPolicyName, typename Compare>
00144   struct generator <SchedPolicyName, Compare, use_default> {
00145     typedef SchedPolicyName task_queue_set;
00146     typedef Compare compare_type;
00147     typedef typename compare_type::first_argument_type priority_type;/* typedef for the priority_type */
00148     typedef default_type<func_tag>::type functor;
00150     GENERATE_PFUNC_TYPES()
00151   };
00152 
00153 
00155   template <typename SchedPolicyName, typename Functor>
00156   struct generator <SchedPolicyName, use_default, Functor> {
00157     typedef SchedPolicyName task_queue_set;
00158     typedef default_type<comp_tag>::type compare_type;
00159     typedef compare_type::first_argument_type priority_type;/* typedef for the priority_type */
00160     typedef Functor functor;
00162     GENERATE_PFUNC_TYPES()
00163   };
00164 
00165 
00167   template <typename Compare, typename Functor>
00168   struct generator <use_default, Compare, Functor> {
00169     typedef default_type<sched_tag>::type task_queue_set;
00170     typedef Compare compare_type;
00171     typedef typename compare_type::first_argument_type priority_type;/* typedef for the priority_type */
00172     typedef Functor functor;
00174     GENERATE_PFUNC_TYPES()
00175   };
00176 
00177 } /* namespace pfunc */
00178 
00179 #endif // PFUNC_GENERATOR_S_HPP