Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:17

0001 /*-----------------------------------------------------------------------------+    
0002 Copyright (c) 2010-2010: Joachim Faulhaber
0003 +------------------------------------------------------------------------------+
0004    Distributed under the Boost Software License, Version 1.0.
0005       (See accompanying file LICENCE.txt or copy at
0006            http://www.boost.org/LICENSE_1_0.txt)
0007 +-----------------------------------------------------------------------------*/
0008 #ifndef BOOST_ICL_CONCEPT_ELEMENT_SET_HPP_JOFA_100921
0009 #define BOOST_ICL_CONCEPT_ELEMENT_SET_HPP_JOFA_100921
0010 
0011 #include <boost/icl/type_traits/is_combinable.hpp>
0012 #include <boost/icl/concept/set_value.hpp>
0013 #include <boost/icl/detail/std_set.hpp>
0014 #include <boost/icl/detail/set_algo.hpp>
0015 
0016 
0017 namespace boost{ namespace icl
0018 {
0019 
0020 //==============================================================================
0021 //= Addition<ElementSet>
0022 //==============================================================================
0023 /** \c add inserts \c operand into the map if it's key does 
0024     not exist in the map.    
0025     If \c operands's key value exists in the map, it's data
0026     value is added to the data value already found in the map. */
0027 template <class Type>
0028 typename enable_if<is_element_set<Type>, Type>::type&
0029 add(Type& object, const typename Type::value_type& operand)
0030 {
0031     object.insert(operand); 
0032     return object;
0033 }
0034 
0035 /** \c add add \c operand into the map using \c prior as a hint to
0036     insert \c operand after the position \c prior is pointing to. */
0037 template <class Type>
0038 typename enable_if<is_element_set<Type>, typename Type::iterator>::type
0039 add(Type& object, typename Type::iterator prior, 
0040     const typename Type::value_type& operand) 
0041 { 
0042     return object.insert(prior, operand); 
0043 }
0044 
0045 //==============================================================================
0046 //= Subtraction
0047 //==============================================================================
0048 /** If the \c operand's key value is in the map, it's data value is
0049     subtraced from the data value stored in the map. */
0050 template<class Type>
0051 typename enable_if<is_element_set<Type>, Type>::type&
0052 subtract(Type& object, const typename Type::value_type& operand)
0053 {
0054     object.erase(operand);
0055     return object;
0056 }
0057 
0058 
0059 //==============================================================================
0060 //= Intersection
0061 //==============================================================================
0062 template<class Type>
0063 inline typename enable_if<is_element_set<Type>, bool>::type
0064 intersects(const Type& object, const typename Type::key_type& operand)
0065 {
0066     return !(object.find(operand) == object.end()); 
0067 }
0068 
0069 template<class Type>
0070 inline typename enable_if<is_element_set<Type>, bool>::type
0071 intersects(const Type& object, const Type& operand)
0072 {
0073     if(iterative_size(object) < iterative_size(operand))
0074         return Set::intersects(object, operand);
0075     else
0076         return Set::intersects(operand, object);
0077 }
0078 
0079 //==============================================================================
0080 //= Symmetric difference
0081 //==============================================================================
0082 template<class Type>
0083 inline typename enable_if<is_element_set<Type>, Type>::type&
0084 flip(Type& object, const typename Type::value_type& operand)
0085 {
0086     typedef typename Type::iterator iterator;
0087     std::pair<iterator,bool> insertion = object.insert(operand);
0088     if(!insertion.second)
0089         object.erase(insertion.first);
0090 
0091     return object;
0092 }
0093 
0094 template<class Type>
0095 inline typename enable_if<is_element_set<Type>, Type>::type&
0096 operator ^= (Type& object, const typename Type::element_type& operand)
0097 {
0098     return icl::flip(object, operand); 
0099 }
0100 
0101 /** Symmetric subtract map \c x2 and \c *this.
0102     So \c *this becomes the symmetric difference of \c *this and \c x2 */
0103 template<class Type>
0104 inline typename enable_if<is_element_set<Type>, Type>::type&
0105 operator ^= (Type& object, const Type& operand)
0106 {
0107     typedef typename Type::const_iterator const_iterator;
0108     const_iterator it_ = operand.begin();
0109     while(it_ != operand.end())
0110         icl::flip(object, *it_++);
0111 
0112     return object;
0113 }
0114 
0115 //==============================================================================
0116 //= Streaming<ElementSet>
0117 //==============================================================================
0118 template<class CharType, class CharTraits, class Type>
0119 inline typename enable_if<is_element_set<Type>, std::basic_ostream<CharType, CharTraits> >::type&
0120 operator << (std::basic_ostream<CharType, CharTraits>& stream, const Type& object)
0121 {
0122     stream << "{";
0123     ICL_const_FORALL(typename Type, it, object)
0124         stream << (*it) << " ";
0125 
0126     return stream << "}";
0127 }
0128 
0129 
0130 }} // namespace boost icl
0131 
0132 #endif
0133 
0134