////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Vicente J. Botet Escriba 2008. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/sync for documentation. // ////////////////////////////////////////////////////////////////////////////// #ifndef __BOOST_SYNC_LOCKABLE_TRAITS__HPP #define __BOOST_SYNC_LOCKABLE_TRAITS__HPP #include "boost/type_traits.hpp" namespace boost { namespace sync { /** * lock_traits_base is helper class that servs as a base class of lockables. */ //[lock_traits_base template< typename Scope, typename Cathegory, typename Reentrancy, typename TimedInterface, typename Base > struct lock_traits_base : Base { // TODO add constraints on typenames typedef Scope scope; typedef Cathegory cathegory; typedef Reentrancy reentrancy; typedef TimedInterface timed_interface; }; //] //[lock_traits_base_void template< typename Scope, typename Cathegory, typename Reentrancy, typename TimedInterface > struct lock_traits_base { typedef Scope scope; typedef Cathegory cathegory; typedef Reentrancy reentrancy; typedef TimedInterface timed_interface; }; //] /** * a scope_tag forms a hierarchy * mono_threaded_tag <- multi_threaded_tag <- multi_process_tag */ //[scope_tag_hierarchy struct mono_threaded_tag {}; struct multi_threaded_tag : mono_threaded_tag {}; struct multi_process_tag : multi_threaded_tag {}; //] /** * A lockable implementer must either * inherit from the helper lock_traits_base or * have a nested type scope or * specialize the scope_tag template class */ //[scope_tag template struct scope_tag { typedef typename Lockable::scope type; }; //] /** * Inherits: If Lockable has a scope_tag that inherits from * then mono_threaded_tag then inherits from true_type, * otherwise inherits from false_type. */ template struct is_mono_threaded : boost::is_base_and_derived< mono_threaded_tag, typename scope_tag::type > {}; /** * Inherits: If Lockable has a scope_tag that inherits from * then multi_threaded_tag then inherits from true_type, * otherwise inherits from false_type. */ template struct is_multi_threaded : boost::is_base_and_derived< multi_threaded_tag, typename scope_tag::type > {}; /** * Inherits: If Lockable has a scope_tag that inherits from * then multi_process_tag then inherits from true_type, * otherwise inherits from false_type. */ template struct is_multi_process : boost::is_base_and_derived< multi_process_tag, typename scope_tag::type > {}; /** * a lifetime_tag forms a hierarchy * process_lifetime_tag <- kernel_lifetime_tag <- filesystem_lifetime_tag */ struct process_lifetime_tag {}; struct kernel_lifetime_tag : process_lifetime_tag {}; struct filesystem_lifetime_tag : kernel_lifetime_tag {}; /** * A lockable implementer must either * inherit from the helper lock_traits_base or * have a nested type lifetime or * specialize the lifetime_tag template class */ template struct lifetime_tag { typedef typename Lockable::lifetime type; }; /** * a naming_tags forms a hierarchy * anonymous_tag <- named_tag */ struct anonymous_tag {}; struct named_tag : anonymous_tag {}; /** * A lockable implementer must either * inherit from the helper lock_traits_base or * have a nested type naming or * specialize the naming_tag template class */ template struct naming_tag { typedef typename Lockable::naming type; }; /** * a category_tag forms a hierarchy * exclusive_lock_tag <- sharable_lock_tag <- upgradable_lock_tag */ struct exclusive_lock_tag {}; struct sharable_lock_tag : exclusive_lock_tag {}; struct upgradable_lock_tag : sharable_lock_tag {}; /** * A lockable implementer must either * inherit from the helper lock_traits_base or * have a nested type cathegory or * specialize the category_tag template class */ template struct category_tag { typedef typename Lockable::category type; }; /** * Inherits: If Lockable has a category_tag that inherits from * then exclusive_lock_tag then inherits from true_type, * otherwise inherits from false_type. */ template struct is_exclusive_lock : boost::is_base_and_derived< exclusive_lock_tag, typename category_tag::type > {}; /** * Inherits: If Lockable has a category_tag that inherits from * then sharable_lock_tag then inherits from true_type, * otherwise inherits from false_type. */ template struct is_sharable_lock : boost::is_base_and_derived< sharable_lock_tag, typename category_tag::type > {}; /** * Inherits: If Lockable has a category_tag that inherits from * then upgradable_lock_tag then inherits from true_type, * otherwise inherits from false_type. */ template struct is_upgradable_lock : boost::is_base_and_derived< upgradable_lock_tag, typename category_tag::type > {}; /** * a reentrancy_tag formas a hierarchy * non_recursive_tag <- recursive_tag */ struct non_recursive_tag {}; struct recursive_tag : non_recursive_tag {}; /** * A lockable implementer must either * inherit from the helper lock_traits_base or * have a nested type reentrancy or * specialize the reentrancy_tag template class */ template struct reentrancy_tag { typedef typename Lockable::reentrancy type; }; /** * Inherits: If Lockable has a reentrancy_tag that inherits from * then recursive_tag then inherits from true_type, * otherwise inherits from false_type. */ template struct is_recursive_lock : boost::is_base_and_derived< recursive_tag, typename reentrancy_tag::type > {}; /** * a timed_interface_tag forms a hierarchy * hasnt_timed_interface_tag <- has_timed_interface_tag */ struct hasnt_timed_interface_tag {}; struct has_timed_interface_tag : hasnt_timed_interface_tag {}; /** * A lockable implementer must either * inherit from the helper lock_traits_base or * have a nested type timed_interface or * specialize the timed_interface_tag template class */ template struct timed_interface_tag { typedef typename Lockable::timed_interface type; }; /** * Inherits: If Lockable has a timed_interface_tag that inherits from * then has_timed_interface_tag then inherits from true_type, * otherwise inherits from false_type. */ template struct has_timed_interface : boost::is_base_and_derived< has_timed_interface_tag, typename timed_interface_tag::type > {}; template struct lockable_type { typedef typename Locker::lockable_type type; }; } } #endif