GenericItem.H
00001
00002
00003 #ifdef INVT_USE_CPPOX//we need c++ 0X features for this to work
00004 #ifndef GENERICITEM_H_DEFINED
00005 #define GENERICITEM_H_DEFINED
00006
00007 #include "GenericUtils/ProcessFunctor.H"
00008 #include <memory>
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 template <template <typename...> class C, typename... FunctorTypes>
00022 class GenericItemBase
00023 {
00024 public:
00025
00026 virtual ~GenericItemBase() { };
00027
00028
00029
00030
00031 virtual void runProcessFunctor(ProcessFunctor<C, FunctorTypes...>& func, const bool convert = false) = 0;
00032
00033 protected:
00034
00035 GenericItemBase() { };
00036 GenericItemBase(const GenericItemBase& rhs) { };
00037 void operator=(const GenericItemBase& rhs) { };
00038 };
00039
00040
00041
00042
00043 template <template <typename...> class C, typename T, typename... FunctorTypes>
00044 class GenericItemImpl : public GenericItemBase<C, FunctorTypes...>
00045 {
00046 public:
00047
00048 GenericItemImpl(const C<T>& item) : itsItem(item) { };
00049
00050
00051
00052
00053 void runProcessFunctor(ProcessFunctor<C, FunctorTypes...>& func, const bool convert = false)
00054 { func(itsItem, convert); }
00055
00056 private:
00057 C<T> itsItem;
00058 };
00059
00060
00061
00062
00063 template <template <typename...> class C, typename... FunctorTypes>
00064 class GenericItem
00065 {
00066 public:
00067
00068 template <class T>
00069 static GenericItem make(const C<T>& item)
00070 {
00071 GenericItem fs;
00072 fs.itsGenItem.reset(new GenericItemImpl<C, T, FunctorTypes...>(item));
00073 return fs;
00074 }
00075
00076
00077
00078
00079 void runProcessFunctor(ProcessFunctor<C, FunctorTypes...>& func, const bool convert = false)
00080 {
00081 itsGenItem->runProcessFunctor(func, convert);
00082 };
00083
00084 private:
00085
00086 GenericItem() : itsGenItem() { };
00087
00088 std::shared_ptr<GenericItemBase<C, FunctorTypes...> > itsGenItem;
00089 };
00090
00091 #endif
00092 #endif