Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:39

0001 // Boost.Bimap
0002 //
0003 // Copyright (c) 2006-2007 Matias Capeletto
0004 //
0005 // Distributed under the Boost Software License, Version 1.0.
0006 // (See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 /// \file relation/mutant_relation.hpp
0010 /// \brief Defines the mutant_relation class
0011 
0012 #ifndef BOOST_BIMAP_RELATION_MUTANT_RELATION_HPP
0013 #define BOOST_BIMAP_RELATION_MUTANT_RELATION_HPP
0014 
0015 #if defined(_MSC_VER)
0016 #pragma once
0017 #endif
0018 
0019 #include <boost/config.hpp>
0020 
0021 #include <boost/mpl/vector.hpp>
0022 #include <boost/operators.hpp>
0023 #include <boost/call_traits.hpp>
0024 
0025 #ifndef BOOST_BIMAP_DISABLE_SERIALIZATION
0026   #include <boost/core/serialization.hpp>
0027 #endif // BOOST_BIMAP_DISABLE_SERIALIZATION
0028 
0029 #include <boost/functional/hash/hash.hpp>
0030 
0031 #include <boost/mpl/aux_/na.hpp>
0032 
0033 // Boost.Bimap
0034 #include <boost/bimap/tags/tagged.hpp>
0035 #include <boost/bimap/tags/support/default_tagged.hpp>
0036 #include <boost/bimap/tags/support/tag_of.hpp>
0037 #include <boost/bimap/tags/support/value_type_of.hpp>
0038 
0039 #include <boost/bimap/relation/member_at.hpp>
0040 #include <boost/bimap/relation/detail/mutant.hpp>
0041 #include <boost/bimap/relation/structured_pair.hpp>
0042 #include <boost/bimap/relation/symmetrical_base.hpp>
0043 #include <boost/bimap/relation/support/get.hpp>
0044 
0045 namespace boost {
0046 namespace bimaps {
0047 namespace relation {
0048 
0049 namespace detail {
0050 
0051 // This class is included so structured_pair and mutant_relation share
0052 // exactly the same class layout
0053 
0054 template< class LeftType, class RightType, bool force_mutable >
0055 class relation_storage :
0056     public symmetrical_base<LeftType,RightType,force_mutable>
0057 {
0058     typedef symmetrical_base<LeftType,RightType,force_mutable> base_;
0059 
0060     typedef relation_storage storage_;
0061 
0062     public:
0063 
0064     typedef relation_storage<LeftType,RightType,false> non_mutable_storage;
0065 
0066     typedef ::boost::mpl::vector2
0067     <
0068         relation_storage< LeftType, RightType, true  >,
0069         relation_storage< LeftType, RightType, false >
0070 
0071     > mutant_views;
0072 
0073     //@{
0074         /// data
0075         BOOST_DEDUCED_TYPENAME base_::left_value_type  left;
0076         BOOST_DEDUCED_TYPENAME base_::right_value_type right;
0077     //@}
0078 
0079     relation_storage() {}
0080 
0081     relation_storage(BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0082                          BOOST_DEDUCED_TYPENAME base_::left_value_type
0083                      >::param_type l,
0084                      BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0085                         BOOST_DEDUCED_TYPENAME base_::right_value_type
0086                      >::param_type r)
0087 
0088         : left(l), right(r) {}
0089 
0090           BOOST_DEDUCED_TYPENAME base_:: left_value_type &  get_left()      { return left;  }
0091     const BOOST_DEDUCED_TYPENAME base_:: left_value_type &  get_left()const { return left;  }
0092           BOOST_DEDUCED_TYPENAME base_::right_value_type & get_right()      { return right; }
0093     const BOOST_DEDUCED_TYPENAME base_::right_value_type & get_right()const { return right; }
0094 };
0095 
0096 
0097 
0098 template< class TA, class TB, class Info, bool force_mutable >
0099 class relation_info_hook : public
0100  ::boost::bimaps::relation::detail::relation_storage<TA,TB,force_mutable>
0101 {
0102     typedef ::boost::bimaps::relation::detail::
0103                 relation_storage<TA,TB,force_mutable> base_;
0104 
0105     typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::tags::support::
0106         default_tagged<Info,member_at::info>::type tagged_info_type;
0107 
0108     public:
0109     typedef BOOST_DEDUCED_TYPENAME tagged_info_type::value_type info_type;
0110     typedef BOOST_DEDUCED_TYPENAME tagged_info_type::tag        info_tag;
0111 
0112     info_type info;
0113 
0114     protected:
0115 
0116     relation_info_hook() {}
0117 
0118     relation_info_hook( BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0119                            BOOST_DEDUCED_TYPENAME base_::left_value_type
0120                         >::param_type l,
0121                         BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0122                             BOOST_DEDUCED_TYPENAME base_::right_value_type
0123                         >::param_type r,
0124                         BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0125                             info_type
0126                         >::param_type i = info_type() )
0127 
0128         : base_(l,r), info(i) {}
0129 
0130     template< class Relation >
0131     relation_info_hook( const Relation & rel ) :
0132         base_(rel.left,rel.right),
0133         info(rel.info) {}
0134 
0135     template< class Relation >
0136     void change_to( const Relation & rel )
0137     {
0138         base_::left  = rel.left ;
0139         base_::right = rel.right;
0140         info         = rel.info ;
0141     }
0142 
0143     #ifndef BOOST_BIMAP_DISABLE_SERIALIZATION
0144     template< class Archive >
0145     void serialize(Archive & ar, const unsigned int)
0146     {
0147         ar & ::boost::serialization::make_nvp("left" , base_::left );
0148         ar & ::boost::serialization::make_nvp("right", base_::right);
0149         ar & ::boost::serialization::make_nvp("info" , info        );
0150     }
0151     #endif // BOOST_BIMAP_DISABLE_SERIALIZATION
0152 };
0153 
0154 template< class TA, class TB, bool force_mutable>
0155 class relation_info_hook<TA,TB,::boost::mpl::na,force_mutable> :
0156     public ::boost::bimaps::relation::detail::relation_storage<TA,TB,force_mutable>
0157 {
0158     typedef ::boost::bimaps::relation::detail::
0159                 relation_storage<TA,TB,force_mutable> base_;
0160 
0161     public:
0162     typedef ::boost::mpl::na info_type;
0163     typedef member_at::info info_tag;
0164 
0165     protected:
0166 
0167     relation_info_hook() {}
0168 
0169     relation_info_hook( BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0170                            BOOST_DEDUCED_TYPENAME base_::left_value_type
0171                         >::param_type l,
0172                         BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0173                             BOOST_DEDUCED_TYPENAME base_::right_value_type
0174                         >::param_type r)
0175 
0176         : base_(l,r) {}
0177 
0178     template< class Relation >
0179     relation_info_hook( const Relation & rel ) :
0180         base_(rel.left,rel.right) {}
0181 
0182     template< class Relation >
0183     void change_to( const Relation & rel )
0184     {
0185         base_::left  = rel.left ;
0186         base_::right = rel.right;
0187     }
0188 
0189     #ifndef BOOST_BIMAP_DISABLE_SERIALIZATION
0190     template< class Archive >
0191     void serialize(Archive & ar, const unsigned int)
0192     {
0193         ar & ::boost::serialization::make_nvp("left" , base_::left );
0194         ar & ::boost::serialization::make_nvp("right", base_::right);
0195     }
0196     #endif // BOOST_BIMAP_DISABLE_SERIALIZATION
0197 };
0198 
0199 
0200 } // namespace detail
0201 
0202 /// \brief Abstraction of a related pair of values, that extends the std::pair class.
0203 /**
0204 The mutant_relation is a mutant class. A mutant class can mutate
0205 with zero overhead in other classes that are called views.
0206 Each view has to be StorageCompatible with the base class
0207 of the mutant. Note that all the views have the following
0208 storage structure:
0209 
0210 \verbatim
0211                         __________
0212                        |          |
0213                        |    TA    |
0214                        |__________|
0215                        |          |
0216                        |    TB    |
0217                        |__________|
0218 
0219 \endverbatim
0220 
0221 See also select_relation, standard_relation.
0222 \ingroup relation_group
0223                                                            **/
0224 
0225 
0226 template< class TA, class TB, class Info = ::boost::mpl::na, bool force_mutable = false >
0227 class mutant_relation : public
0228     ::boost::bimaps::relation::detail::
0229         relation_info_hook<TA,TB,Info,force_mutable>
0230 {
0231     typedef ::boost::bimaps::relation::detail::
0232         relation_info_hook<TA,TB,Info,force_mutable> base_;
0233 
0234     public:
0235 
0236     // We have to know the type of the base where the types are
0237     // defined because Boost.MultiIndex requires it.
0238 
0239     typedef ::boost::bimaps::relation::detail::
0240                 relation_storage<TA,TB,force_mutable> storage_base;
0241 
0242     /// Above view, non mutable view of the relation
0243 
0244     typedef mutant_relation<TA,TB,Info,false> above_view;
0245 
0246     //@{
0247         /// A signature compatible std::pair that is a view of the relation.
0248 
0249         typedef structured_pair< TA, TB, Info, normal_layout >  left_pair;
0250         typedef structured_pair< TB, TA, Info, mirror_layout > right_pair;
0251     //@}
0252 
0253     typedef ::boost::mpl::vector4
0254     <
0255          left_pair,
0256         right_pair,
0257 
0258         mutant_relation< TA, TB, Info, true  >,
0259         mutant_relation< TA, TB, Info, false >
0260 
0261     > mutant_views;
0262 
0263     mutant_relation() {}
0264 
0265     mutant_relation(BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0266                         BOOST_DEDUCED_TYPENAME base_:: left_value_type
0267                     >::param_type l,
0268                     BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0269                         BOOST_DEDUCED_TYPENAME base_::right_value_type
0270                     >::param_type r) :
0271         base_(l,r) {}
0272 
0273     mutant_relation(BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0274                         BOOST_DEDUCED_TYPENAME base_:: left_value_type
0275                     >::param_type l,
0276                     BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0277                         BOOST_DEDUCED_TYPENAME base_::right_value_type
0278                     >::param_type r,
0279                     BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0280                         BOOST_DEDUCED_TYPENAME base_::info_type
0281                     >::param_type i) :
0282         base_(l,r,i) {}
0283 
0284     mutant_relation(const mutant_relation<TA,TB,Info,false> & rel) :
0285         base_(rel) {}
0286 
0287     mutant_relation(const mutant_relation<TA,TB,Info,true> & rel) :
0288         base_(rel) {}
0289 
0290     // Operators
0291 
0292     template< bool FM >
0293     mutant_relation& operator=(const mutant_relation<TA,TB,Info,FM> & rel)
0294     {
0295         base_::change_to(rel);
0296         return *this;
0297     }
0298 
0299     // The following functions are redundant if you only consider this class.
0300     // They are included to make easier the construction of the get and the
0301     // pair_by metafunction. Remember that not all compiler supports the mutant
0302     // idiom.
0303 
0304     left_pair & get_left_pair()
0305     {
0306         return ::boost::bimaps::relation::detail::mutate<left_pair>(*this);
0307     }
0308 
0309     const left_pair & get_left_pair() const
0310     {
0311         return ::boost::bimaps::relation::detail::mutate<left_pair>(*this);
0312     }
0313 
0314     right_pair & get_right_pair()
0315     {
0316         return ::boost::bimaps::relation::detail::mutate<right_pair>(*this);
0317     }
0318 
0319     const right_pair & get_right_pair() const
0320     {
0321         return ::boost::bimaps::relation::detail::mutate<right_pair>(*this);
0322     }
0323 
0324     above_view & get_view()
0325     {
0326         return ::boost::bimaps::relation::detail::mutate<above_view>(*this);
0327     }
0328 
0329     const above_view & get_view() const
0330     {
0331         return ::boost::bimaps::relation::detail::mutate<above_view>(*this);
0332     }
0333 
0334     template< class Tag >
0335     const BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
0336         result_of::get<Tag,const mutant_relation>::type
0337     get() const
0338     {
0339         return ::boost::bimaps::relation::support::get<Tag>(*this);
0340     }
0341 
0342     template< class Tag >
0343     BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
0344         result_of::get<Tag,mutant_relation>::type
0345     get()
0346     {
0347         return ::boost::bimaps::relation::support::get<Tag>(*this);
0348     }
0349     
0350     #ifndef BOOST_BIMAP_DISABLE_SERIALIZATION
0351 
0352     private:
0353     friend class ::boost::serialization::access;
0354 
0355     template<class Archive>
0356     void serialize(Archive & ar, const unsigned int version)
0357     {
0358         base_::serialize(ar,version);
0359     }
0360 
0361     #endif // BOOST_BIMAP_DISABLE_SERIALIZATION
0362 };
0363 
0364 // hash value
0365 
0366 template< class FirstType, class SecondType, bool FM >
0367 std::size_t hash_value(const detail::relation_storage<FirstType,SecondType,FM> & r)
0368 {
0369     std::size_t seed = 0;
0370     ::boost::hash_combine(seed, r. left );
0371     ::boost::hash_combine(seed, r.right );
0372 
0373     return seed;
0374 }
0375 
0376 // mutant_relation - mutant_relation
0377 
0378 template< class FirstType, class SecondType, bool FM1, bool FM2 >
0379 bool operator==(const detail::relation_storage<FirstType,SecondType,FM1> & a,
0380                 const detail::relation_storage<FirstType,SecondType,FM2> & b)
0381 {
0382     return ( ( a.left  == b.left  ) &&
0383              ( a.right == b.right ) );
0384 }
0385 
0386 template< class FirstType, class SecondType, bool FM1, bool FM2 >
0387 bool operator!=(const detail::relation_storage<FirstType,SecondType,FM1> & a,
0388                 const detail::relation_storage<FirstType,SecondType,FM2> & b)
0389 {
0390     return ! ( a == b );
0391 }
0392 
0393 template< class FirstType, class SecondType, bool FM1, bool FM2 >
0394 bool operator<(const detail::relation_storage<FirstType,SecondType,FM1> & a,
0395                const detail::relation_storage<FirstType,SecondType,FM2> & b)
0396 {
0397     return (  ( a.left  <  b.left  ) ||
0398              (( a.left == b.left ) && ( a.right < b.right )));
0399 }
0400 
0401 template< class FirstType, class SecondType, bool FM1, bool FM2 >
0402 bool operator<=(const detail::relation_storage<FirstType,SecondType,FM1> & a,
0403                 const detail::relation_storage<FirstType,SecondType,FM2> & b)
0404 {
0405     return (  ( a.left  <  b.left  ) ||
0406              (( a.left == b.left ) && ( a.right <= b.right )));
0407 }
0408 
0409 template< class FirstType, class SecondType, bool FM1, bool FM2 >
0410 bool operator>(const detail::relation_storage<FirstType,SecondType,FM1> & a,
0411                const detail::relation_storage<FirstType,SecondType,FM2> & b)
0412 {
0413     return ( ( a.left  >  b.left  ) ||
0414              (( a.left == b.left ) && ( a.right > b.right )));
0415 }
0416 
0417 template< class FirstType, class SecondType, bool FM1, bool FM2 >
0418 bool operator>=(const detail::relation_storage<FirstType,SecondType,FM1> & a,
0419                 const detail::relation_storage<FirstType,SecondType,FM2> & b)
0420 {
0421     return ( ( a.left  >  b.left  ) ||
0422              (( a.left == b.left ) && ( a.right >= b.right )));
0423 }
0424 
0425 namespace detail {
0426 
0427 template< class TA, class TB, class Info, bool force_mutable>
0428 mutant_relation<TA,TB,Info,force_mutable> 
0429     copy_with_left_replaced(mutant_relation<TA,TB,Info,force_mutable> const& rel,
0430         BOOST_DEDUCED_TYPENAME ::boost::call_traits< BOOST_DEDUCED_TYPENAME 
0431             mutant_relation<TA,TB,Info,force_mutable>::left_value_type>
0432                 ::param_type l)
0433 {
0434     return mutant_relation<TA,TB,Info,force_mutable>(l,rel.right,rel.info);
0435 }
0436     
0437 template< class TA, class TB, bool force_mutable>
0438 mutant_relation<TA,TB,::boost::mpl::na,force_mutable>
0439     copy_with_left_replaced(mutant_relation<TA,TB,::boost::mpl::na,force_mutable> const& rel,
0440         BOOST_DEDUCED_TYPENAME ::boost::call_traits< BOOST_DEDUCED_TYPENAME 
0441             mutant_relation<TA,TB,::boost::mpl::na,force_mutable>::left_value_type>
0442                 ::param_type l)
0443 {
0444     return mutant_relation<TA,TB,::boost::mpl::na,force_mutable>(l,rel.right);  
0445 }
0446     
0447 template< class TA, class TB, class Info, bool force_mutable>
0448 mutant_relation<TA,TB,Info,force_mutable> 
0449     copy_with_right_replaced(mutant_relation<TA,TB,Info,force_mutable> const& rel,
0450         BOOST_DEDUCED_TYPENAME ::boost::call_traits< BOOST_DEDUCED_TYPENAME 
0451             mutant_relation<TA,TB,Info,force_mutable>::right_value_type>
0452                 ::param_type r)
0453 {
0454     return mutant_relation<TA,TB,Info,force_mutable>(rel.left,r,rel.info);
0455 }
0456     
0457 template< class TA, class TB, bool force_mutable>
0458 mutant_relation<TA,TB,::boost::mpl::na,force_mutable>
0459     copy_with_right_replaced(mutant_relation<TA,TB,::boost::mpl::na,force_mutable> const& rel,
0460         BOOST_DEDUCED_TYPENAME ::boost::call_traits< BOOST_DEDUCED_TYPENAME 
0461             mutant_relation<TA,TB,::boost::mpl::na,force_mutable>::right_value_type>
0462                 ::param_type r)
0463 {
0464     return mutant_relation<TA,TB,::boost::mpl::na,force_mutable>(rel.left,r);  
0465 }
0466 
0467 } // namespace detail
0468 
0469 } // namespace relation
0470 } // namespace bimaps
0471 } // namespace boost
0472 
0473 
0474 #endif // BOOST_BIMAP_RELATION_MUTANT_RELATION_HPP
0475 
0476 
0477