Loki 라이브러리
Loki<library> 다운로드 링크:
http://loki-lib.sourceforge.net/index.php?n=Main.Download
※ 직접 다운받기:
loki-book-1st-edition-version.zip
※ Loki 라이브러리 라이선스:
MIT License
이 문서는, Loki 라이브러리의 Reference 폴더 내에 들어있는, 헤더 파일과 cpp 파일을 담고 있습니다.
차례
-
AbstractFactory.h 보기
-
-
- #ifndef ABSTRACTFACTORY_INC_
- #define ABSTRACTFACTORY_INC_
-
- #include
- #include
- #include
-
- #include
-
- namespace Loki
- {
-
-
- template <class T>
- class AbstractFactoryUnit
- {
- public:
- virtual T* DoCreate(Type2Type<T>) = 0;
- virtual ~AbstractFactoryUnit() {}
- };
-
-
- template
- <
- class TList,
- template <class> class Unit = AbstractFactoryUnit
- >
- class AbstractFactory : public GenScatterHierarchy<TList, Unit>
- {
- public:
- typedef TList ProductList;
-
- template <class T> T* Create()
- {
- Unit<T>& unit = *this;
- return unit.DoCreate(Type2Type<T>());
- }
- };
-
-
- template <class ConcreteProduct, class Base>
- class OpNewFactoryUnit : public Base
- {
- typedef typename Base::ProductList BaseProductList;
-
- protected:
- typedef typename BaseProductList::Tail ProductList;
-
- public:
- typedef typename BaseProductList::Head AbstractProduct;
- ConcreteProduct* DoCreate(Type2Type<AbstractProduct>)
- {
- return new ConcreteProduct;
- }
- };
-
-
- template <class ConcreteProduct, class Base>
- class PrototypeFactoryUnit : public Base
- {
- typedef typename Base::ProductList BaseProductList;
-
- protected:
- typedef typename BaseProductList::Tail ProductList;
-
- public:
- typedef typename BaseProductList::Head AbstractProduct;
-
- PrototypeFactoryUnit(AbstractProduct* p = 0)
- : pPrototype_(p)
- {}
-
- friend void DoGetPrototype(const PrototypeFactoryUnit& me,
- AbstractProduct*& pPrototype)
- { pPrototype = me.pPrototype_; }
-
- friend void DoSetPrototype(PrototypeFactoryUnit& me,
- AbstractProduct* pObj)
- { me.pPrototype_ = pObj; }
-
- template <class U>
- void GetPrototype(U*& p)
- { return DoGetPrototype(*this, p); }
-
- template <class U>
- void SetPrototype(U* pObj)
- { DoSetPrototype(*this, pObj); }
-
- AbstractProduct* DoCreate(Type2Type<AbstractProduct>)
- {
- assert(pPrototype_);
- return pPrototype_->Clone();
- }
-
- private:
- AbstractProduct* pPrototype_;
- };
-
-
- template
- <
- class AbstractFact,
- template <class, class> class Creator = OpNewFactoryUnit,
- class TList = typename AbstractFact::ProductList
- >
- class ConcreteFactory
- : public GenLinearHierarchy<
- typename TL::Reverse<TList>::Result, Creator, AbstractFact>
- {
- public:
- typedef typename AbstractFact::ProductList ProductList;
- typedef TList ConcreteProductList;
- };
-
- }
-
-
- #endif
-
AbstractFactory.h 접기
-
AssocVector.h 보기
-
- #ifndef ASSOCVECTOR_INC_
- #define ASSOCVECTOR_INC_
-
- #include
- #include
- #include
- #include
-
- namespace Loki
- {
-
- namespace Private
- {
- template <class Value, class C>
- class AssocVectorCompare : public C
- {
- typedef std::pair<typename C::first_argument_type, Value>
- Data;
- typedef typename C::first_argument_type first_argument_type;
-
- public:
- AssocVectorCompare()
- {}
-
- AssocVectorCompare(const C& src) : C(src)
- {}
-
- bool operator()(const first_argument_type& lhs,
- const first_argument_type& rhs) const
- { return C::operator()(lhs, rhs); }
-
- bool operator()(const Data& lhs, const Data& rhs) const
- { return operator()(lhs.first, rhs.first); }
-
- bool operator()(const Data& lhs,
- const first_argument_type& rhs) const
- { return operator()(lhs.first, rhs); }
-
- bool operator()(const first_argument_type& lhs,
- const Data& rhs) const
- { return operator()(lhs, rhs.first); }
- };
- }
-
-
- template
- <
- class K,
- class V,
- class C = std::less<K>,
- class A = std::allocator< std::pair<K, V> >
- >
- class AssocVector
- : private std::vector< std::pair<K, V>, A >
- , private Private::AssocVectorCompare<V, C>
- {
- typedef std::vector<std::pair<K, V>, A> Base;
- typedef Private::AssocVectorCompare<V, C> MyCompare;
-
- public:
- typedef K key_type;
- typedef V mapped_type;
- typedef typename Base::value_type value_type;
-
- typedef C key_compare;
- typedef A allocator_type;
- typedef typename A::reference reference;
- typedef typename A::const_reference const_reference;
- typedef typename Base::iterator iterator;
- typedef typename Base::const_iterator const_iterator;
- typedef typename Base::size_type size_type;
- typedef typename Base::difference_type difference_type;
- typedef typename A::pointer pointer;
- typedef typename A::const_pointer const_pointer;
- typedef typename Base::reverse_iterator reverse_iterator;
- typedef typename Base::const_reverse_iterator const_reverse_iterator;
-
- class value_compare
- : public std::binary_function<value_type, value_type, bool>
- , private key_compare
- {
- friend class AssocVector;
-
- protected:
- value_compare(key_compare pred) : key_compare(pred)
- {}
-
- public:
- bool operator()(const value_type& lhs, const value_type& rhs) const
- { return key_compare::operator()(lhs.first, rhs.first); }
- };
-
-
-
- explicit AssocVector(const key_compare& comp = key_compare(),
- const A& alloc = A())
- : Base(alloc), MyCompare(comp)
- {}
-
- template <class InputIterator>
- AssocVector(InputIterator first, InputIterator last,
- const key_compare& comp = key_compare(),
- const A& alloc = A())
- : Base(first, last, alloc), MyCompare(comp)
- {
- MyCompare& me = *this;
- std::sort(begin(), end(), me);
- }
-
- AssocVector& operator=(const AssocVector& rhs)
- {
- AssocVector(rhs).swap(*this);
- return *this;
- }
-
-
-
- iterator begin() { return Base::begin(); }
- const_iterator begin() const { return Base::begin(); }
- iterator end() { return Base::end(); }
- const_iterator end() const { return Base::end(); }
- reverse_iterator rbegin() { return Base::rbegin(); }
- const_reverse_iterator rbegin() const { return Base::rbegin(); }
- reverse_iterator rend() { return Base::rend(); }
- const_reverse_iterator rend() const { return Base::rend(); }
-
-
- bool empty() const { return Base::empty(); }
- size_type size() const { return Base::size(); }
- size_type max_size() { return Base::max_size(); }
-
-
- mapped_type& operator[](const key_type& key)
- { return insert(value_type(key, mapped_type())).first->second; }
-
-
- std::pair<iterator, bool> insert(const value_type& val)
- {
- bool found(true);
- iterator i(lower_bound(val.first));
-
- if (i == end() || this->operator()(val.first, i->first))
- {
- i = Base::insert(i, val);
- found = false;
- }
- return std::make_pair(i, !found);
- }
-
- iterator insert(iterator pos, const value_type& val)
- {
- if (pos != end() && this->operator()(*pos, val) &&
- (pos == end() - 1 ||
- !this->operator()(val, pos[1]) &&
- this->operator()(pos[1], val)))
- {
- return Base::insert(pos, val);
- }
- return insert(val).first;
- }
-
- template <class InputIterator>
- void insert(InputIterator first, InputIterator last)
- { for (; first != last; ++first) insert(*first); }
-
- void erase(iterator pos)
- { Base::erase(pos); }
-
- size_type erase(const key_type& k)
- {
- iterator i(find(k));
- if (i == end()) return 0;
- erase(i);
- return 1;
- }
-
- void erase(iterator first, iterator last)
- { Base::erase(first, last); }
-
- void swap(AssocVector& other)
- {
- using std::swap;
- Base::swap(other);
- MyCompare& me = *this;
- MyCompare& rhs = other;
- swap(me, rhs);
- }
-
- void clear()
- { Base::clear(); }
-
-
- key_compare key_comp() const
- { return *this; }
-
- value_compare value_comp() const
- {
- const key_compare& comp = *this;
- return value_compare(comp);
- }
-
-
- iterator find(const key_type& k)
- {
- iterator i(lower_bound(k));
- if (i != end() && this->operator()(k, i->first))
- {
- i = end();
- }
- return i;
- }
-
- const_iterator find(const key_type& k) const
- {
- const_iterator i(lower_bound(k));
- if (i != end() && this->operator()(k, i->first))
- {
- i = end();
- }
- return i;
- }
-
- size_type count(const key_type& k) const
- { return find(k) != end(); }
-
- iterator lower_bound(const key_type& k)
- {
- MyCompare& me = *this;
- return std::lower_bound(begin(), end(), k, me);
- }
-
- const_iterator lower_bound(const key_type& k) const
- {
- const MyCompare& me = *this;
- return std::lower_bound(begin(), end(), k, me);
- }
-
- iterator upper_bound(const key_type& k)
- {
- MyCompare& me = *this;
- return std::upper_bound(begin(), end(), k, me);
- }
-
- const_iterator upper_bound(const key_type& k) const
- {
- const MyCompare& me = *this;
- return std::upper_bound(begin(), end(), k, me);
- }
-
- std::pair<iterator, iterator> equal_range(const key_type& k)
- {
- MyCompare& me = *this;
- return std::equal_range(begin(), end(), k, me);
- }
-
- std::pair<const_iterator, const_iterator> equal_range(
- const key_type& k) const
- {
- const MyCompare& me = *this;
- return std::equal_range(begin(), end(), k, me);
- }
-
- friend bool operator==(const AssocVector& lhs, const AssocVector& rhs)
- {
- const Base& me = lhs;
- return me == rhs;
- }
-
- bool operator<(const AssocVector& rhs) const
- {
- const Base& me = *this;
- const Base& yo = rhs;
- return me < yo;
- }
-
- friend bool operator!=(const AssocVector& lhs, const AssocVector& rhs)
- { return !(lhs == rhs); }
-
- friend bool operator>(const AssocVector& lhs, const AssocVector& rhs)
- { return rhs < lhs; }
-
- friend bool operator>=(const AssocVector& lhs, const AssocVector& rhs)
- { return !(lhs < rhs); }
-
- friend bool operator<=(const AssocVector& lhs, const AssocVector& rhs)
- { return !(rhs < lhs); }
- };
-
-
- template <class K, class V, class C, class A>
- void swap(AssocVector<K, V, C, A>& lhs, AssocVector<K, V, C, A>& rhs)
- { lhs.swap(rhs); }
-
- }
-
-
- #endif
-
AssocVector.h 접기
-
DataGenerators.h 보기
-
-
- #ifndef DATAGENERATORS_H
- #define DATAGENERATORS_H
- #include
-
-
-
-
-
- namespace Loki
- {
- namespace TL
- {
- template<typename T>
- struct nameof_type
- {
- const char* operator()()
- {
- return typeid(T).name();
- }
- };
- template<typename T>
- struct sizeof_type
- {
- size_t operator()()
- {
- return sizeof(T);
- }
- };
- template <class TList, template <class> class GenFunc>
- struct IterateTypes;
-
- template <class T1, class T2, template <class> class GenFunc>
- struct IterateTypes<Typelist<T1, T2>, GenFunc>
- {
- typedef IterateTypes<T1, GenFunc> head_t;
- head_t head;
- typedef IterateTypes<T2, GenFunc> tail_t;
- tail_t tail;
- template<class II>
- void operator()(II ii)
- {
- head.operator()(ii);
- tail.operator()(ii);
- }
- };
-
- template <class AtomicType, template <class> class GenFunc>
- struct IterateTypes
- {
- template<class II>
- void operator()(II ii)
- {
- GenFunc<AtomicType> genfunc;
- *ii = genfunc();
- ++ii;
- }
- };
-
- template <template <class> class GenFunc>
- struct IterateTypes<NullType, GenFunc>
- {
- template<class II>
- void operator()(II ii)
- {}
- };
-
- template<typename Types, template <class> class UnitFunc, typename II>
- void iterate_types(II ii)
- {
- Loki::TL::IterateTypes<Types, UnitFunc> it;
- it(ii);
- }
- }
- }
-
- #endif
-
DataGenerators.h 접기
-
EmptyType.h 보기
-
-
- #ifndef EMPTYTYPE_INC_
- #define EMPTYTYPE_INC_
-
- namespace Loki
- {
-
- class EmptyType {};
- }
-
-
- #endif
-
EmptyType.h 접기
-
Factory.h 보기
-
- #ifndef FACTORY_INC_
- #define FACTORY_INC_
-
- #include
- #include
- #include
-
- namespace Loki
- {
-
-
- template <typename IdentifierType, class AbstractProduct>
- struct DefaultFactoryError
- {
- struct Exception : public std::exception
- {
- const char* what() const throw() { return "Unknown Type"; }
- };
-
- static AbstractProduct* OnUnknownType(IdentifierType)
- {
- throw Exception();
- }
- };
-
-
- template
- <
- class AbstractProduct,
- typename IdentifierType,
- typename ProductCreator = AbstractProduct* (*)(),
- template<typename, class>
- class FactoryErrorPolicy = DefaultFactoryError
- >
- class Factory
- : public FactoryErrorPolicy<IdentifierType, AbstractProduct>
- {
- public:
- bool Register(const IdentifierType& id, ProductCreator creator)
- {
- return associations_.insert(
- typename IdToProductMap::value_type(id, creator)).second;
- }
-
- bool Unregister(const IdentifierType& id)
- {
- return associations_.erase(id) == 1;
- }
-
- AbstractProduct* CreateObject(const IdentifierType& id)
- {
- typename IdToProductMap::iterator i = associations_.find(id);
- if (i != associations_.end())
- {
- return (i->second)();
- }
- return this->OnUnknownType(id);
- }
-
- private:
- typedef AssocVector<IdentifierType, ProductCreator> IdToProductMap;
- IdToProductMap associations_;
- };
-
-
- template
- <
- class AbstractProduct,
- class ProductCreator =
- AbstractProduct* (*)(const AbstractProduct*),
- template<typename, class>
- class FactoryErrorPolicy = DefaultFactoryError
- >
- class CloneFactory
- : public FactoryErrorPolicy<TypeInfo, AbstractProduct>
- {
- public:
- bool Register(const TypeInfo& ti, ProductCreator creator)
- {
- return associations_.insert(
- typename IdToProductMap::value_type(ti, creator)).second;
- }
-
- bool Unregister(const TypeInfo& id)
- {
- return associations_.erase(id) == 1;
- }
-
- AbstractProduct* CreateObject(const AbstractProduct* model)
- {
- if (model == 0) return 0;
-
- typename IdToProductMap::iterator i =
- associations_.find(typeid(*model));
- if (i != associations_.end())
- {
- return (i->second)(model);
- }
- return this->OnUnknownType(typeid(*model));
- }
-
- private:
- typedef AssocVector<TypeInfo, ProductCreator> IdToProductMap;
- IdToProductMap associations_;
- };
- }
-
-
- #endif
-
Factory.h 접기
-
Functor.h 보기
-
-
- #ifndef FUNCTOR_INC_
- #define FUNCTOR_INC_
-
- #include
- #include
- #include
- #include
- #include
- #include
-
- namespace Loki
- {
-
- namespace Private
- {
- template <typename R, template <class> class ThreadingModel>
- struct FunctorImplBase : public SmallObject<ThreadingModel>
- {
- typedef R ResultType;
-
- typedef EmptyType Parm1;
- typedef EmptyType Parm2;
- typedef EmptyType Parm3;
- typedef EmptyType Parm4;
- typedef EmptyType Parm5;
- typedef EmptyType Parm6;
- typedef EmptyType Parm7;
- typedef EmptyType Parm8;
- typedef EmptyType Parm9;
- typedef EmptyType Parm10;
- typedef EmptyType Parm11;
- typedef EmptyType Parm12;
- typedef EmptyType Parm13;
- typedef EmptyType Parm14;
- typedef EmptyType Parm15;
-
- virtual FunctorImplBase* DoClone() const = 0;
- template <class U>
- static U* Clone(U* pObj)
- {
- if (!pObj) return 0;
- U* pClone = static_cast<U*>(pObj->DoClone());
- assert(typeid(*pClone) == typeid(*pObj));
- return pClone;
- }
- };
- }
-
-
- #define DEFINE_CLONE_FUNCTORIMPL(Cls) \
- virtual Cls* DoClone() const { return new Cls(*this); }
-
-
- template <typename R, class TList,
- template <class> class ThreadingModel = DEFAULT_THREADING>
- class FunctorImpl;
-
-
- template <typename R, template <class> class ThreadingModel>
- class FunctorImpl<R, NullType, ThreadingModel>
- : public Private::FunctorImplBase<R, ThreadingModel>
- {
- public:
- typedef R ResultType;
- virtual R operator()() = 0;
- };
-
-
- template <typename R, typename P1, template <class> class ThreadingModel>
- class FunctorImpl<R, TYPELIST_1(P1), ThreadingModel>
- : public Private::FunctorImplBase<R, ThreadingModel>
- {
- public:
- typedef R ResultType;
- typedef typename TypeTraits<P1>::ParameterType Parm1;
- virtual R operator()(Parm1) = 0;
- };
-
-
- template <typename R, typename P1, typename P2,
- template <class> class ThreadingModel>
- class FunctorImpl<R, TYPELIST_2(P1, P2), ThreadingModel>
- : public Private::FunctorImplBase<R, ThreadingModel>
- {
- public:
- typedef R ResultType;
- typedef typename TypeTraits<P1>::ParameterType Parm1;
- typedef typename TypeTraits<P2>::ParameterType Parm2;
- virtual R operator()(Parm1, Parm2) = 0;
- };
-
-
- template <typename R, typename P1, typename P2, typename P3,
- template <class> class ThreadingModel>
- class FunctorImpl<R, TYPELIST_3(P1, P2, P3), ThreadingModel>
- : public Private::FunctorImplBase<R, ThreadingModel>
- {
- public:
- typedef R ResultType;
- typedef typename TypeTraits<P1>::ParameterType Parm1;
- typedef typename TypeTraits<P2>::ParameterType Parm2;
- typedef typename TypeTraits<P3>::ParameterType Parm3;
- virtual R operator()(Parm1, Parm2, Parm3) = 0;
- };
-
-
- template <typename R, typename P1, typename P2, typename P3, typename P4,
- template <class> class ThreadingModel>
- class FunctorImpl<R, TYPELIST_4(P1, P2, P3, P4), ThreadingModel>
- : public Private::FunctorImplBase<R, ThreadingModel>
- {
- public:
- typedef R ResultType;
- typedef typename TypeTraits<P1>::ParameterType Parm1;
- typedef typename TypeTraits<P2>::ParameterType Parm2;
- typedef typename TypeTraits<P3>::ParameterType Parm3;
- typedef typename TypeTraits<P4>::ParameterType Parm4;
- virtual R operator()(Parm1, Parm2, Parm3, Parm4) = 0;
- };
-
-
- template <typename R, typename P1, typename P2, typename P3, typename P4,
- typename P5,
- template <class> class ThreadingModel>
- class FunctorImpl<R, TYPELIST_5(P1, P2, P3, P4, P5), ThreadingModel>
- : public Private::FunctorImplBase<R, ThreadingModel>
- {
- public:
- typedef R ResultType;
- typedef typename TypeTraits<P1>::ParameterType Parm1;
- typedef typename TypeTraits<P2>::ParameterType Parm2;
- typedef typename TypeTraits<P3>::ParameterType Parm3;
- typedef typename TypeTraits<P4>::ParameterType Parm4;
- typedef typename TypeTraits<P5>::ParameterType Parm5;
- virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5) = 0;
- };
-
-
- template <typename R, typename P1, typename P2, typename P3, typename P4,
- typename P5, typename P6,
- template <class> class ThreadingModel>
- class FunctorImpl<R, TYPELIST_6(P1, P2, P3, P4, P5, P6), ThreadingModel>
- : public Private::FunctorImplBase<R, ThreadingModel>
- {
- public:
- typedef R ResultType;
- typedef typename TypeTraits<P1>::ParameterType Parm1;
- typedef typename TypeTraits<P2>::ParameterType Parm2;
- typedef typename TypeTraits<P3>::ParameterType Parm3;
- typedef typename TypeTraits<P4>::ParameterType Parm4;
- typedef typename TypeTraits<P5>::ParameterType Parm5;
- typedef typename TypeTraits<P6>::ParameterType Parm6;
- virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6) = 0;
- };
-
-
- template <typename R, typename P1, typename P2, typename P3, typename P4,
- typename P5, typename P6, typename P7,
- template <class> class ThreadingModel>
- class FunctorImpl<R, TYPELIST_7(P1, P2, P3, P4, P5, P6, P7), ThreadingModel>
- : public Private::FunctorImplBase<R, ThreadingModel>
- {
- public:
- typedef R ResultType;
- typedef typename TypeTraits<P1>::ParameterType Parm1;
- typedef typename TypeTraits<P2>::ParameterType Parm2;
- typedef typename TypeTraits<P3>::ParameterType Parm3;
- typedef typename TypeTraits<P4>::ParameterType Parm4;
- typedef typename TypeTraits<P5>::ParameterType Parm5;
- typedef typename TypeTraits<P6>::ParameterType Parm6;
- typedef typename TypeTraits<P7>::ParameterType Parm7;
- virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6,
- Parm7) = 0;
- };
-
-
- template <typename R, typename P1, typename P2, typename P3, typename P4,
- typename P5, typename P6, typename P7, typename P8,
- template <class> class ThreadingModel>
- class FunctorImpl<R, TYPELIST_8(P1, P2, P3, P4, P5, P6, P7, P8),
- ThreadingModel>
- : public Private::FunctorImplBase<R, ThreadingModel>
- {
- public:
- typedef R ResultType;
- typedef typename TypeTraits<P1>::ParameterType Parm1;
- typedef typename TypeTraits<P2>::ParameterType Parm2;
- typedef typename TypeTraits<P3>::ParameterType Parm3;
- typedef typename TypeTraits<P4>::ParameterType Parm4;
- typedef typename TypeTraits<P5>::ParameterType Parm5;
- typedef typename TypeTraits<P6>::ParameterType Parm6;
- typedef typename TypeTraits<P7>::ParameterType Parm7;
- typedef typename TypeTraits<P8>::ParameterType Parm8;
- virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6,
- Parm7, Parm8) = 0;
- };
-
-
- template <typename R, typename P1, typename P2, typename P3, typename P4,
- typename P5, typename P6, typename P7, typename P8, typename P9,
- template <class> class ThreadingModel>
- class FunctorImpl<R, TYPELIST_9(P1, P2, P3, P4, P5, P6, P7, P8, P9),
- ThreadingModel>
- : public Private::FunctorImplBase<R, ThreadingModel>
- {
- public:
- typedef R ResultType;
- typedef typename TypeTraits<P1>::ParameterType Parm1;
- typedef typename TypeTraits<P2>::ParameterType Parm2;
- typedef typename TypeTraits<P3>::ParameterType Parm3;
- typedef typename TypeTraits<P4>::ParameterType Parm4;
- typedef typename TypeTraits<P5>::ParameterType Parm5;
- typedef typename TypeTraits<P6>::ParameterType Parm6;
- typedef typename TypeTraits<P7>::ParameterType Parm7;
- typedef typename TypeTraits<P8>::ParameterType Parm8;
- typedef typename TypeTraits<P9>::ParameterType Parm9;
- virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6,
- Parm7, Parm8, Parm9) = 0;
- };
-
-
- template <typename R, typename P1, typename P2, typename P3, typename P4,
- typename P5, typename P6, typename P7, typename P8, typename P9,
- typename P10,
- template <class> class ThreadingModel>
- class FunctorImpl<R, TYPELIST_10(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10),
- ThreadingModel>
- : public Private::FunctorImplBase<R, ThreadingModel>
- {
- public:
- typedef R ResultType;
- typedef typename TypeTraits<P1>::ParameterType Parm1;
- typedef typename TypeTraits<P2>::ParameterType Parm2;
- typedef typename TypeTraits<P3>::ParameterType Parm3;
- typedef typename TypeTraits<P4>::ParameterType Parm4;
- typedef typename TypeTraits<P5>::ParameterType Parm5;
- typedef typename TypeTraits<P6>::ParameterType Parm6;
- typedef typename TypeTraits<P7>::ParameterType Parm7;
- typedef typename TypeTraits<P8>::ParameterType Parm8;
- typedef typename TypeTraits<P9>::ParameterType Parm9;
- typedef typename TypeTraits<P10>::ParameterType Parm10;
- virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6,
- Parm7, Parm8, Parm9, Parm10) = 0;
- };
-
-
- template <typename R, typename P1, typename P2, typename P3, typename P4,
- typename P5, typename P6, typename P7, typename P8, typename P9,
- typename P10, typename P11,
- template <class> class ThreadingModel>
- class FunctorImpl<R,
- TYPELIST_11(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11),
- ThreadingModel>
- : public Private::FunctorImplBase<R, ThreadingModel>
- {
- public:
- typedef R ResultType;
- typedef typename TypeTraits<P1>::ParameterType Parm1;
- typedef typename TypeTraits<P2>::ParameterType Parm2;
- typedef typename TypeTraits<P3>::ParameterType Parm3;
- typedef typename TypeTraits<P4>::ParameterType Parm4;
- typedef typename TypeTraits<P5>::ParameterType Parm5;
- typedef typename TypeTraits<P6>::ParameterType Parm6;
- typedef typename TypeTraits<P7>::ParameterType Parm7;
- typedef typename TypeTraits<P8>::ParameterType Parm8;
- typedef typename TypeTraits<P9>::ParameterType Parm9;
- typedef typename TypeTraits<P10>::ParameterType Parm10;
- typedef typename TypeTraits<P11>::ParameterType Parm11;
- virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6,
- Parm7, Parm8, Parm9, Parm10, Parm11) = 0;
- };
-
-
- template <typename R, typename P1, typename P2, typename P3, typename P4,
- typename P5, typename P6, typename P7, typename P8, typename P9,
- typename P10, typename P11, typename P12,
- template <class> class ThreadingModel>
- class FunctorImpl<R,
- TYPELIST_12(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12),
- ThreadingModel>
- : public Private::FunctorImplBase<R, ThreadingModel>
- {
- public:
- typedef R ResultType;
- typedef typename TypeTraits<P1>::ParameterType Parm1;
- typedef typename TypeTraits<P2>::ParameterType Parm2;
- typedef typename TypeTraits<P3>::ParameterType Parm3;
- typedef typename TypeTraits<P4>::ParameterType Parm4;
- typedef typename TypeTraits<P5>::ParameterType Parm5;
- typedef typename TypeTraits<P6>::ParameterType Parm6;
- typedef typename TypeTraits<P7>::ParameterType Parm7;
- typedef typename TypeTraits<P8>::ParameterType Parm8;
- typedef typename TypeTraits<P9>::ParameterType Parm9;
- typedef typename TypeTraits<P10>::ParameterType Parm10;
- typedef typename TypeTraits<P11>::ParameterType Parm11;
- typedef typename TypeTraits<P12>::ParameterType Parm12;
- virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6,
- Parm7, Parm8, Parm9, Parm10, Parm11, Parm12) = 0;
- };
-
-
- template <typename R, typename P1, typename P2, typename P3, typename P4,
- typename P5, typename P6, typename P7, typename P8, typename P9,
- typename P10, typename P11, typename P12, typename P13,
- template <class> class ThreadingModel>
- class FunctorImpl<R,
- TYPELIST_13(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13),
- ThreadingModel>
- : public Private::FunctorImplBase<R, ThreadingModel>
- {
- public:
- typedef R ResultType;
- typedef typename TypeTraits<P1>::ParameterType Parm1;
- typedef typename TypeTraits<P2>::ParameterType Parm2;
- typedef typename TypeTraits<P3>::ParameterType Parm3;
- typedef typename TypeTraits<P4>::ParameterType Parm4;
- typedef typename TypeTraits<P5>::ParameterType Parm5;
- typedef typename TypeTraits<P6>::ParameterType Parm6;
- typedef typename TypeTraits<P7>::ParameterType Parm7;
- typedef typename TypeTraits<P8>::ParameterType Parm8;
- typedef typename TypeTraits<P9>::ParameterType Parm9;
- typedef typename TypeTraits<P10>::ParameterType Parm10;
- typedef typename TypeTraits<P11>::ParameterType Parm11;
- typedef typename TypeTraits<P12>::ParameterType Parm12;
- typedef typename TypeTraits<P13>::ParameterType Parm13;
- virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6,
- Parm7, Parm8, Parm9, Parm10, Parm11, Parm12, Parm13) = 0;
- };
-
-
- template <typename R, typename P1, typename P2, typename P3, typename P4,
- typename P5, typename P6, typename P7, typename P8, typename P9,
- typename P10, typename P11, typename P12, typename P13, typename P14,
- template <class> class ThreadingModel>
- class FunctorImpl<R,
- TYPELIST_14(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13,
- P14),
- ThreadingModel>
- : public Private::FunctorImplBase<R, ThreadingModel>
- {
- public:
- typedef R ResultType;
- typedef typename TypeTraits<P1>::ParameterType Parm1;
- typedef typename TypeTraits<P2>::ParameterType Parm2;
- typedef typename TypeTraits<P3>::ParameterType Parm3;
- typedef typename TypeTraits<P4>::ParameterType Parm4;
- typedef typename TypeTraits<P5>::ParameterType Parm5;
- typedef typename TypeTraits<P6>::ParameterType Parm6;
- typedef typename TypeTraits<P7>::ParameterType Parm7;
- typedef typename TypeTraits<P8>::ParameterType Parm8;
- typedef typename TypeTraits<P9>::ParameterType Parm9;
- typedef typename TypeTraits<P10>::ParameterType Parm10;
- typedef typename TypeTraits<P11>::ParameterType Parm11;
- typedef typename TypeTraits<P12>::ParameterType Parm12;
- typedef typename TypeTraits<P13>::ParameterType Parm13;
- typedef typename TypeTraits<P14>::ParameterType Parm14;
- virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6,
- Parm7, Parm8, Parm9, Parm10, Parm11, Parm12, Parm13, Parm14) = 0;
- };
-
-
- template <typename R, typename P1, typename P2, typename P3, typename P4,
- typename P5, typename P6, typename P7, typename P8, typename P9,
- typename P10, typename P11, typename P12, typename P13, typename P14,
- typename P15, template <class> class ThreadingModel>
- class FunctorImpl<R,
- TYPELIST_15(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13,
- P14, P15),
- ThreadingModel>
- : public Private::FunctorImplBase<R, ThreadingModel>
- {
- public:
- typedef R ResultType;
- typedef typename TypeTraits<P1>::ParameterType Parm1;
- typedef typename TypeTraits<P2>::ParameterType Parm2;
- typedef typename TypeTraits<P3>::ParameterType Parm3;
- typedef typename TypeTraits<P4>::ParameterType Parm4;
- typedef typename TypeTraits<P5>::ParameterType Parm5;
- typedef typename TypeTraits<P6>::ParameterType Parm6;
- typedef typename TypeTraits<P7>::ParameterType Parm7;
- typedef typename TypeTraits<P8>::ParameterType Parm8;
- typedef typename TypeTraits<P9>::ParameterType Parm9;
- typedef typename TypeTraits<P10>::ParameterType Parm10;
- typedef typename TypeTraits<P11>::ParameterType Parm11;
- typedef typename TypeTraits<P12>::ParameterType Parm12;
- typedef typename TypeTraits<P13>::ParameterType Parm13;
- typedef typename TypeTraits<P14>::ParameterType Parm14;
- typedef typename TypeTraits<P15>::ParameterType Parm15;
- virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6,
- Parm7, Parm8, Parm9, Parm10, Parm11, Parm12, Parm13, Parm14,
- Parm15) = 0;
- };
-
-
- template <class ParentFunctor, typename Fun>
- class FunctorHandler
- : public ParentFunctor::Impl
- {
- typedef typename ParentFunctor::Impl Base;
-
- public:
- typedef typename Base::ResultType ResultType;
- typedef typename Base::Parm1 Parm1;
- typedef typename Base::Parm2 Parm2;
- typedef typename Base::Parm3 Parm3;
- typedef typename Base::Parm4 Parm4;
- typedef typename Base::Parm5 Parm5;
- typedef typename Base::Parm6 Parm6;
- typedef typename Base::Parm7 Parm7;
- typedef typename Base::Parm8 Parm8;
- typedef typename Base::Parm9 Parm9;
- typedef typename Base::Parm10 Parm10;
- typedef typename Base::Parm11 Parm11;
- typedef typename Base::Parm12 Parm12;
- typedef typename Base::Parm13 Parm13;
- typedef typename Base::Parm14 Parm14;
- typedef typename Base::Parm15 Parm15;
-
- FunctorHandler(const Fun& fun) : f_(fun) {}
-
- DEFINE_CLONE_FUNCTORIMPL(FunctorHandler)
-
-
-
- ResultType operator()()
- { return f_(); }
-
- ResultType operator()(Parm1 p1)
- { return f_(p1); }
-
- ResultType operator()(Parm1 p1, Parm2 p2)
- { return f_(p1, p2); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3)
- { return f_(p1, p2, p3); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4)
- { return f_(p1, p2, p3, p4); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5)
- { return f_(p1, p2, p3, p4, p5); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6)
- { return f_(p1, p2, p3, p4, p5, p6); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7)
- { return f_(p1, p2, p3, p4, p5, p6, p7); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8)
- { return f_(p1, p2, p3, p4, p5, p6, p7, p8); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9)
- { return f_(p1, p2, p3, p4, p5, p6, p7, p8, p9); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10)
- { return f_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11)
- { return f_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12)
- { return f_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12, Parm13 p13)
- { return f_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12, Parm13 p13, Parm14 p14)
- {
- return f_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13,
- p14);
- }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12, Parm13 p13, Parm14 p14, Parm15 p15)
- {
- return f_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13,
- p14, p15);
- }
-
- private:
- Fun f_;
- };
-
-
- template <class ParentFunctor, typename PointerToObj,
- typename PointerToMemFn>
- class MemFunHandler : public ParentFunctor::Impl
- {
- typedef typename ParentFunctor::Impl Base;
-
- public:
- typedef typename Base::ResultType ResultType;
- typedef typename Base::Parm1 Parm1;
- typedef typename Base::Parm2 Parm2;
- typedef typename Base::Parm3 Parm3;
- typedef typename Base::Parm4 Parm4;
- typedef typename Base::Parm5 Parm5;
- typedef typename Base::Parm6 Parm6;
- typedef typename Base::Parm7 Parm7;
- typedef typename Base::Parm8 Parm8;
- typedef typename Base::Parm9 Parm9;
- typedef typename Base::Parm10 Parm10;
- typedef typename Base::Parm11 Parm11;
- typedef typename Base::Parm12 Parm12;
- typedef typename Base::Parm13 Parm13;
- typedef typename Base::Parm14 Parm14;
- typedef typename Base::Parm15 Parm15;
-
- MemFunHandler(const PointerToObj& pObj, PointerToMemFn pMemFn)
- : pObj_(pObj), pMemFn_(pMemFn)
- {}
-
- DEFINE_CLONE_FUNCTORIMPL(MemFunHandler)
-
- ResultType operator()()
- { return ((*pObj_).*pMemFn_)(); }
-
- ResultType operator()(Parm1 p1)
- { return ((*pObj_).*pMemFn_)(p1); }
-
- ResultType operator()(Parm1 p1, Parm2 p2)
- { return ((*pObj_).*pMemFn_)(p1, p2); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3)
- { return ((*pObj_).*pMemFn_)(p1, p2, p3); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4)
- { return ((*pObj_).*pMemFn_)(p1, p2, p3, p4); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5)
- { return ((*pObj_).*pMemFn_)(p1, p2, p3, p4, p5); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6)
- { return ((*pObj_).*pMemFn_)(p1, p2, p3, p4, p5, p6); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7)
- { return ((*pObj_).*pMemFn_)(p1, p2, p3, p4, p5, p6, p7); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8)
- { return ((*pObj_).*pMemFn_)(p1, p2, p3, p4, p5, p6, p7, p8); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9)
- { return ((*pObj_).*pMemFn_)(p1, p2, p3, p4, p5, p6, p7, p8, p9); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10)
- { return ((*pObj_).*pMemFn_)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11)
- {
- return ((*pObj_).*pMemFn_)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10,
- p11);
- }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12)
- {
- return ((*pObj_).*pMemFn_)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10,
- p11, p12);
- }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12, Parm13 p13)
- {
- return ((*pObj_).*pMemFn_)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10,
- p11, p12, p13);
- }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12, Parm13 p13, Parm14 p14)
- {
- return ((*pObj_).*pMemFn_)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10,
- p11, p12, p13, p14);
- }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12, Parm13 p13, Parm14 p14, Parm15 p15)
- {
- return ((*pObj_).*pMemFn_)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10,
- p11, p12, p13, p14, p15);
- }
-
- private:
- PointerToObj pObj_;
- PointerToMemFn pMemFn_;
- };
-
-
- template <typename R, class TList = NullType,
- template<class> class ThreadingModel = DEFAULT_THREADING>
- class Functor
- {
- public:
-
- typedef FunctorImpl<R, TList, ThreadingModel> Impl;
- typedef R ResultType;
- typedef TList ParmList;
- typedef typename Impl::Parm1 Parm1;
- typedef typename Impl::Parm2 Parm2;
- typedef typename Impl::Parm3 Parm3;
- typedef typename Impl::Parm4 Parm4;
- typedef typename Impl::Parm5 Parm5;
- typedef typename Impl::Parm6 Parm6;
- typedef typename Impl::Parm7 Parm7;
- typedef typename Impl::Parm8 Parm8;
- typedef typename Impl::Parm9 Parm9;
- typedef typename Impl::Parm10 Parm10;
- typedef typename Impl::Parm11 Parm11;
- typedef typename Impl::Parm12 Parm12;
- typedef typename Impl::Parm13 Parm13;
- typedef typename Impl::Parm14 Parm14;
- typedef typename Impl::Parm15 Parm15;
-
-
-
- Functor() : spImpl_(0)
- {}
-
- Functor(const Functor& rhs) : spImpl_(Impl::Clone(rhs.spImpl_.get()))
- {}
-
- Functor(std::auto_ptr<Impl> spImpl) : spImpl_(spImpl)
- {}
-
- template <typename Fun>
- Functor(Fun fun)
- : spImpl_(new FunctorHandler<Functor, Fun>(fun))
- {}
-
- template <class PtrObj, typename MemFn>
- Functor(const PtrObj& p, MemFn memFn)
- : spImpl_(new MemFunHandler<Functor, PtrObj, MemFn>(p, memFn))
- {}
-
- typedef Impl * (std::auto_ptr<Impl>::*unspecified_bool_type)() const;
-
- operator unspecified_bool_type() const
- {
- return spImpl_.get() ? &std::auto_ptr<Impl>::get : 0;
- }
-
- Functor& operator=(const Functor& rhs)
- {
- Functor copy(rhs);
-
- Impl* p = spImpl_.release();
- spImpl_.reset(copy.spImpl_.release());
- copy.spImpl_.reset(p);
- return *this;
- }
-
- ResultType operator()() const
- { return (*spImpl_)(); }
-
- ResultType operator()(Parm1 p1) const
- { return (*spImpl_)(p1); }
-
- ResultType operator()(Parm1 p1, Parm2 p2) const
- { return (*spImpl_)(p1, p2); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3) const
- { return (*spImpl_)(p1, p2, p3); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4) const
- { return (*spImpl_)(p1, p2, p3, p4); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5) const
- { return (*spImpl_)(p1, p2, p3, p4, p5); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6) const
- { return (*spImpl_)(p1, p2, p3, p4, p5, p6); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7) const
- { return (*spImpl_)(p1, p2, p3, p4, p5, p6, p7); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8) const
- { return (*spImpl_)(p1, p2, p3, p4, p5, p6, p7, p8); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9) const
- { return (*spImpl_)(p1, p2, p3, p4, p5, p6, p7, p8, p9); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10) const
- { return (*spImpl_)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11) const
- { return (*spImpl_)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12) const
- {
- return (*spImpl_)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11,
- p12);
- }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12, Parm13 p13) const
- {
- return (*spImpl_)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11,
- p12, p13);
- }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12, Parm13 p13, Parm14 p14) const
- {
- return (*spImpl_)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11,
- p12, p13, p14);
- }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12, Parm13 p13, Parm14 p14, Parm15 p15) const
- {
- return (*spImpl_)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11,
- p12, p13, p14, p15);
- }
-
- private:
- std::auto_ptr<Impl> spImpl_;
- };
-
- namespace Private
- {
- template <class Fctor> struct BinderFirstTraits;
-
- template <typename R, class TList, template <class> class ThreadingModel>
- struct BinderFirstTraits< Functor<R, TList, ThreadingModel> >
- {
- typedef typename TL::Erase<TList,
- typename TL::TypeAt<TList, 0>::Result>::Result
- ParmList;
- typedef Functor<R, ParmList, ThreadingModel> BoundFunctorType;
- typedef typename BoundFunctorType::Impl Impl;
- };
- }
-
-
- template <class OriginalFunctor>
- class BinderFirst
- : public Private::BinderFirstTraits<OriginalFunctor>::Impl
- {
- typedef typename Private::BinderFirstTraits<OriginalFunctor>::Impl Base;
- typedef typename OriginalFunctor::ResultType ResultType;
-
- typedef typename OriginalFunctor::Parm1 BoundType;
-
- typedef typename OriginalFunctor::Parm2 Parm1;
- typedef typename OriginalFunctor::Parm3 Parm2;
- typedef typename OriginalFunctor::Parm4 Parm3;
- typedef typename OriginalFunctor::Parm5 Parm4;
- typedef typename OriginalFunctor::Parm6 Parm5;
- typedef typename OriginalFunctor::Parm7 Parm6;
- typedef typename OriginalFunctor::Parm8 Parm7;
- typedef typename OriginalFunctor::Parm9 Parm8;
- typedef typename OriginalFunctor::Parm10 Parm9;
- typedef typename OriginalFunctor::Parm11 Parm10;
- typedef typename OriginalFunctor::Parm12 Parm11;
- typedef typename OriginalFunctor::Parm13 Parm12;
- typedef typename OriginalFunctor::Parm14 Parm13;
- typedef typename OriginalFunctor::Parm15 Parm14;
- typedef EmptyType Parm15;
-
- public:
- BinderFirst(const OriginalFunctor& fun, BoundType bound)
- : f_(fun), b_(bound)
- {}
-
- DEFINE_CLONE_FUNCTORIMPL(BinderFirst)
-
-
-
- ResultType operator()()
- { return f_(b_); }
-
- ResultType operator()(Parm1 p1)
- { return f_(b_, p1); }
-
- ResultType operator()(Parm1 p1, Parm2 p2)
- { return f_(b_, p1, p2); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3)
- { return f_(b_, p1, p2, p3); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4)
- { return f_(b_, p1, p2, p3, p4); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5)
- { return f_(b_, p1, p2, p3, p4, p5); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6)
- { return f_(b_, p1, p2, p3, p4, p5, p6); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7)
- { return f_(b_, p1, p2, p3, p4, p5, p6, p7); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8)
- { return f_(b_, p1, p2, p3, p4, p5, p6, p7, p8); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9)
- { return f_(b_, p1, p2, p3, p4, p5, p6, p7, p8, p9); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10)
- { return f_(b_, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11)
- { return f_(b_, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12)
- { return f_(b_, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12, Parm13 p13)
- { return f_(b_, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12, Parm13 p13, Parm14 p14)
- {
- return f_(b_, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13,
- p14);
- }
-
- private:
- OriginalFunctor f_;
- BoundType b_;
- };
-
-
- template <class Fctor>
- typename Private::BinderFirstTraits<Fctor>::BoundFunctorType
- BindFirst(
- const Fctor& fun,
- typename Fctor::Parm1 bound)
- {
- typedef typename Private::BinderFirstTraits<Fctor>::BoundFunctorType
- Outgoing;
-
- return Outgoing(std::auto_ptr<typename Outgoing::Impl>(
- new BinderFirst<Fctor>(fun, bound)));
- }
-
-
- template <typename Fun1, typename Fun2>
- class Chainer : public Fun2::Impl
- {
- typedef Fun2 Base;
-
- public:
- typedef typename Base::ResultType ResultType;
- typedef typename Base::Parm1 Parm1;
- typedef typename Base::Parm2 Parm2;
- typedef typename Base::Parm3 Parm3;
- typedef typename Base::Parm4 Parm4;
- typedef typename Base::Parm5 Parm5;
- typedef typename Base::Parm6 Parm6;
- typedef typename Base::Parm7 Parm7;
- typedef typename Base::Parm8 Parm8;
- typedef typename Base::Parm9 Parm9;
- typedef typename Base::Parm10 Parm10;
- typedef typename Base::Parm11 Parm11;
- typedef typename Base::Parm12 Parm12;
- typedef typename Base::Parm13 Parm13;
- typedef typename Base::Parm14 Parm14;
- typedef typename Base::Parm15 Parm15;
-
- Chainer(const Fun1& fun1, const Fun2& fun2) : f1_(fun1), f2_(fun2) {}
-
- DEFINE_CLONE_FUNCTORIMPL(Chainer)
-
-
-
- ResultType operator()()
- { return f1_(), f2_(); }
-
- ResultType operator()(Parm1 p1)
- { return f1_(p1), f2_(p1); }
-
- ResultType operator()(Parm1 p1, Parm2 p2)
- { return f1_(p1, p2), f2_(p1, p2); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3)
- { return f1_(p1, p2, p3), f2_(p1, p2, p3); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4)
- { return f1_(p1, p2, p3, p4), f2_(p1, p2, p3, p4); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5)
- { return f1_(p1, p2, p3, p4, p5), f2_(p1, p2, p3, p4, p5); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6)
- { return f1_(p1, p2, p3, p4, p5, p6), f2_(p1, p2, p3, p4, p5, p6); }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7)
- {
- return f1_(p1, p2, p3, p4, p5, p6, p7),
- f2_(p1, p2, p3, p4, p5, p6, p7);
- }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8)
- {
- return f1_(p1, p2, p3, p4, p5, p6, p7, p8),
- f2_(p1, p2, p3, p4, p5, p6, p7, p8);
- }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9)
- {
- return f1_(p1, p2, p3, p4, p5, p6, p7, p8, p9),
- f2_(p1, p2, p3, p4, p5, p6, p7, p8, p9);
- }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10)
- {
- return f1_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10),
- f2_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
- }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11)
- {
- return f1_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11),
- f2_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11);
- }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12)
- {
- return f1_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12),
- f2_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12);
- }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12, Parm13 p13)
- {
- return f1_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13),
- f2_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13);
- }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12, Parm13 p13, Parm14 p14)
- {
- return f1_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13,
- p14),
- f2_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13,
- p14);
- }
-
- ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
- Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10, Parm11 p11,
- Parm12 p12, Parm13 p13, Parm14 p14, Parm15 p15)
- {
- return f1_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13,
- p14, p15),
- f2_(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13,
- p14, p15);
- }
-
- private:
- Fun1 f1_;
- Fun2 f2_;
- };
-
-
-
- template <class Fun1, class Fun2>
- Fun2 Chain(
- const Fun1& fun1,
- const Fun2& fun2)
- {
- return Fun2(std::auto_ptr<typename Fun2::Impl>(
- new Chainer<Fun1, Fun2>(fun1, fun2)));
- }
-
- }
-
-
- #endif
-
Functor.h 접기
-
HierarchyGenerators.h 보기
-
-
- #ifndef HIERARCHYGENERATORS_INC_
- #define HIERARCHYGENERATORS_INC_
-
- #include
- #include
- #include
-
- namespace Loki
- {
- #if defined(_MSC_VER) && _MSC_VER >= 1300
- #pragma warning( push )
-
- #pragma warning( disable : 4584 )
- #endif
-
-
- namespace Private
- {
-
-
-
-
-
-
-
-
- template<class, class>
- struct ScatterHierarchyTag;
- }
-
- template <class TList, template <class> class Unit>
- class GenScatterHierarchy;
-
- template <class T1, class T2, template <class> class Unit>
- class GenScatterHierarchy<Typelist<T1, T2>, Unit>
- : public GenScatterHierarchy<Private::ScatterHierarchyTag<T1, T2>, Unit>
- , public GenScatterHierarchy<T2, Unit>
- {
- public:
- typedef Typelist<T1, T2> TList;
-
- typedef GenScatterHierarchy<Private::ScatterHierarchyTag<T1, T2>, Unit> LeftBase;
- typedef GenScatterHierarchy<T2, Unit> RightBase;
- template <typename T> struct Rebind
- {
- typedef Unit<T> Result;
- };
- };
-
-
- template <class T1, class T2, template <class> class Unit>
- class GenScatterHierarchy<Private::ScatterHierarchyTag<T1, T2>, Unit>
- : public GenScatterHierarchy<T1, Unit>
- {
- };
-
- template <class AtomicType, template <class> class Unit>
- class GenScatterHierarchy : public Unit<AtomicType>
- {
- typedef Unit<AtomicType> LeftBase;
- template <typename T> struct Rebind
- {
- typedef Unit<T> Result;
- };
- };
-
- template <template <class> class Unit>
- class GenScatterHierarchy<NullType, Unit>
- {
- template <typename T> struct Rebind
- {
- typedef Unit<T> Result;
- };
- };
-
-
- template <class T, class H>
- typename H::template Rebind<T>::Result& Field(H& obj)
- {
- return obj;
- }
-
- template <class T, class H>
- const typename H::template Rebind<T>::Result& Field(const H& obj)
- {
- return obj;
- }
-
-
- template <class T>
- struct TupleUnit
- {
- T value_;
- operator T&() { return value_; }
- operator const T&() const { return value_; }
- };
-
-
- template <class TList>
- struct Tuple : public GenScatterHierarchy<TList, TupleUnit>
- {
- };
-
-
- template <class H, unsigned int i> struct FieldHelper;
-
- template <class H>
- struct FieldHelper<H, 0>
- {
- typedef typename H::TList::Head ElementType;
- typedef typename H::template Rebind<ElementType>::Result UnitType;
-
- enum
- {
- isTuple = Conversion<UnitType, TupleUnit<ElementType> >::sameType,
- isConst = TypeTraits<H>::isConst
- };
-
- typedef const typename H::LeftBase ConstLeftBase;
-
- typedef typename Select<isConst, ConstLeftBase,
- typename H::LeftBase>::Result LeftBase;
-
- typedef typename Select<isTuple, ElementType,
- UnitType>::Result UnqualifiedResultType;
-
- typedef typename Select<isConst, const UnqualifiedResultType,
- UnqualifiedResultType>::Result ResultType;
-
- static ResultType& Do(H& obj)
- {
- LeftBase& leftBase = obj;
- return leftBase;
- }
- };
-
- template <class H, unsigned int i>
- struct FieldHelper
- {
- typedef typename TL::TypeAt<typename H::TList, i>::Result ElementType;
- typedef typename H::template Rebind<ElementType>::Result UnitType;
-
- enum
- {
- isTuple = Conversion<UnitType, TupleUnit<ElementType> >::sameType,
- isConst = TypeTraits<H>::isConst
- };
-
- typedef const typename H::RightBase ConstRightBase;
-
- typedef typename Select<isConst, ConstRightBase,
- typename H::RightBase>::Result RightBase;
-
- typedef typename Select<isTuple, ElementType,
- UnitType>::Result UnqualifiedResultType;
-
- typedef typename Select<isConst, const UnqualifiedResultType,
- UnqualifiedResultType>::Result ResultType;
-
- static ResultType& Do(H& obj)
- {
- RightBase& rightBase = obj;
- return FieldHelper<RightBase, i - 1>::Do(rightBase);
- }
- };
-
-
- template <int i, class H>
- typename FieldHelper<H, i>::ResultType&
- Field(H& obj)
- {
- return FieldHelper<H, i>::Do(obj);
- }
-
-
-
- template
- <
- class TList,
- template <class AtomicType, class Base> class Unit,
- class Root = EmptyType
- >
- class GenLinearHierarchy;
-
- template
- <
- class T1,
- class T2,
- template <class, class> class Unit,
- class Root
- >
- class GenLinearHierarchy<Typelist<T1, T2>, Unit, Root>
- : public Unit< T1, GenLinearHierarchy<T2, Unit, Root> >
- {
- };
-
- template
- <
- class T,
- template <class, class> class Unit,
- class Root
- >
- class GenLinearHierarchy<Typelist<T, NullType>, Unit, Root>
- : public Unit<T, Root>
- {
- };
-
- #if defined(_MSC_VER) && _MSC_VER >= 1300
- #pragma warning( pop )
- #endif
- }
-
-
- #endif
-
HierarchyGenerators.h 접기
-
LokiTypeInfo.h 보기
-
MultiMethods.h 보기
-
- #ifndef MULTIMETHODS_INC_
- #define MULTIMETHODS_INC_
-
- #include
- #include
- #include
- #include
-
-
- namespace Loki
- {
-
- namespace Private
- {
- template <class SomeLhs, class SomeRhs,
- class Executor, typename ResultType>
- struct InvocationTraits
- {
- static ResultType
- DoDispatch(SomeLhs& lhs, SomeRhs& rhs,
- Executor& exec, Int2Type<false>)
- {
- return exec.Fire(lhs, rhs);
- }
- static ResultType
- DoDispatch(SomeLhs& lhs, SomeRhs& rhs,
- Executor& exec, Int2Type<true>)
- {
- return exec.Fire(rhs, lhs);
- }
- };
- }
-
-
- template
- <
- class Executor,
- class BaseLhs,
- class TypesLhs,
- bool symmetric = true,
- class BaseRhs = BaseLhs,
- class TypesRhs = TypesLhs,
- typename ResultType = void
- >
- class StaticDispatcher
- {
- template <class SomeLhs>
- static ResultType DispatchRhs(SomeLhs& lhs, BaseRhs& rhs,
- Executor exec, NullType)
- { return exec.OnError(lhs, rhs); }
-
- template <class Head, class Tail, class SomeLhs>
- static ResultType DispatchRhs(SomeLhs& lhs, BaseRhs& rhs,
- Executor exec, Typelist<Head, Tail>)
- {
- if (Head* p2 = dynamic_cast<Head*>(&rhs))
- {
- Int2Type<(symmetric &&
- int(TL::IndexOf<TypesRhs, Head>::value) <
- int(TL::IndexOf<TypesLhs, SomeLhs>::value))> i2t;
-
- typedef Private::InvocationTraits<
- SomeLhs, Head, Executor, ResultType> CallTraits;
-
- return CallTraits::DoDispatch(lhs, *p2, exec, i2t);
- }
- return DispatchRhs(lhs, rhs, exec, Tail());
- }
-
- static ResultType DispatchLhs(BaseLhs& lhs, BaseRhs& rhs,
- Executor exec, NullType)
- { return exec.OnError(lhs, rhs); }
-
- template <class Head, class Tail>
- static ResultType DispatchLhs(BaseLhs& lhs, BaseRhs& rhs,
- Executor exec, Typelist<Head, Tail>)
- {
- if (Head* p1 = dynamic_cast<Head*>(&lhs))
- {
- return DispatchRhs(*p1, rhs, exec, TypesRhs());
- }
- return DispatchLhs(lhs, rhs, exec, Tail());
- }
-
- public:
- static ResultType Go(BaseLhs& lhs, BaseRhs& rhs,
- Executor exec)
- { return DispatchLhs(lhs, rhs, exec, TypesLhs()); }
- };
-
-
- template
- <
- class BaseLhs,
- class BaseRhs = BaseLhs,
- typename ResultType = void,
- typename CallbackType = ResultType (*)(BaseLhs&, BaseRhs&)
- >
- class BasicDispatcher
- {
- typedef std::pair<TypeInfo,TypeInfo> KeyType;
- typedef CallbackType MappedType;
- typedef AssocVector<KeyType, MappedType> MapType;
- MapType callbackMap_;
-
- void DoAdd(TypeInfo lhs, TypeInfo rhs, CallbackType fun);
- bool DoRemove(TypeInfo lhs, TypeInfo rhs);
-
- public:
- template <class SomeLhs, class SomeRhs>
- void Add(CallbackType fun)
- {
- DoAdd(typeid(SomeLhs), typeid(SomeRhs), fun);
- }
-
- template <class SomeLhs, class SomeRhs>
- bool Remove()
- {
- return DoRemove(typeid(SomeLhs), typeid(SomeRhs));
- }
-
- ResultType Go(BaseLhs& lhs, BaseRhs& rhs);
- };
-
-
- template <class BaseLhs, class BaseRhs,
- typename ResultType, typename CallbackType>
- void BasicDispatcher<BaseLhs,BaseRhs,ResultType,CallbackType>
- ::DoAdd(TypeInfo lhs, TypeInfo rhs, CallbackType fun)
- {
- callbackMap_[KeyType(lhs, rhs)] = fun;
- }
-
- template <class BaseLhs, class BaseRhs,
- typename ResultType, typename CallbackType>
- bool BasicDispatcher<BaseLhs,BaseRhs,ResultType,CallbackType>
- ::DoRemove(TypeInfo lhs, TypeInfo rhs)
- {
- return callbackMap_.erase(KeyType(lhs, rhs)) == 1;
- }
-
- template <class BaseLhs, class BaseRhs,
- typename ResultType, typename CallbackType>
- ResultType BasicDispatcher<BaseLhs,BaseRhs,ResultType,CallbackType>
- ::Go(BaseLhs& lhs, BaseRhs& rhs)
- {
- typename MapType::key_type k(typeid(lhs),typeid(rhs));
- typename MapType::iterator i = callbackMap_.find(k);
- if (i == callbackMap_.end())
- {
- throw std::runtime_error("Function not found");
- }
- return (i->second)(lhs, rhs);
- }
-
-
- template <class To, class From>
- struct StaticCaster
- {
- static To& Cast(From& obj)
- {
- return static_cast<To&>(obj);
- }
- };
-
-
- template <class To, class From>
- struct DynamicCaster
- {
- static To& Cast(From& obj)
- {
- return dynamic_cast<To&>(obj);
- }
- };
-
-
- namespace Private
- {
- template <class BaseLhs, class BaseRhs,
- class SomeLhs, class SomeRhs,
- typename ResultType,
- class CastLhs, class CastRhs,
- ResultType (*Callback)(SomeLhs&, SomeRhs&)>
- struct FnDispatcherHelper
- {
- static ResultType Trampoline(BaseLhs& lhs, BaseRhs& rhs)
- {
- return Callback(CastLhs::Cast(lhs), CastRhs::Cast(rhs));
- }
- static ResultType TrampolineR(BaseRhs& rhs, BaseLhs& lhs)
- {
- return Trampoline(lhs, rhs);
- }
- };
- }
-
-
- template <class BaseLhs, class BaseRhs = BaseLhs,
- typename ResultType = void,
- template <class, class> class CastingPolicy = DynamicCaster,
- template <class, class, class, class>
- class DispatcherBackend = BasicDispatcher>
- class FnDispatcher
- {
- DispatcherBackend<BaseLhs, BaseRhs, ResultType,
- ResultType (*)(BaseLhs&, BaseRhs&)> backEnd_;
-
- public:
- template <class SomeLhs, class SomeRhs>
- void Add(ResultType (*pFun)(BaseLhs&, BaseRhs&))
- {
- return backEnd_.template Add<SomeLhs, SomeRhs>(pFun);
- }
-
- template <class SomeLhs, class SomeRhs,
- ResultType (*callback)(SomeLhs&, SomeRhs&)>
- void Add()
- {
- typedef Private::FnDispatcherHelper<
- BaseLhs, BaseRhs,
- SomeLhs, SomeRhs,
- ResultType,
- CastingPolicy<SomeLhs,BaseLhs>,
- CastingPolicy<SomeRhs,BaseRhs>,
- callback> Local;
-
- Add<SomeLhs, SomeRhs>(&Local::Trampoline);
- }
-
- template <class SomeLhs, class SomeRhs,
- ResultType (*callback)(SomeLhs&, SomeRhs&),
- bool symmetric>
- void Add(bool = true)
- {
- typedef Private::FnDispatcherHelper<
- BaseLhs, BaseRhs,
- SomeLhs, SomeRhs,
- ResultType,
- CastingPolicy<SomeLhs,BaseLhs>,
- CastingPolicy<SomeRhs,BaseRhs>,
- callback> Local;
-
- Add<SomeLhs, SomeRhs>(&Local::Trampoline);
- if (symmetric)
- {
- Add<SomeRhs, SomeLhs>(&Local::TrampolineR);
- }
- }
-
- template <class SomeLhs, class SomeRhs>
- void Remove()
- {
- backEnd_.template Remove<SomeLhs, SomeRhs>();
- }
-
- ResultType Go(BaseLhs& lhs, BaseRhs& rhs)
- {
- return backEnd_.Go(lhs, rhs);
- }
- };
-
-
- namespace Private
- {
- template <class BaseLhs, class BaseRhs,
- class SomeLhs, class SomeRhs,
- typename ResultType,
- class CastLhs, class CastRhs,
- class Fun, bool SwapArgs>
- class FunctorDispatcherHelper
- {
- Fun fun_;
- ResultType Fire(BaseLhs& lhs, BaseRhs& rhs,Int2Type<false>)
- {
- return fun_(CastLhs::Cast(lhs), CastRhs::Cast(rhs));
- }
- ResultType Fire(BaseLhs& rhs, BaseRhs& lhs,Int2Type<true>)
- {
- return fun_(CastLhs::Cast(lhs), CastRhs::Cast(rhs));
- }
- public:
- FunctorDispatcherHelper(const Fun& fun) : fun_(fun) {}
-
- ResultType operator()(BaseLhs& lhs, BaseRhs& rhs)
- {
- return Fire(lhs,rhs,Int2Type<SwapArgs>());
- }
- };
- }
-
-
- template <class BaseLhs, class BaseRhs = BaseLhs,
- typename ResultType = void,
- template <class, class> class CastingPolicy = DynamicCaster,
- template <class, class, class, class>
- class DispatcherBackend = BasicDispatcher>
- class FunctorDispatcher
- {
- typedef TYPELIST_2(BaseLhs&, BaseRhs&) ArgsList;
- typedef Functor<ResultType, ArgsList, DEFAULT_THREADING> FunctorType;
-
- DispatcherBackend<BaseLhs, BaseRhs, ResultType, FunctorType> backEnd_;
-
- public:
- template <class SomeLhs, class SomeRhs, class Fun>
- void Add(const Fun& fun)
- {
- typedef Private::FunctorDispatcherHelper<
- BaseLhs, BaseRhs,
- SomeLhs, SomeRhs,
- ResultType,
- CastingPolicy<SomeLhs, BaseLhs>,
- CastingPolicy<SomeRhs, BaseRhs>,
- Fun, false> Adapter;
-
- backEnd_.template Add<SomeLhs, SomeRhs>(FunctorType(Adapter(fun)));
- }
- template <class SomeLhs, class SomeRhs, bool symmetric, class Fun>
- void Add(const Fun& fun)
- {
- Add<SomeLhs,SomeRhs>(fun);
-
- if (symmetric)
- {
-
- typedef Private::FunctorDispatcherHelper<
- BaseLhs, BaseLhs,
- SomeLhs, SomeRhs,
- ResultType,
- CastingPolicy<SomeLhs, BaseLhs>,
- CastingPolicy<SomeRhs, BaseLhs>,
- Fun, true> AdapterR;
-
- backEnd_.template Add<SomeRhs, SomeLhs>(FunctorType(AdapterR(fun)));
- }
- }
-
- template <class SomeLhs, class SomeRhs>
- void Remove()
- {
- backEnd_.template Remove<SomeLhs, SomeRhs>();
- }
-
- ResultType Go(BaseLhs& lhs, BaseRhs& rhs)
- {
- return backEnd_.Go(lhs, rhs);
- }
- };
- }
-
-
- #endif
-
MultiMethods.h 접기
-
NullType.h 보기
-
-
- #ifndef NULLTYPE_INC_
- #define NULLTYPE_INC_
-
- namespace Loki
- {
-
- class NullType {};
-
- }
-
-
- #endif
-
NullType.h 접기
-
Singleton.h 보기
-
- #ifndef SINGLETON_INC_
- #define SINGLETON_INC_
-
- #include
- #include
- #include
- #include
- #include
- #include
-
- #ifdef _MSC_VER
- #define C_CALLING_CONVENTION_QUALIFIER __cdecl
- #else
- #define C_CALLING_CONVENTION_QUALIFIER
- #endif
-
- namespace Loki
- {
- typedef void (C_CALLING_CONVENTION_QUALIFIER *atexit_pfn_t)();
-
- namespace Private
- {
-
- class LifetimeTracker
- {
- public:
- LifetimeTracker(unsigned int x) : longevity_(x)
- {}
-
- virtual ~LifetimeTracker() = 0;
-
- static bool Compare(const LifetimeTracker* lhs,
- const LifetimeTracker* rhs)
- {
- return lhs->longevity_ < rhs->longevity_;
- }
-
- private:
- unsigned int longevity_;
- };
-
-
- inline LifetimeTracker::~LifetimeTracker() {}
-
-
- typedef LifetimeTracker** TrackerArray;
- extern TrackerArray pTrackerArray;
- extern unsigned int elements;
-
-
- template <typename T>
- struct Deleter
- {
- static void Delete(T* pObj)
- { delete pObj; }
- };
-
-
- template <typename T, typename Destroyer>
- class ConcreteLifetimeTracker : public LifetimeTracker
- {
- public:
- ConcreteLifetimeTracker(T* p,unsigned int longevity, Destroyer d)
- : LifetimeTracker(longevity)
- , pTracked_(p)
- , destroyer_(d)
- {}
-
- ~ConcreteLifetimeTracker()
- { destroyer_(pTracked_); }
-
- private:
- T* pTracked_;
- Destroyer destroyer_;
- };
-
- void C_CALLING_CONVENTION_QUALIFIER AtExitFn();
- }
-
-
- template <typename T, typename Destroyer>
- void SetLongevity(T* pDynObject, unsigned int longevity,
- Destroyer d = Private::Deleter<T>::Delete)
- {
- using namespace Private;
-
- TrackerArray pNewArray = static_cast<TrackerArray>(
- std::realloc(pTrackerArray,
- sizeof(*pTrackerArray) * (elements + 1)));
- if (!pNewArray) throw std::bad_alloc();
-
-
- pTrackerArray = pNewArray;
-
- LifetimeTracker* p = new ConcreteLifetimeTracker<T, Destroyer>(
- pDynObject, longevity, d);
-
-
- TrackerArray pos = std::upper_bound(
- pTrackerArray,
- pTrackerArray + elements,
- p,
- LifetimeTracker::Compare);
- std::copy_backward(
- pos,
- pTrackerArray + elements,
- pTrackerArray + elements + 1);
- *pos = p;
- ++elements;
-
-
- std::atexit(Private::AtExitFn);
- }
-
-
- template <class T> struct CreateUsingNew
- {
- static T* Create()
- { return new T; }
-
- static void Destroy(T* p)
- { delete p; }
- };
-
-
- template <class T> struct CreateUsingMalloc
- {
- static T* Create()
- {
- void* p = std::malloc(sizeof(T));
- if (!p) return 0;
- return new(p) T;
- }
-
- static void Destroy(T* p)
- {
- p->~T();
- std::free(p);
- }
- };
-
-
- template <class T> struct CreateStatic
- {
- #if defined(_MSC_VER) && _MSC_VER >= 1300
- #pragma warning( push )
-
- #pragma warning( disable : 4121 )
- #endif
- union MaxAlign
- {
- char t_[sizeof(T)];
- short int shortInt_;
- int int_;
- long int longInt_;
- float float_;
- double double_;
- long double longDouble_;
- struct Test;
- int Test::* pMember_;
- int (Test::*pMemberFn_)(int);
- };
- #if defined(_MSC_VER) && _MSC_VER >= 1300
- #pragma warning( pop )
- #endif
-
- static T* Create()
- {
- static MaxAlign staticMemory_;
- return new(&staticMemory_) T;
- }
-
- static void Destroy(T* p)
- {
- p->~T();
- }
- };
-
-
- template <class T>
- struct DefaultLifetime
- {
- static void ScheduleDestruction(T*, atexit_pfn_t pFun)
- { std::atexit(pFun); }
-
- static void OnDeadReference()
- { throw std::logic_error("Dead Reference Detected"); }
- };
-
-
- template <class T>
- class PhoenixSingleton
- {
- public:
- static void ScheduleDestruction(T*, atexit_pfn_t pFun)
- {
- #ifndef ATEXIT_FIXED
- if (!destroyedOnce_)
- #endif
- std::atexit(pFun);
- }
-
- static void OnDeadReference()
- {
- #ifndef ATEXIT_FIXED
- destroyedOnce_ = true;
- #endif
- }
-
- private:
- #ifndef ATEXIT_FIXED
- static bool destroyedOnce_;
- #endif
- };
-
- #ifndef ATEXIT_FIXED
- template <class T> bool PhoenixSingleton<T>::destroyedOnce_ = false;
- #endif
-
-
- namespace Private
- {
- template <class T>
- struct Adapter
- {
- void operator()(T*) { return pFun_(); }
- atexit_pfn_t pFun_;
- };
- }
-
-
- template <class T>
- class SingletonWithLongevity
- {
- public:
- static void ScheduleDestruction(T* pObj, atexit_pfn_t pFun)
- {
- Private::Adapter<T> adapter = { pFun };
- SetLongevity(pObj, GetLongevity(pObj), adapter);
- }
-
- static void OnDeadReference()
- { throw std::logic_error("Dead Reference Detected"); }
- };
-
-
- template <class T>
- struct NoDestroy
- {
- static void ScheduleDestruction(T*, atexit_pfn_t pFun)
- {}
-
- static void OnDeadReference()
- {}
- };
-
-
- template
- <
- typename T,
- template <class> class CreationPolicy = CreateUsingNew,
- template <class> class LifetimePolicy = DefaultLifetime,
- template <class> class ThreadingModel = SingleThreaded
- >
- class SingletonHolder
- {
- public:
- static T& Instance();
-
- private:
-
- static void MakeInstance();
- static void C_CALLING_CONVENTION_QUALIFIER DestroySingleton();
-
-
- SingletonHolder();
-
-
- typedef typename ThreadingModel<T*>::VolatileType PtrInstanceType;
- static PtrInstanceType pInstance_;
- static bool destroyed_;
- };
-
-
- template
- <
- class T,
- template <class> class C,
- template <class> class L,
- template <class> class M
- >
- typename SingletonHolder<T, C, L, M>::PtrInstanceType
- SingletonHolder<T, C, L, M>::pInstance_;
-
- template
- <
- class T,
- template <class> class C,
- template <class> class L,
- template <class> class M
- >
- bool SingletonHolder<T, C, L, M>::destroyed_;
-
-
- template
- <
- class T,
- template <class> class CreationPolicy,
- template <class> class LifetimePolicy,
- template <class> class ThreadingModel
- >
- inline T& SingletonHolder<T, CreationPolicy,
- LifetimePolicy, ThreadingModel>::Instance()
- {
- if (!pInstance_)
- {
- MakeInstance();
- }
- return *pInstance_;
- }
-
-
- template
- <
- class T,
- template <class> class CreationPolicy,
- template <class> class LifetimePolicy,
- template <class> class ThreadingModel
- >
- void SingletonHolder<T, CreationPolicy,
- LifetimePolicy, ThreadingModel>::MakeInstance()
- {
- typename ThreadingModel<T>::Lock guard;
- (void)guard;
-
- if (!pInstance_)
- {
- if (destroyed_)
- {
- LifetimePolicy<T>::OnDeadReference();
- destroyed_ = false;
- }
- pInstance_ = CreationPolicy<T>::Create();
- LifetimePolicy<T>::ScheduleDestruction(pInstance_,
- &DestroySingleton);
- }
- }
-
- template
- <
- class T,
- template <class> class CreationPolicy,
- template <class> class L,
- template <class> class M
- >
- void C_CALLING_CONVENTION_QUALIFIER
- SingletonHolder<T, CreationPolicy, L, M>::DestroySingleton()
- {
- assert(!destroyed_);
- CreationPolicy<T>::Destroy(pInstance_);
- pInstance_ = 0;
- destroyed_ = true;
- }
- }
-
-
- #endif
-
Singleton.h 접기
Singleton.cpp 보기
-
-
- #include
-
- using namespace Loki::Private;
-
- Loki::Private::TrackerArray Loki::Private::pTrackerArray = 0;
- unsigned int Loki::Private::elements = 0;
-
-
- void C_CALLING_CONVENTION_QUALIFIER Loki::Private::AtExitFn()
- {
- assert(elements > 0 && pTrackerArray != 0);
-
- LifetimeTracker* pTop = pTrackerArray[elements - 1];
-
-
-
- pTrackerArray = static_cast<TrackerArray>(std::realloc(
- pTrackerArray, sizeof(*pTrackerArray) * --elements));
-
- delete pTop;
- }
-
-
Singleton.cpp 접기
-
SmallObj.h 보기
-
-
- #ifndef SMALLOBJ_INC_
- #define SMALLOBJ_INC_
-
- #include
- #include
- #include
- #include
-
- #ifndef DEFAULT_CHUNK_SIZE
- #define DEFAULT_CHUNK_SIZE 4096
- #endif
-
- #ifndef MAX_SMALL_OBJECT_SIZE
- #define MAX_SMALL_OBJECT_SIZE 64
- #endif
-
- namespace Loki
- {
-
- class FixedAllocator
- {
- private:
- struct Chunk
- {
- void Init(std::size_t blockSize, unsigned char blocks);
- void* Allocate(std::size_t blockSize);
- void Deallocate(void* p, std::size_t blockSize);
- void Reset(std::size_t blockSize, unsigned char blocks);
- void Release();
- unsigned char* pData_;
- unsigned char
- firstAvailableBlock_,
- blocksAvailable_;
- };
-
-
- void DoDeallocate(void* p);
- Chunk* VicinityFind(void* p);
-
-
- std::size_t blockSize_;
- unsigned char numBlocks_;
- typedef std::vector<Chunk> Chunks;
- Chunks chunks_;
- Chunk* allocChunk_;
- Chunk* deallocChunk_;
-
- mutable const FixedAllocator* prev_;
- mutable const FixedAllocator* next_;
-
- public:
-
- explicit FixedAllocator(std::size_t blockSize = 0);
- FixedAllocator(const FixedAllocator&);
- FixedAllocator& operator=(const FixedAllocator&);
- ~FixedAllocator();
-
- void Swap(FixedAllocator& rhs);
-
-
- void* Allocate();
-
-
- void Deallocate(void* p);
-
- std::size_t BlockSize() const
- { return blockSize_; }
- };
-
-
- class SmallObjAllocator
- {
- public:
- SmallObjAllocator(
- std::size_t chunkSize,
- std::size_t maxObjectSize);
-
- void* Allocate(std::size_t numBytes);
- void Deallocate(void* p, std::size_t size);
-
- private:
- SmallObjAllocator(const SmallObjAllocator&);
- SmallObjAllocator& operator=(const SmallObjAllocator&);
-
- typedef std::vector<FixedAllocator> Pool;
- Pool pool_;
- FixedAllocator* pLastAlloc_;
- FixedAllocator* pLastDealloc_;
- std::size_t chunkSize_;
- std::size_t maxObjectSize_;
- };
-
-
- template
- <
- template <class> class ThreadingModel = DEFAULT_THREADING,
- std::size_t chunkSize = DEFAULT_CHUNK_SIZE,
- std::size_t maxSmallObjectSize = MAX_SMALL_OBJECT_SIZE
- >
- class SmallObject : public ThreadingModel<
- SmallObject<ThreadingModel, chunkSize, maxSmallObjectSize> >
- {
- typedef ThreadingModel< SmallObject<ThreadingModel,
- chunkSize, maxSmallObjectSize> > MyThreadingModel;
-
- struct MySmallObjAllocator : public SmallObjAllocator
- {
- MySmallObjAllocator()
- : SmallObjAllocator(chunkSize, maxSmallObjectSize)
- {}
- };
-
-
-
-
-
- public:
- static void* operator new(std::size_t size)
- {
- #if (MAX_SMALL_OBJECT_SIZE != 0) && (DEFAULT_CHUNK_SIZE != 0)
- typename MyThreadingModel::Lock lock;
- (void)lock;
-
- return SingletonHolder<MySmallObjAllocator, CreateStatic,
- PhoenixSingleton>::Instance().Allocate(size);
- #else
- return ::operator new(size);
- #endif
- }
- static void operator delete(void* p, std::size_t size)
- {
- #if (MAX_SMALL_OBJECT_SIZE != 0) && (DEFAULT_CHUNK_SIZE != 0)
- typename MyThreadingModel::Lock lock;
- (void)lock;
-
- SingletonHolder<MySmallObjAllocator, CreateStatic,
- PhoenixSingleton>::Instance().Deallocate(p, size);
- #else
- ::operator delete(p);
- #endif
- }
- virtual ~SmallObject() {}
- };
- }
-
-
- #endif
-
SmallObj.h 접기
SmallObj.cpp 보기
-
-
- #include
- #include
- #include
- #include
-
- using namespace Loki;
-
-
- void FixedAllocator::Chunk::Init(std::size_t blockSize, unsigned char blocks)
- {
- assert(blockSize > 0);
- assert(blocks > 0);
-
- assert((blockSize * blocks) / blockSize == blocks);
-
- pData_ = new unsigned char[blockSize * blocks];
- Reset(blockSize, blocks);
- }
-
-
- void FixedAllocator::Chunk::Reset(std::size_t blockSize, unsigned char blocks)
- {
- assert(blockSize > 0);
- assert(blocks > 0);
-
- assert((blockSize * blocks) / blockSize == blocks);
-
- firstAvailableBlock_ = 0;
- blocksAvailable_ = blocks;
-
- unsigned char i = 0;
- unsigned char* p = pData_;
- for (; i != blocks; p += blockSize)
- {
- *p = ++i;
- }
- }
-
-
- void FixedAllocator::Chunk::Release()
- {
- delete[] pData_;
- }
-
-
- void* FixedAllocator::Chunk::Allocate(std::size_t blockSize)
- {
- if (!blocksAvailable_) return 0;
-
- assert((firstAvailableBlock_ * blockSize) / blockSize ==
- firstAvailableBlock_);
-
- unsigned char* pResult =
- pData_ + (firstAvailableBlock_ * blockSize);
- firstAvailableBlock_ = *pResult;
- --blocksAvailable_;
-
- return pResult;
- }
-
-
- void FixedAllocator::Chunk::Deallocate(void* p, std::size_t blockSize)
- {
- assert(p >= pData_);
-
- unsigned char* toRelease = static_cast<unsigned char*>(p);
-
- assert((toRelease - pData_) % blockSize == 0);
-
- *toRelease = firstAvailableBlock_;
- firstAvailableBlock_ = static_cast<unsigned char>(
- (toRelease - pData_) / blockSize);
-
- assert(firstAvailableBlock_ == (toRelease - pData_) / blockSize);
-
- ++blocksAvailable_;
- }
-
-
- FixedAllocator::FixedAllocator(std::size_t blockSize)
- : blockSize_(blockSize)
- , allocChunk_(0)
- , deallocChunk_(0)
- {
- assert(blockSize_ > 0);
-
- prev_ = next_ = this;
-
- std::size_t numBlocks = DEFAULT_CHUNK_SIZE / blockSize;
- if (numBlocks > UCHAR_MAX) numBlocks = UCHAR_MAX;
- else if (numBlocks == 0) numBlocks = 8 * blockSize;
-
- numBlocks_ = static_cast<unsigned char>(numBlocks);
- assert(numBlocks_ == numBlocks);
- }
-
-
- FixedAllocator::FixedAllocator(const FixedAllocator& rhs)
- : blockSize_(rhs.blockSize_)
- , numBlocks_(rhs.numBlocks_)
- , chunks_(rhs.chunks_)
- {
- prev_ = &rhs;
- next_ = rhs.next_;
- rhs.next_->prev_ = this;
- rhs.next_ = this;
-
- allocChunk_ = rhs.allocChunk_
- ? &chunks_.front() + (rhs.allocChunk_ - &rhs.chunks_.front())
- : 0;
-
- deallocChunk_ = rhs.deallocChunk_
- ? &chunks_.front() + (rhs.deallocChunk_ - &rhs.chunks_.front())
- : 0;
- }
-
- FixedAllocator& FixedAllocator::operator=(const FixedAllocator& rhs)
- {
- FixedAllocator copy(rhs);
- copy.Swap(*this);
- return *this;
- }
-
-
- FixedAllocator::~FixedAllocator()
- {
- if (prev_ != this)
- {
- prev_->next_ = next_;
- next_->prev_ = prev_;
- return;
- }
-
- assert(prev_ == next_);
- Chunks::iterator i = chunks_.begin();
- for (; i != chunks_.end(); ++i)
- {
- assert(i->blocksAvailable_ == numBlocks_);
- i->Release();
- }
- }
-
-
- void FixedAllocator::Swap(FixedAllocator& rhs)
- {
- using namespace std;
-
- swap(blockSize_, rhs.blockSize_);
- swap(numBlocks_, rhs.numBlocks_);
- chunks_.swap(rhs.chunks_);
- swap(allocChunk_, rhs.allocChunk_);
- swap(deallocChunk_, rhs.deallocChunk_);
- }
-
-
- void* FixedAllocator::Allocate()
- {
- if (allocChunk_ == 0 || allocChunk_->blocksAvailable_ == 0)
- {
- Chunks::iterator i = chunks_.begin();
- for (;; ++i)
- {
- if (i == chunks_.end())
- {
-
- chunks_.reserve(chunks_.size() + 1);
- Chunk newChunk;
- newChunk.Init(blockSize_, numBlocks_);
- chunks_.push_back(newChunk);
- allocChunk_ = &chunks_.back();
- deallocChunk_ = &chunks_.front();
- break;
- }
- if (i->blocksAvailable_ > 0)
- {
- allocChunk_ = &*i;
- break;
- }
- }
- }
- assert(allocChunk_ != 0);
- assert(allocChunk_->blocksAvailable_ > 0);
-
- return allocChunk_->Allocate(blockSize_);
- }
-
-
- void FixedAllocator::Deallocate(void* p)
- {
- assert(!chunks_.empty());
- assert(&chunks_.front() <= deallocChunk_);
- assert(&chunks_.back() >= deallocChunk_);
-
- deallocChunk_ = VicinityFind(p);
- assert(deallocChunk_);
-
- DoDeallocate(p);
- }
-
-
- FixedAllocator::Chunk* FixedAllocator::VicinityFind(void* p)
- {
- assert(!chunks_.empty());
- assert(deallocChunk_);
-
- const std::size_t chunkLength = numBlocks_ * blockSize_;
-
- Chunk* lo = deallocChunk_;
- Chunk* hi = deallocChunk_ + 1;
- Chunk* loBound = &chunks_.front();
- Chunk* hiBound = &chunks_.back() + 1;
-
-
- if (hi == hiBound) hi = 0;
-
- for (;;)
- {
- if (lo)
- {
- if (p >= lo->pData_ && p < lo->pData_ + chunkLength)
- {
- return lo;
- }
- if (lo == loBound) lo = 0;
- else --lo;
- }
-
- if (hi)
- {
- if (p >= hi->pData_ && p < hi->pData_ + chunkLength)
- {
- return hi;
- }
- if (++hi == hiBound) hi = 0;
- }
- }
- assert(false);
- return 0;
- }
-
-
- void FixedAllocator::DoDeallocate(void* p)
- {
- assert(deallocChunk_->pData_ <= p);
- assert(deallocChunk_->pData_ + numBlocks_ * blockSize_ > p);
-
-
- deallocChunk_->Deallocate(p, blockSize_);
-
- if (deallocChunk_->blocksAvailable_ == numBlocks_)
- {
-
-
- Chunk& lastChunk = chunks_.back();
-
- if (&lastChunk == deallocChunk_)
- {
-
-
- if (chunks_.size() > 1 &&
- deallocChunk_[-1].blocksAvailable_ == numBlocks_)
- {
-
- lastChunk.Release();
- chunks_.pop_back();
- allocChunk_ = deallocChunk_ = &chunks_.front();
- }
- return;
- }
-
- if (lastChunk.blocksAvailable_ == numBlocks_)
- {
-
- lastChunk.Release();
- chunks_.pop_back();
- allocChunk_ = deallocChunk_;
- }
- else
- {
-
- std::swap(*deallocChunk_, lastChunk);
- allocChunk_ = &chunks_.back();
- }
- }
- }
-
-
- SmallObjAllocator::SmallObjAllocator(
- std::size_t chunkSize,
- std::size_t maxObjectSize)
- : pLastAlloc_(0), pLastDealloc_(0)
- , chunkSize_(chunkSize), maxObjectSize_(maxObjectSize)
- {
- }
-
- namespace {
-
- struct CompareFixedAllocatorSize
- : std::binary_function<const FixedAllocator &, std::size_t, bool>
- {
- bool operator()(const FixedAllocator &x, std::size_t numBytes) const
- {
- return x.BlockSize() < numBytes;
- }
- };
-
- }
-
-
- void* SmallObjAllocator::Allocate(std::size_t numBytes)
- {
- if (numBytes > maxObjectSize_) return operator new(numBytes);
-
- if (pLastAlloc_ && pLastAlloc_->BlockSize() == numBytes)
- {
- return pLastAlloc_->Allocate();
- }
- Pool::iterator i = std::lower_bound(pool_.begin(), pool_.end(), numBytes,
- CompareFixedAllocatorSize());
- if (i == pool_.end() || i->BlockSize() != numBytes)
- {
- i = pool_.insert(i, FixedAllocator(numBytes));
- pLastDealloc_ = &*pool_.begin();
- }
- pLastAlloc_ = &*i;
- return pLastAlloc_->Allocate();
- }
-
-
- void SmallObjAllocator::Deallocate(void* p, std::size_t numBytes)
- {
- if (numBytes > maxObjectSize_) return operator delete(p);
-
- if (pLastDealloc_ && pLastDealloc_->BlockSize() == numBytes)
- {
- pLastDealloc_->Deallocate(p);
- return;
- }
- Pool::iterator i = std::lower_bound(pool_.begin(), pool_.end(), numBytes,
- CompareFixedAllocatorSize());
- assert(i != pool_.end());
- assert(i->BlockSize() == numBytes);
- pLastDealloc_ = &*i;
- pLastDealloc_->Deallocate(p);
- }
-
-
SmallObj.cpp 접기
-
SmartPtr.h 보기
-
- #ifndef SMARTPTR_INC_
- #define SMARTPTR_INC_
-
-
-
- #include
- #include
- #include
- #include
- #include
- #include
-
- namespace Loki
- {
-
-
- template <class T>
- class DefaultSPStorage
- {
- public:
- typedef T* StoredType;
- typedef T* PointerType;
- typedef T& ReferenceType;
-
- DefaultSPStorage() : pointee_(Default())
- {}
-
-
-
- DefaultSPStorage(const DefaultSPStorage&)
- {}
-
- template <class U>
- DefaultSPStorage(const DefaultSPStorage<U>&)
- {}
-
- DefaultSPStorage(const StoredType& p) : pointee_(p) {}
-
- PointerType operator->() const { return pointee_; }
-
- ReferenceType operator*() const { return *pointee_; }
-
- void Swap(DefaultSPStorage& rhs)
- { std::swap(pointee_, rhs.pointee_); }
-
-
- friend inline PointerType GetImpl(const DefaultSPStorage& sp)
- { return sp.pointee_; }
-
- friend inline const StoredType& GetImplRef(const DefaultSPStorage& sp)
- { return sp.pointee_; }
-
- friend inline StoredType& GetImplRef(DefaultSPStorage& sp)
- { return sp.pointee_; }
-
- protected:
-
-
- void Destroy()
- { delete pointee_; }
-
-
- static StoredType Default()
- { return 0; }
-
- private:
-
- StoredType pointee_;
- };
-
-
- template <class P>
- class RefCounted
- {
- public:
- RefCounted()
- {
- pCount_ = static_cast<unsigned int*>(
- SmallObject<>::operator new(sizeof(unsigned int)));
- assert(pCount_);
- *pCount_ = 1;
- }
-
- RefCounted(const RefCounted& rhs)
- : pCount_(rhs.pCount_)
- {}
-
-
- template <typename P1>
- RefCounted(const RefCounted<P1>& rhs)
- : pCount_(reinterpret_cast<const RefCounted&>(rhs).pCount_)
- {}
-
- P Clone(const P& val)
- {
- ++*pCount_;
- return val;
- }
-
- bool Release(const P&)
- {
- if (!--*pCount_)
- {
- SmallObject<>::operator delete(pCount_, sizeof(unsigned int));
- return true;
- }
- return false;
- }
-
- void Swap(RefCounted& rhs)
- { std::swap(pCount_, rhs.pCount_); }
-
- enum { destructiveCopy = false };
-
- private:
-
- unsigned int* pCount_;
- };
-
-
- template <template <class> class ThreadingModel>
- struct RefCountedMTAdj
- {
- template <class P>
- class RefCountedMT : public ThreadingModel< RefCountedMT<P> >
- {
- typedef ThreadingModel< RefCountedMT<P> > base_type;
- typedef typename base_type::IntType CountType;
- typedef volatile CountType *CountPtrType;
-
- public:
- RefCountedMT()
- {
- pCount_ = static_cast<CountPtrType>(
- SmallObject<ThreadingModel>::operator new(
- sizeof(*pCount_)));
- assert(pCount_);
- *pCount_ = 1;
- }
-
- RefCountedMT(const RefCountedMT& rhs)
- : pCount_(rhs.pCount_)
- {}
-
-
- template <typename P1>
- RefCountedMT(const RefCountedMT<P1>& rhs)
- : pCount_(reinterpret_cast<const RefCountedMT<P>&>(rhs).pCount_)
- {}
-
- P Clone(const P& val)
- {
- ThreadingModel<RefCountedMT>::AtomicIncrement(*pCount_);
- return val;
- }
-
- bool Release(const P&)
- {
- if (!ThreadingModel<RefCountedMT>::AtomicDecrement(*pCount_))
- {
- SmallObject<ThreadingModel>::operator delete(
- const_cast<CountType *>(pCount_),
- sizeof(*pCount_));
- return true;
- }
- return false;
- }
-
- void Swap(RefCountedMT& rhs)
- { std::swap(pCount_, rhs.pCount_); }
-
- enum { destructiveCopy = false };
-
- private:
-
- CountPtrType pCount_;
- };
- };
-
-
- template <class P>
- class COMRefCounted
- {
- public:
- COMRefCounted()
- {}
-
- template <class U>
- COMRefCounted(const COMRefCounted<U>&)
- {}
-
- static P Clone(const P& val)
- {
- val->AddRef();
- return val;
- }
-
- static bool Release(const P& val)
- { val->Release(); return false; }
-
- enum { destructiveCopy = false };
-
- static void Swap(COMRefCounted&)
- {}
- };
-
-
- template <class P>
- struct DeepCopy
- {
- DeepCopy()
- {}
-
- template <class P1>
- DeepCopy(const DeepCopy<P1>&)
- {}
-
- static P Clone(const P& val)
- { return val->Clone(); }
-
- static bool Release(const P& val)
- { return true; }
-
- static void Swap(DeepCopy&)
- {}
-
- enum { destructiveCopy = false };
- };
-
-
- namespace Private
- {
- class RefLinkedBase
- {
- public:
- RefLinkedBase()
- { prev_ = next_ = this; }
-
- RefLinkedBase(const RefLinkedBase& rhs)
- {
- prev_ = &rhs;
- next_ = rhs.next_;
- prev_->next_ = this;
- next_->prev_ = this;
- }
-
- bool Release()
- {
- if (next_ == this)
- {
- assert(prev_ == this);
- return true;
- }
- prev_->next_ = next_;
- next_->prev_ = prev_;
- return false;
- }
-
- void Swap(RefLinkedBase& rhs)
- {
- if (next_ == this)
- {
- assert(prev_ == this);
- if (rhs.next_ == &rhs)
- {
- assert(rhs.prev_ == &rhs);
-
- return;
- }
- prev_ = rhs.prev_;
- next_ = rhs.next_;
- prev_->next_ = next_->prev_ = this;
- rhs.next_ = rhs.prev_ = &rhs;
- return;
- }
- if (rhs.next_ == &rhs)
- {
- rhs.Swap(*this);
- return;
- }
- std::swap(prev_, rhs.prev_);
- std::swap(next_, rhs.next_);
- std::swap(prev_->next_, rhs.prev_->next_);
- std::swap(next_->prev_, rhs.next_->prev_);
- }
-
- enum { destructiveCopy = false };
-
- private:
- mutable const RefLinkedBase* prev_;
- mutable const RefLinkedBase* next_;
- };
- }
-
- template <class P>
- class RefLinked : public Private::RefLinkedBase
- {
- public:
- RefLinked()
- {}
-
- template <class P1>
- RefLinked(const RefLinked<P1>& rhs)
- : Private::RefLinkedBase(rhs)
- {}
-
- static P Clone(const P& val)
- { return val; }
-
- bool Release(const P&)
- { return Private::RefLinkedBase::Release(); }
- };
-
-
- template <class P>
- class DestructiveCopy
- {
- public:
- DestructiveCopy()
- {}
-
- template <class P1>
- DestructiveCopy(const DestructiveCopy<P1>&)
- {}
-
- template <class P1>
- static P Clone(P1& val)
- {
- P result(val);
- val = P1();
- return result;
- }
-
- static bool Release(const P&)
- { return true; }
-
- static void Swap(DestructiveCopy&)
- {}
-
- enum { destructiveCopy = true };
- };
-
-
- template <class P>
- class NoCopy
- {
- public:
- NoCopy()
- {}
-
- template <class P1>
- NoCopy(const NoCopy<P1>&)
- {}
-
- static P Clone(const P&)
- {
-
- static const bool DependedFalse = sizeof(P*) == 0;
-
- STATIC_CHECK(DependedFalse, This_Policy_Disallows_Value_Copying);
- }
-
- static bool Release(const P&)
- { return true; }
-
- static void Swap(NoCopy&)
- {}
-
- enum { destructiveCopy = false };
- };
-
-
- struct AllowConversion
- {
- enum { allow = true };
-
- void Swap(AllowConversion&)
- {}
- };
-
-
- struct DisallowConversion
- {
- DisallowConversion()
- {}
-
- DisallowConversion(const AllowConversion&)
- {}
-
- enum { allow = false };
-
- void Swap(DisallowConversion&)
- {}
- };
-
-
- template <class P>
- struct NoCheck
- {
- NoCheck()
- {}
-
- template <class P1>
- NoCheck(const NoCheck<P1>&)
- {}
-
- static void OnDefault(const P&)
- {}
-
- static void OnInit(const P&)
- {}
-
- static void OnDereference(const P&)
- {}
-
- static void Swap(NoCheck&)
- {}
- };
-
-
-
- template <class P>
- struct AssertCheck
- {
- AssertCheck()
- {}
-
- template <class P1>
- AssertCheck(const AssertCheck<P1>&)
- {}
-
- template <class P1>
- AssertCheck(const NoCheck<P1>&)
- {}
-
- static void OnDefault(const P&)
- {}
-
- static void OnInit(const P&)
- {}
-
- static void OnDereference(P val)
- { assert(val); (void)val; }
-
- static void Swap(AssertCheck&)
- {}
- };
-
-
- template <class P>
- struct AssertCheckStrict
- {
- AssertCheckStrict()
- {}
-
- template <class U>
- AssertCheckStrict(const AssertCheckStrict<U>&)
- {}
-
- template <class U>
- AssertCheckStrict(const AssertCheck<U>&)
- {}
-
- template <class P1>
- AssertCheckStrict(const NoCheck<P1>&)
- {}
-
- static void OnDefault(P val)
- { assert(val); }
-
- static void OnInit(P val)
- { assert(val); }
-
- static void OnDereference(P val)
- { assert(val); }
-
- static void Swap(AssertCheckStrict&)
- {}
- };
-
-
- struct NullPointerException : public std::runtime_error
- {
- NullPointerException() : std::runtime_error("")
- { }
- const char* what() const throw()
- { return "Null Pointer Exception"; }
- };
-
-
- template <class P>
- struct RejectNullStatic
- {
- RejectNullStatic()
- {}
-
- template <class P1>
- RejectNullStatic(const RejectNullStatic<P1>&)
- {}
-
- template <class P1>
- RejectNullStatic(const NoCheck<P1>&)
- {}
-
- template <class P1>
- RejectNullStatic(const AssertCheck<P1>&)
- {}
-
- template <class P1>
- RejectNullStatic(const AssertCheckStrict<P1>&)
- {}
-
- static void OnDefault(const P&)
- {
-
- static const bool DependedFalse = sizeof(P*) == 0;
-
- STATIC_CHECK(DependedFalse, ERROR_This_Policy_Does_Not_Allow_Default_Initialization);
- }
-
- static void OnInit(const P& val)
- { if (!val) throw NullPointerException(); }
-
- static void OnDereference(const P& val)
- { if (!val) throw NullPointerException(); }
-
- static void Swap(RejectNullStatic&)
- {}
- };
-
-
- template <class P>
- struct RejectNull
- {
- RejectNull()
- {}
-
- template <class P1>
- RejectNull(const RejectNull<P1>&)
- {}
-
- static void OnInit(P val)
- { if (!val) throw NullPointerException(); }
-
- static void OnDefault(P val)
- { OnInit(val); }
-
- void OnDereference(P val)
- { OnInit(val); }
-
- void Swap(RejectNull&)
- {}
- };
-
-
- template <class P>
- struct RejectNullStrict
- {
- RejectNullStrict()
- {}
-
- template <class P1>
- RejectNullStrict(const RejectNullStrict<P1>&)
- {}
-
- template <class P1>
- RejectNullStrict(const RejectNull<P1>&)
- {}
-
- static void OnInit(P val)
- { if (!val) throw NullPointerException(); }
-
- void OnDereference(P val)
- { OnInit(val); }
-
- void Swap(RejectNullStrict&)
- {}
- };
-
-
- template <class T>
- class ByRef
- {
- public:
- ByRef(T& v) : value_(v) {}
- operator T&() { return value_; }
-
-
- private:
- ByRef& operator=(const ByRef &);
- T& value_;
- };
-
-
- template
- <
- typename T,
- template <class> class OwnershipPolicy = RefCounted,
- class ConversionPolicy = DisallowConversion,
- template <class> class CheckingPolicy = AssertCheck,
- template <class> class StoragePolicy = DefaultSPStorage
- >
- class SmartPtr;
-
-
- template
- <
- typename T,
- template <class> class OwnershipPolicy = RefCounted,
- class ConversionPolicy = DisallowConversion,
- template <class> class CheckingPolicy = AssertCheck,
- template <class> class StoragePolicy = DefaultSPStorage
- >
- struct SmartPtrDef
- {
- typedef SmartPtr
- <
- T,
- OwnershipPolicy,
- ConversionPolicy,
- CheckingPolicy,
- StoragePolicy
- >
- type;
- };
-
-
- template
- <
- typename T,
- template <class> class OwnershipPolicy,
- class ConversionPolicy,
- template <class> class CheckingPolicy,
- template <class> class StoragePolicy
- >
- class SmartPtr
- : public StoragePolicy<T>
- , public OwnershipPolicy<typename StoragePolicy<T>::PointerType>
- , public CheckingPolicy<typename StoragePolicy<T>::StoredType>
- , public ConversionPolicy
- {
- typedef StoragePolicy<T> SP;
- typedef OwnershipPolicy<typename StoragePolicy<T>::PointerType> OP;
- typedef CheckingPolicy<typename StoragePolicy<T>::StoredType> KP;
- typedef ConversionPolicy CP;
-
- public:
- typedef typename SP::PointerType PointerType;
- typedef typename SP::StoredType StoredType;
- typedef typename SP::ReferenceType ReferenceType;
-
- typedef typename Select<OP::destructiveCopy,
- SmartPtr, const SmartPtr>::Result
- CopyArg;
-
- private:
- struct NeverMatched;
-
- #ifdef LOKI_SMARTPTR_CONVERSION_CONSTRUCTOR_POLICY
- typedef typename Select< CP::allow, const StoredType&, NeverMatched>::Result ImplicitArg;
- typedef typename Select<!CP::allow, const StoredType&, NeverMatched>::Result ExplicitArg;
- #else
- typedef const StoredType& ImplicitArg;
- typedef typename Select<false, const StoredType&, NeverMatched>::Result ExplicitArg;
- #endif
-
- public:
-
- SmartPtr()
- { KP::OnDefault(GetImpl(*this)); }
-
- explicit
- SmartPtr(ExplicitArg p) : SP(p)
- { KP::OnInit(GetImpl(*this)); }
-
- SmartPtr(ImplicitArg p) : SP(p)
- { KP::OnInit(GetImpl(*this)); }
-
- SmartPtr(CopyArg& rhs)
- : SP(rhs), OP(rhs), KP(rhs), CP(rhs)
- { GetImplRef(*this) = OP::Clone(GetImplRef(rhs)); }
-
- template
- <
- typename T1,
- template <class> class OP1,
- class CP1,
- template <class> class KP1,
- template <class> class SP1
- >
- SmartPtr(const SmartPtr<T1, OP1, CP1, KP1, SP1>& rhs)
- : SP(rhs), OP(rhs), KP(rhs), CP(rhs)
- { GetImplRef(*this) = OP::Clone(GetImplRef(rhs)); }
-
- template
- <
- typename T1,
- template <class> class OP1,
- class CP1,
- template <class> class KP1,
- template <class> class SP1
- >
- SmartPtr(SmartPtr<T1, OP1, CP1, KP1, SP1>& rhs)
- : SP(rhs), OP(rhs), KP(rhs), CP(rhs)
- { GetImplRef(*this) = OP::Clone(GetImplRef(rhs)); }
-
- SmartPtr(ByRef<SmartPtr> rhs)
- : SP(rhs), OP(rhs), KP(rhs), CP(rhs)
- {}
-
- operator ByRef<SmartPtr>()
- { return ByRef<SmartPtr>(*this); }
-
- SmartPtr& operator=(CopyArg& rhs)
- {
- SmartPtr temp(rhs);
- temp.Swap(*this);
- return *this;
- }
-
- template
- <
- typename T1,
- template <class> class OP1,
- class CP1,
- template <class> class KP1,
- template <class> class SP1
- >
- SmartPtr& operator=(const SmartPtr<T1, OP1, CP1, KP1, SP1>& rhs)
- {
- SmartPtr temp(rhs);
- temp.Swap(*this);
- return *this;
- }
-
- template
- <
- typename T1,
- template <class> class OP1,
- class CP1,
- template <class> class KP1,
- template <class> class SP1
- >
- SmartPtr& operator=(SmartPtr<T1, OP1, CP1, KP1, SP1>& rhs)
- {
- SmartPtr temp(rhs);
- temp.Swap(*this);
- return *this;
- }
-
- void Swap(SmartPtr& rhs)
- {
- OP::Swap(rhs);
- CP::Swap(rhs);
- KP::Swap(rhs);
- SP::Swap(rhs);
- }
-
- ~SmartPtr()
- {
- if (OP::Release(GetImpl(*static_cast<SP*>(this))))
- {
- SP::Destroy();
- }
- }
-
- friend inline void Release(SmartPtr& sp, typename SP::StoredType& p)
- {
- p = GetImplRef(sp);
- GetImplRef(sp) = SP::Default();
- }
-
- friend inline void Reset(SmartPtr& sp, typename SP::StoredType p)
- { SmartPtr(p).Swap(sp); }
-
- PointerType operator->()
- {
- KP::OnDereference(GetImplRef(*this));
- return SP::operator->();
- }
-
- PointerType operator->() const
- {
- KP::OnDereference(GetImplRef(*this));
- return SP::operator->();
- }
-
- ReferenceType operator*()
- {
- KP::OnDereference(GetImplRef(*this));
- return SP::operator*();
- }
-
- ReferenceType operator*() const
- {
- KP::OnDereference(GetImplRef(*this));
- return SP::operator*();
- }
-
- bool operator!() const
- { return GetImpl(*this) == 0; }
-
-
-
- template
- <
- typename T1,
- template <class> class OP1,
- class CP1,
- template <class> class KP1,
- template <class> class SP1
- >
- bool operator==(const SmartPtr<T1, OP1, CP1, KP1, SP1>& rhs) const
- { return GetImpl(*this) == GetImpl(rhs); }
-
-
- template
- <
- typename T1,
- template <class> class OP1,
- class CP1,
- template <class> class KP1,
- template <class> class SP1
- >
- bool operator!=(const SmartPtr<T1, OP1, CP1, KP1, SP1>& rhs) const
- { return !(*this == rhs); }
-
-
- template
- <
- typename T1,
- template <class> class OP1,
- class CP1,
- template <class> class KP1,
- template <class> class SP1
- >
- bool operator<(const SmartPtr<T1, OP1, CP1, KP1, SP1>& rhs) const
- { return GetImpl(*this) < GetImpl(rhs); }
-
- private:
-
- struct Tester
- {
- Tester(int) {}
- void dummy() {}
- };
-
- typedef void (Tester::*unspecified_boolean_type_)();
-
- typedef typename Select<CP::allow, Tester, unspecified_boolean_type_>::Result
- unspecified_boolean_type;
-
- public:
-
- operator unspecified_boolean_type() const
- {
- return !*this ? 0 : &Tester::dummy;
- }
-
- private:
-
- struct Insipid
- {
- Insipid(PointerType) {}
- };
-
- typedef typename Select<CP::allow, PointerType, Insipid>::Result
- AutomaticConversionResult;
-
- public:
- operator AutomaticConversionResult() const
- { return GetImpl(*this); }
- };
-
-
-
- template
- <
- typename T,
- template <class> class OP,
- class CP,
- template <class> class KP,
- template <class> class SP,
- typename U
- >
- inline bool operator==(const SmartPtr<T, OP, CP, KP, SP>& lhs,
- U* rhs)
- { return GetImpl(lhs) == rhs; }
-
-
- template
- <
- typename T,
- template <class> class OP,
- class CP,
- template <class> class KP,
- template <class> class SP,
- typename U
- >
- inline bool operator==(U* lhs,
- const SmartPtr<T, OP, CP, KP, SP>& rhs)
- { return rhs == lhs; }
-
-
- template
- <
- typename T,
- template <class> class OP,
- class CP,
- template <class> class KP,
- template <class> class SP,
- typename U
- >
- inline bool operator!=(const SmartPtr<T, OP, CP, KP, SP>& lhs,
- U* rhs)
- { return !(lhs == rhs); }
-
-
- template
- <
- typename T,
- template <class> class OP,
- class CP,
- template <class> class KP,
- template <class> class SP,
- typename U
- >
- inline bool operator!=(U* lhs,
- const SmartPtr<T, OP, CP, KP, SP>& rhs)
- { return rhs != lhs; }
-
-
- template
- <
- typename T,
- template <class> class OP,
- class CP,
- template <class> class KP,
- template <class> class SP,
- typename U
- >
- inline bool operator<(const SmartPtr<T, OP, CP, KP, SP>& lhs,
- U* rhs);
-
-
- template
- <
- typename T,
- template <class> class OP,
- class CP,
- template <class> class KP,
- template <class> class SP,
- typename U
- >
- inline bool operator<(U* lhs,
- const SmartPtr<T, OP, CP, KP, SP>& rhs);
-
-
- template
- <
- typename T,
- template <class> class OP,
- class CP,
- template <class> class KP,
- template <class> class SP,
- typename U
- >
- inline bool operator>(const SmartPtr<T, OP, CP, KP, SP>& lhs,
- U* rhs)
- { return rhs < lhs; }
-
-
- template
- <
- typename T,
- template <class> class OP,
- class CP,
- template <class> class KP,
- template <class> class SP,
- typename U
- >
- inline bool operator>(U* lhs,
- const SmartPtr<T, OP, CP, KP, SP>& rhs)
- { return rhs < lhs; }
-
-
- template
- <
- typename T,
- template <class> class OP,
- class CP,
- template <class> class KP,
- template <class> class SP,
- typename U
- >
- inline bool operator<=(const SmartPtr<T, OP, CP, KP, SP>& lhs,
- U* rhs)
- { return !(rhs < lhs); }
-
-
- template
- <
- typename T,
- template <class> class OP,
- class CP,
- template <class> class KP,
- template <class> class SP,
- typename U
- >
- inline bool operator<=(U* lhs,
- const SmartPtr<T, OP, CP, KP, SP>& rhs)
- { return !(rhs < lhs); }
-
-
- template
- <
- typename T,
- template <class> class OP,
- class CP,
- template <class> class KP,
- template <class> class SP,
- typename U
- >
- inline bool operator>=(const SmartPtr<T, OP, CP, KP, SP>& lhs,
- U* rhs)
- { return !(lhs < rhs); }
-
-
- template
- <
- typename T,
- template <class> class OP,
- class CP,
- template <class> class KP,
- template <class> class SP,
- typename U
- >
- inline bool operator>=(U* lhs,
- const SmartPtr<T, OP, CP, KP, SP>& rhs)
- { return !(lhs < rhs); }
-
- }
-
-
- namespace std
- {
- template
- <
- typename T,
- template <class> class OP,
- class CP,
- template <class> class KP,
- template <class> class SP
- >
- struct less< Loki::SmartPtr<T, OP, CP, KP, SP> >
- : public binary_function<Loki::SmartPtr<T, OP, CP, KP, SP>,
- Loki::SmartPtr<T, OP, CP, KP, SP>, bool>
- {
- bool operator()(const Loki::SmartPtr<T, OP, CP, KP, SP>& lhs,
- const Loki::SmartPtr<T, OP, CP, KP, SP>& rhs) const
- { return less<T*>()(GetImpl(lhs), GetImpl(rhs)); }
- };
- }
-
-
-
- #endif
-
SmartPtr.h 접기
-
static_check.h 보기
-
-
- #ifndef STATIC_CHECK_INC_
- #define STATIC_CHECK_INC_
-
- namespace Loki
- {
-
- template<int> struct CompileTimeError;
- template<> struct CompileTimeError<true> {};
- }
-
-
- #define STATIC_CHECK(expr, msg) \
- { Loki::CompileTimeError<((expr) != 0)> ERROR_##msg; (void)ERROR_##msg; }
-
-
-
- #endif
-
static_check.h 접기
-
Threads.h 보기
- #ifndef THREADS_H_
- #define THREADS_H_
-
-
-
- #ifndef DEFAULT_THREADING
- #define DEFAULT_THREADING ::Loki::SingleThreaded
- #endif
-
- namespace Loki
- {
-
- template <class Host>
- class SingleThreaded
- {
- public:
- struct Lock
- {
- Lock() {}
- explicit Lock(const SingleThreaded&) {}
- };
-
- typedef Host VolatileType;
-
- typedef int IntType;
-
- static IntType AtomicAdd(volatile IntType& lval, IntType val)
- { return lval += val; }
-
- static IntType AtomicSubtract(volatile IntType& lval, IntType val)
- { return lval -= val; }
-
- static IntType AtomicMultiply(volatile IntType& lval, IntType val)
- { return lval *= val; }
-
- static IntType AtomicDivide(volatile IntType& lval, IntType val)
- { return lval /= val; }
-
- static IntType AtomicIncrement(volatile IntType& lval)
- { return ++lval; }
-
- static IntType AtomicDecrement(volatile IntType& lval)
- { return --lval; }
-
- static void AtomicAssign(volatile IntType & lval, IntType val)
- { lval = val; }
-
- static void AtomicAssign(IntType & lval, volatile IntType & val)
- { lval = val; }
- };
-
- #ifdef _WINDOWS_
-
-
- template <class Host>
- class ObjectLevelLockable
- {
- mutable CRITICAL_SECTION mtx_;
-
- public:
- ObjectLevelLockable()
- {
- ::InitializeCriticalSection(&mtx_);
- }
-
- ~ObjectLevelLockable()
- {
- ::DeleteCriticalSection(&mtx_);
- }
-
- class Lock;
- friend class Lock;
-
- class Lock
- {
- ObjectLevelLockable const& host_;
-
- Lock(const Lock&);
- Lock& operator=(const Lock&);
- public:
-
- explicit Lock(const ObjectLevelLockable& host) : host_(host)
- {
- ::EnterCriticalSection(&host_.mtx_);
- }
-
- ~Lock()
- {
- ::LeaveCriticalSection(&host_.mtx_);
- }
- };
-
- typedef volatile Host VolatileType;
-
- typedef LONG IntType;
-
- static IntType AtomicIncrement(volatile IntType& lval)
- { return InterlockedIncrement(&const_cast<IntType&>(lval)); }
-
- static IntType AtomicDecrement(volatile IntType& lval)
- { return InterlockedDecrement(&const_cast<IntType&>(lval)); }
-
- static void AtomicAssign(volatile IntType& lval, IntType val)
- { InterlockedExchange(&const_cast<IntType&>(lval), val); }
-
- static void AtomicAssign(IntType& lval, volatile IntType& val)
- { InterlockedExchange(&lval, val); }
- };
-
- template <class Host>
- class ClassLevelLockable
- {
- struct Initializer
- {
- CRITICAL_SECTION mtx_;
-
- Initializer()
- {
- ::InitializeCriticalSection(&mtx_);
- }
- ~Initializer()
- {
- ::DeleteCriticalSection(&mtx_);
- }
- };
-
- static Initializer initializer_;
-
- public:
- class Lock;
- friend class Lock;
-
- class Lock
- {
- Lock(const Lock&);
- Lock& operator=(const Lock&);
- public:
- Lock()
- {
- ::EnterCriticalSection(&initializer_.mtx_);
- }
- explicit Lock(const ClassLevelLockable&)
- {
- ::EnterCriticalSection(&initializer_.mtx_);
- }
- ~Lock()
- {
- ::LeaveCriticalSection(&initializer_.mtx_);
- }
- };
-
- typedef volatile Host VolatileType;
-
- typedef LONG IntType;
-
- static IntType AtomicIncrement(volatile IntType& lval)
- { return InterlockedIncrement(&const_cast<IntType&>(lval)); }
-
- static IntType AtomicDecrement(volatile IntType& lval)
- { return InterlockedDecrement(&const_cast<IntType&>(lval)); }
-
- static void AtomicAssign(volatile IntType& lval, IntType val)
- { InterlockedExchange(&const_cast<IntType&>(lval), val); }
-
- static void AtomicAssign(IntType& lval, volatile IntType& val)
- { InterlockedExchange(&lval, val); }
- };
-
- template <class Host>
- typename ClassLevelLockable<Host>::Initializer
- ClassLevelLockable<Host>::initializer_;
-
- #endif
- }
-
-
- #endif
-
Threads.h 접기
-
Tuple.h 보기
-
Typelist.h 보기
-
-
- #ifndef TYPELIST_INC_
- #define TYPELIST_INC_
-
- #include
- #include
-
-
- #define TYPELIST_1(T1) ::Loki::Typelist<T1, ::Loki::NullType>
-
- #define TYPELIST_2(T1, T2) ::Loki::Typelist<T1, TYPELIST_1(T2) >
-
- #define TYPELIST_3(T1, T2, T3) ::Loki::Typelist<T1, TYPELIST_2(T2, T3) >
-
- #define TYPELIST_4(T1, T2, T3, T4) \
- ::Loki::Typelist<T1, TYPELIST_3(T2, T3, T4) >
-
- #define TYPELIST_5(T1, T2, T3, T4, T5) \
- ::Loki::Typelist<T1, TYPELIST_4(T2, T3, T4, T5) >
-
- #define TYPELIST_6(T1, T2, T3, T4, T5, T6) \
- ::Loki::Typelist<T1, TYPELIST_5(T2, T3, T4, T5, T6) >
-
- #define TYPELIST_7(T1, T2, T3, T4, T5, T6, T7) \
- ::Loki::Typelist<T1, TYPELIST_6(T2, T3, T4, T5, T6, T7) >
-
- #define TYPELIST_8(T1, T2, T3, T4, T5, T6, T7, T8) \
- ::Loki::Typelist<T1, TYPELIST_7(T2, T3, T4, T5, T6, T7, T8) >
-
- #define TYPELIST_9(T1, T2, T3, T4, T5, T6, T7, T8, T9) \
- ::Loki::Typelist<T1, TYPELIST_8(T2, T3, T4, T5, T6, T7, T8, T9) >
-
- #define TYPELIST_10(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) \
- ::Loki::Typelist<T1, TYPELIST_9(T2, T3, T4, T5, T6, T7, T8, T9, T10) >
-
- #define TYPELIST_11(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) \
- ::Loki::Typelist<T1, TYPELIST_10(T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) >
-
- #define TYPELIST_12(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) \
- ::Loki::Typelist<T1, TYPELIST_11(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12) >
-
- #define TYPELIST_13(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) \
- ::Loki::Typelist<T1, TYPELIST_12(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13) >
-
- #define TYPELIST_14(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14) \
- ::Loki::Typelist<T1, TYPELIST_13(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14) >
-
- #define TYPELIST_15(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15) \
- ::Loki::Typelist<T1, TYPELIST_14(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15) >
-
- #define TYPELIST_16(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16) \
- ::Loki::Typelist<T1, TYPELIST_15(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16) >
-
- #define TYPELIST_17(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17) \
- ::Loki::Typelist<T1, TYPELIST_16(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17) >
-
- #define TYPELIST_18(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18) \
- ::Loki::Typelist<T1, TYPELIST_17(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18) >
-
- #define TYPELIST_19(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19) \
- ::Loki::Typelist<T1, TYPELIST_18(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19) >
-
- #define TYPELIST_20(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) \
- ::Loki::Typelist<T1, TYPELIST_19(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) >
-
- #define TYPELIST_21(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) \
- ::Loki::Typelist<T1, TYPELIST_20(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) >
-
- #define TYPELIST_22(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) \
- ::Loki::Typelist<T1, TYPELIST_21(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) >
-
- #define TYPELIST_23(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23) \
- ::Loki::Typelist<T1, TYPELIST_22(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23) >
-
- #define TYPELIST_24(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24) \
- ::Loki::Typelist<T1, TYPELIST_23(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24) >
-
- #define TYPELIST_25(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25) \
- ::Loki::Typelist<T1, TYPELIST_24(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25) >
-
- #define TYPELIST_26(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26) \
- ::Loki::Typelist<T1, TYPELIST_25(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26) >
-
- #define TYPELIST_27(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27) \
- ::Loki::Typelist<T1, TYPELIST_26(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27) >
-
- #define TYPELIST_28(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28) \
- ::Loki::Typelist<T1, TYPELIST_27(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28) >
-
- #define TYPELIST_29(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29) \
- ::Loki::Typelist<T1, TYPELIST_28(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29) >
-
- #define TYPELIST_30(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30) \
- ::Loki::Typelist<T1, TYPELIST_29(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30) >
-
- #define TYPELIST_31(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31) \
- ::Loki::Typelist<T1, TYPELIST_30(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31) >
-
- #define TYPELIST_32(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32) \
- ::Loki::Typelist<T1, TYPELIST_31(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32) >
-
- #define TYPELIST_33(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33) \
- ::Loki::Typelist<T1, TYPELIST_32(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33) >
-
- #define TYPELIST_34(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33, T34) \
- ::Loki::Typelist<T1, TYPELIST_33(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33, T34) >
-
- #define TYPELIST_35(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35) \
- ::Loki::Typelist<T1, TYPELIST_34(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35) >
-
- #define TYPELIST_36(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36) \
- ::Loki::Typelist<T1, TYPELIST_35(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36) >
-
- #define TYPELIST_37(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37) \
- ::Loki::Typelist<T1, TYPELIST_36(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37) >
-
- #define TYPELIST_38(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38) \
- ::Loki::Typelist<T1, TYPELIST_37(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38) >
-
- #define TYPELIST_39(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39) \
- ::Loki::Typelist<T1, TYPELIST_38(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39) >
-
- #define TYPELIST_40(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40) \
- ::Loki::Typelist<T1, TYPELIST_39(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40) >
-
- #define TYPELIST_41(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41) \
- ::Loki::Typelist<T1, TYPELIST_40(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41) >
-
- #define TYPELIST_42(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42) \
- ::Loki::Typelist<T1, TYPELIST_41(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42) >
-
- #define TYPELIST_43(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43) \
- ::Loki::Typelist<T1, TYPELIST_42(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43) >
-
- #define TYPELIST_44(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44) \
- ::Loki::Typelist<T1, TYPELIST_43(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44) >
-
- #define TYPELIST_45(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
- T41, T42, T43, T44, T45) \
- ::Loki::Typelist<T1, TYPELIST_44(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
- T41, T42, T43, T44, T45) >
-
- #define TYPELIST_46(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
- T41, T42, T43, T44, T45, T46) \
- ::Loki::Typelist<T1, TYPELIST_45(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
- T41, T42, T43, T44, T45, T46) >
-
- #define TYPELIST_47(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
- T41, T42, T43, T44, T45, T46, T47) \
- ::Loki::Typelist<T1, TYPELIST_46(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
- T41, T42, T43, T44, T45, T46, T47) >
-
- #define TYPELIST_48(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
- T41, T42, T43, T44, T45, T46, T47, T48) \
- ::Loki::Typelist<T1, TYPELIST_47(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
- T41, T42, T43, T44, T45, T46, T47, T48) >
-
- #define TYPELIST_49(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
- T41, T42, T43, T44, T45, T46, T47, T48, T49) \
- ::Loki::Typelist<T1, TYPELIST_48(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
- T41, T42, T43, T44, T45, T46, T47, T48, T49) >
-
- #define TYPELIST_50(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
- T41, T42, T43, T44, T45, T46, T47, T48, T49, T50) \
- ::Loki::Typelist<T1, TYPELIST_49(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
- T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
- T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
- T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
- T41, T42, T43, T44, T45, T46, T47, T48, T49, T50) >
-
- namespace Loki
- {
-
- template <class T, class U>
- struct Typelist
- {
- typedef T Head;
- typedef U Tail;
- };
-
-
- namespace TL
- {
-
-
- template
- <
- typename T1 = NullType, typename T2 = NullType, typename T3 = NullType,
- typename T4 = NullType, typename T5 = NullType, typename T6 = NullType,
- typename T7 = NullType, typename T8 = NullType, typename T9 = NullType,
- typename T10 = NullType, typename T11 = NullType, typename T12 = NullType,
- typename T13 = NullType, typename T14 = NullType, typename T15 = NullType,
- typename T16 = NullType, typename T17 = NullType, typename T18 = NullType
- >
- struct MakeTypelist
- {
- private:
- typedef typename MakeTypelist
- <
- T2 , T3 , T4 ,
- T5 , T6 , T7 ,
- T8 , T9 , T10,
- T11, T12, T13,
- T14, T15, T16,
- T17, T18
- >
- ::Result TailResult;
-
- public:
- typedef Typelist<T1, TailResult> Result;
- };
-
- template<>
- struct MakeTypelist<>
- {
- typedef NullType Result;
- };
-
-
- template <class TList> struct Length;
- template <> struct Length<NullType>
- {
- enum { value = 0 };
- };
-
- template <class T, class U>
- struct Length< Typelist<T, U> >
- {
- enum { value = 1 + Length<U>::value };
- };
-
-
- template <class TList, unsigned int index> struct TypeAt;
-
- template <class Head, class Tail>
- struct TypeAt<Typelist<Head, Tail>, 0>
- {
- typedef Head Result;
- };
-
- template <class Head, class Tail, unsigned int i>
- struct TypeAt<Typelist<Head, Tail>, i>
- {
- typedef typename TypeAt<Tail, i - 1>::Result Result;
- };
-
-
- template <class TList, unsigned int index,
- typename DefaultType = NullType>
- struct TypeAtNonStrict
- {
- typedef DefaultType Result;
- };
-
- template <class Head, class Tail, typename DefaultType>
- struct TypeAtNonStrict<Typelist<Head, Tail>, 0, DefaultType>
- {
- typedef Head Result;
- };
-
- template <class Head, class Tail, unsigned int i, typename DefaultType>
- struct TypeAtNonStrict<Typelist<Head, Tail>, i, DefaultType>
- {
- typedef typename
- TypeAtNonStrict<Tail, i - 1, DefaultType>::Result Result;
- };
-
-
- template <class TList, class T> struct IndexOf;
-
- template <class T>
- struct IndexOf<NullType, T>
- {
- enum { value = -1 };
- };
-
- template <class T, class Tail>
- struct IndexOf<Typelist<T, Tail>, T>
- {
- enum { value = 0 };
- };
-
- template <class Head, class Tail, class T>
- struct IndexOf<Typelist<Head, Tail>, T>
- {
- private:
- enum { temp = IndexOf<Tail, T>::value };
- public:
- enum { value = (temp == -1 ? -1 : 1 + temp) };
- };
-
-
- template <class TList, class T> struct Append;
-
- template <> struct Append<NullType, NullType>
- {
- typedef NullType Result;
- };
-
- template <class T> struct Append<NullType, T>
- {
- typedef TYPELIST_1(T) Result;
- };
-
- template <class Head, class Tail>
- struct Append<NullType, Typelist<Head, Tail> >
- {
- typedef Typelist<Head, Tail> Result;
- };
-
- template <class Head, class Tail, class T>
- struct Append<Typelist<Head, Tail>, T>
- {
- typedef Typelist<Head,
- typename Append<Tail, T>::Result>
- Result;
- };
-
-
- template <class TList, class T> struct Erase;
-
- template <class T>
- struct Erase<NullType, T>
- {
- typedef NullType Result;
- };
-
- template <class T, class Tail>
- struct Erase<Typelist<T, Tail>, T>
- {
- typedef Tail Result;
- };
-
- template <class Head, class Tail, class T>
- struct Erase<Typelist<Head, Tail>, T>
- {
- typedef Typelist<Head,
- typename Erase<Tail, T>::Result>
- Result;
- };
-
-
- template <class TList, class T> struct EraseAll;
- template <class T>
- struct EraseAll<NullType, T>
- {
- typedef NullType Result;
- };
- template <class T, class Tail>
- struct EraseAll<Typelist<T, Tail>, T>
- {
-
- typedef typename EraseAll<Tail, T>::Result Result;
- };
- template <class Head, class Tail, class T>
- struct EraseAll<Typelist<Head, Tail>, T>
- {
-
- typedef Typelist<Head,
- typename EraseAll<Tail, T>::Result>
- Result;
- };
-
-
- template <class TList> struct NoDuplicates;
-
- template <> struct NoDuplicates<NullType>
- {
- typedef NullType Result;
- };
-
- template <class Head, class Tail>
- struct NoDuplicates< Typelist<Head, Tail> >
- {
- private:
- typedef typename NoDuplicates<Tail>::Result L1;
- typedef typename Erase<L1, Head>::Result L2;
- public:
- typedef Typelist<Head, L2> Result;
- };
-
-
- template <class TList, class T, class U> struct Replace;
-
- template <class T, class U>
- struct Replace<NullType, T, U>
- {
- typedef NullType Result;
- };
-
- template <class T, class Tail, class U>
- struct Replace<Typelist<T, Tail>, T, U>
- {
- typedef Typelist<U, Tail> Result;
- };
-
- template <class Head, class Tail, class T, class U>
- struct Replace<Typelist<Head, Tail>, T, U>
- {
- typedef Typelist<Head,
- typename Replace<Tail, T, U>::Result>
- Result;
- };
-
-
- template <class TList, class T, class U> struct ReplaceAll;
-
- template <class T, class U>
- struct ReplaceAll<NullType, T, U>
- {
- typedef NullType Result;
- };
-
- template <class T, class Tail, class U>
- struct ReplaceAll<Typelist<T, Tail>, T, U>
- {
- typedef Typelist<U, typename ReplaceAll<Tail, T, U>::Result> Result;
- };
-
- template <class Head, class Tail, class T, class U>
- struct ReplaceAll<Typelist<Head, Tail>, T, U>
- {
- typedef Typelist<Head,
- typename ReplaceAll<Tail, T, U>::Result>
- Result;
- };
-
-
- template <class TList> struct Reverse;
-
- template <>
- struct Reverse<NullType>
- {
- typedef NullType Result;
- };
-
- template <class Head, class Tail>
- struct Reverse< Typelist<Head, Tail> >
- {
- typedef typename Append<
- typename Reverse<Tail>::Result, Head>::Result Result;
- };
-
-
- template <class TList, class T> struct MostDerived;
-
- template <class T>
- struct MostDerived<NullType, T>
- {
- typedef T Result;
- };
-
- template <class Head, class Tail, class T>
- struct MostDerived<Typelist<Head, Tail>, T>
- {
- private:
- typedef typename MostDerived<Tail, T>::Result Candidate;
- public:
- typedef typename Select<
- SuperSubclass<Candidate,Head>::value,
- Head, Candidate>::Result Result;
- };
-
-
- template <class TList> struct DerivedToFront;
-
- template <>
- struct DerivedToFront<NullType>
- {
- typedef NullType Result;
- };
-
- template <class Head, class Tail>
- struct DerivedToFront< Typelist<Head, Tail> >
- {
- private:
- typedef typename MostDerived<Tail, Head>::Result
- TheMostDerived;
- typedef typename Replace<Tail,
- TheMostDerived, Head>::Result Temp;
- typedef typename DerivedToFront<Temp>::Result L;
- public:
- typedef Typelist<TheMostDerived, L> Result;
- };
-
- }
- }
-
-
- #endif
-
Typelist.h 접기
-
TypeManip.h 보기
-
-
- #ifndef TYPEMANIP_INC_
- #define TYPEMANIP_INC_
-
- namespace Loki
- {
-
- template <int v>
- struct Int2Type
- {
- enum { value = v };
- };
-
-
- template <typename T>
- struct Type2Type
- {
- typedef T OriginalType;
- };
-
-
- template <bool flag, typename T, typename U>
- struct Select
- {
- typedef T Result;
- };
- template <typename T, typename U>
- struct Select<false, T, U>
- {
- typedef U Result;
- };
-
-
- template <typename T, typename U>
- struct IsSameType
- {
- enum { value = false };
- };
-
- template <typename T>
- struct IsSameType<T,T>
- {
- enum { value = true };
- };
-
-
- namespace Private
- {
- template <class T, class U>
- struct ConversionHelper
- {
- typedef char Small;
- struct Big { char dummy[2]; };
- static Big Test(...);
- static Small Test(U);
- static T MakeT();
- };
- }
-
-
- template <class T, class U>
- struct Conversion
- {
- typedef Private::ConversionHelper<T, U> H;
- #ifndef __MWERKS__
- enum { exists = sizeof(typename H::Small) == sizeof((H::Test(H::MakeT()))) };
- #else
- enum { exists = false };
- #endif
- enum { exists2Way = exists && Conversion<U, T>::exists };
- enum { sameType = false };
- };
-
- template <class T>
- struct Conversion<T, T>
- {
- enum { exists = 1, exists2Way = 1, sameType = 1 };
- };
-
- template <class T>
- struct Conversion<void, T>
- {
- enum { exists = 0, exists2Way = 0, sameType = 0 };
- };
-
- template <class T>
- struct Conversion<T, void>
- {
- enum { exists = 0, exists2Way = 0, sameType = 0 };
- };
-
- template <>
- struct Conversion<void, void>
- {
- public:
- enum { exists = 1, exists2Way = 1, sameType = 1 };
- };
-
-
- template <class T, class U>
- struct SuperSubclass
- {
- enum { value = (::Loki::Conversion<const volatile U*, const volatile T*>::exists &&
- !::Loki::Conversion<const volatile T*, const volatile void*>::sameType) };
- };
-
-
- template<class T,class U>
- struct SuperSubclassStrict
- {
- enum { value = (::Loki::Conversion<const volatile U*, const volatile T*>::exists &&
- !::Loki::Conversion<const volatile T*, const volatile void*>::sameType &&
- !::Loki::Conversion<const volatile T*, const volatile U*>::sameType) };
- };
-
- }
-
-
- #define SUPERSUBCLASS(T, U) \
- ::Loki::SuperSubclass<T,U>::value
-
-
- #define SUPERSUBCLASS_STRICT(T, U) \
- ::Loki::SuperSubclassStrict<T,U>::value
-
-
- #endif
-
TypeManip.h 접기
-
TypeTraits.h 보기
- #ifndef TYPETRAITS_INC_
- #define TYPETRAITS_INC_
-
- #include
-
- namespace Loki
- {
-
- template <typename T>
- struct IsCustomUnsignedInt
- {
- enum { value = 0 };
- };
-
-
- template <typename T>
- struct IsCustomSignedInt
- {
- enum { value = 0 };
- };
-
-
- template <typename T>
- struct IsCustomFloat
- {
- enum { value = 0 };
- };
-
-
- namespace Private
- {
- typedef TYPELIST_4(unsigned char, unsigned short int,
- unsigned int, unsigned long int) StdUnsignedInts;
- typedef TYPELIST_4(signed char, short int,
- int, long int) StdSignedInts;
- typedef TYPELIST_3(bool, char, wchar_t) StdOtherInts;
- typedef TYPELIST_3(float, double, long double) StdFloats;
-
- template <class U> struct AddReference
- {
- typedef U & Result;
- };
-
- template <class U> struct AddReference<U &>
- {
- typedef U & Result;
- };
-
- template <> struct AddReference<void>
- {
- typedef NullType Result;
- };
- }
-
-
- template <typename T>
- class TypeTraits
- {
- private:
- template <class U> struct PointerTraits
- {
- enum { result = false };
- typedef NullType PointeeType;
- };
-
- template <class U> struct PointerTraits<U*>
- {
- enum { result = true };
- typedef U PointeeType;
- };
-
- template <class U> struct ReferenceTraits
- {
- enum { result = false };
- typedef U ReferredType;
- };
-
- template <class U> struct ReferenceTraits<U&>
- {
- enum { result = true };
- typedef U ReferredType;
- };
-
- template <class U> struct PToMTraits
- {
- enum { result = false };
- };
-
- template <class U, class V>
- struct PToMTraits<U V::*>
- {
- enum { result = true };
- };
-
- template <class U> struct UnConst
- {
- typedef U Result;
- enum { isConst = 0 };
- };
-
- template <class U> struct UnConst<const U>
- {
- typedef U Result;
- enum { isConst = 1 };
- };
-
- template <class U> struct UnVolatile
- {
- typedef U Result;
- enum { isVolatile = 0 };
- };
-
- template <class U> struct UnVolatile<volatile U>
- {
- typedef U Result;
- enum { isVolatile = 1 };
- };
-
- public:
- enum { isPointer = PointerTraits<T>::result };
- typedef typename PointerTraits<T>::PointeeType PointeeType;
-
- enum { isReference = ReferenceTraits<T>::result };
- typedef typename ReferenceTraits<T>::ReferredType ReferredType;
-
- enum { isMemberPointer = PToMTraits<T>::result };
-
- enum { isStdUnsignedInt =
- TL::IndexOf<Private::StdUnsignedInts, T>::value >= 0 };
- enum { isStdSignedInt =
- TL::IndexOf<Private::StdSignedInts, T>::value >= 0 };
- enum { isStdIntegral = isStdUnsignedInt || isStdSignedInt ||
- TL::IndexOf<Private::StdOtherInts, T>::value >= 0 };
- enum { isStdFloat = TL::IndexOf<Private::StdFloats, T>::value >= 0 };
- enum { isStdArith = isStdIntegral || isStdFloat };
- enum { isStdFundamental = isStdArith || isStdFloat ||
- Conversion<T, void>::sameType };
-
- enum { isUnsignedInt = isStdUnsignedInt || IsCustomUnsignedInt<T>::value };
- enum { isSignedInt = isStdSignedInt || IsCustomSignedInt<T>::value };
- enum { isIntegral = isStdIntegral || isUnsignedInt || isSignedInt };
- enum { isFloat = isStdFloat || IsCustomFloat<T>::value };
- enum { isArith = isIntegral || isFloat };
- enum { isFundamental = isStdFundamental || isArith || isFloat };
-
- typedef typename Select<isStdArith || isPointer || isMemberPointer,
- T, typename Private::AddReference<T>::Result>::Result ParameterType;
-
- enum { isConst = UnConst<T>::isConst };
- typedef typename UnConst<T>::Result NonConstType;
- enum { isVolatile = UnVolatile<T>::isVolatile };
- typedef typename UnVolatile<T>::Result NonVolatileType;
- typedef typename UnVolatile<typename UnConst<T>::Result>::Result
- UnqualifiedType;
- };
- }
-
-
- #endif
-
TypeTraits.h 접기
-
Visitor.h 보기
-
-
- #ifndef VISITOR_INC_
- #define VISITOR_INC_
-
- #include
- #include
-
- namespace Loki
- {
-
-
- class BaseVisitor
- {
- public:
- virtual ~BaseVisitor() {}
- };
-
-
- template <class T, typename R = void>
- class Visitor
- {
- public:
- typedef R ReturnType;
- virtual ReturnType Visit(T&) = 0;
- };
-
-
- template <class Head, class Tail, typename R>
- class Visitor<Typelist<Head, Tail>, R>
- : public Visitor<Head, R>, public Visitor<Tail, R>
- {
- public:
- typedef R ReturnType;
-
-
- };
-
- template <class Head, typename R>
- class Visitor<Typelist<Head, NullType>, R> : public Visitor<Head, R>
- {
- public:
- typedef R ReturnType;
- using Visitor<Head, R>::Visit;
- };
-
-
- template <class TList, typename R = void> class BaseVisitorImpl;
-
- template <class Head, class Tail, typename R>
- class BaseVisitorImpl<Typelist<Head, Tail>, R>
- : public Visitor<Head, R>
- , public BaseVisitorImpl<Tail, R>
- {
- public:
-
-
- virtual R Visit(Head&)
- { return R(); }
- };
-
- template <class Head, typename R>
- class BaseVisitorImpl<Typelist<Head, NullType>, R>
- : public Visitor<Head, R>
- {
- public:
- virtual R Visit(Head&)
- { return R(); }
- };
-
-
- template <typename R, typename Visited>
- struct DefaultCatchAll
- {
- static R OnUnknownVisitor(Visited&, BaseVisitor&)
- { return R(); }
- };
-
-
- template
- <
- typename R = void,
- template <typename, class> class CatchAll = DefaultCatchAll
- >
- class BaseVisitable
- {
- public:
- typedef R ReturnType;
- virtual ~BaseVisitable() {}
- virtual ReturnType Accept(BaseVisitor&) = 0;
-
- protected:
- template <class T>
- static ReturnType AcceptImpl(T& visited, BaseVisitor& guest)
- {
-
- if (Visitor<T,R>* p = dynamic_cast<Visitor<T,R>*>(&guest))
- {
- return p->Visit(visited);
- }
- return CatchAll<R, T>::OnUnknownVisitor(visited, guest);
- }
- };
-
-
- #define DEFINE_VISITABLE() \
- virtual ReturnType Accept(::Loki::BaseVisitor& guest) \
- { return AcceptImpl(*this, guest); }
-
-
- template <typename R, class TList>
- class CyclicVisitor : public Visitor<TList, R>
- {
- public:
- typedef R ReturnType;
-
-
- template <class Visited>
- ReturnType GenericVisit(Visited& host)
- {
- Visitor<Visited, ReturnType>& subObj = *this;
- return subObj.Visit(host);
- }
- };
-
-
- #define DEFINE_CYCLIC_VISITABLE(SomeVisitor) \
- virtual SomeVisitor::ReturnType Accept(SomeVisitor& guest) \
- { return guest.GenericVisit(*this); }
-
- }
-
-
- #endif
-
-
Visitor.h 접기