• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2006-2012. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/interprocess for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10 
11 #ifndef BOOST_INTERPROCESS_TEST_CHECK_EQUAL_CONTAINERS_HPP
12 #define BOOST_INTERPROCESS_TEST_CHECK_EQUAL_CONTAINERS_HPP
13 
14 #include <boost/interprocess/detail/config_begin.hpp>
15 // container/detail
16 #include <boost/container/detail/iterator.hpp>
17 #include <boost/container/detail/pair.hpp>
18 
19 namespace boost{
20 namespace interprocess{
21 namespace test{
22 
23 template< class T1, class T2>
CheckEqual(const T1 & t1,const T2 & t2,typename boost::container::dtl::enable_if_c<!boost::container::dtl::is_pair<T1>::value &&!boost::container::dtl::is_pair<T2>::value>::type * =0)24 bool CheckEqual( const T1 &t1, const T2 &t2
25                , typename boost::container::dtl::enable_if_c
26                   <!boost::container::dtl::is_pair<T1>::value &&
27                    !boost::container::dtl::is_pair<T2>::value
28                   >::type* = 0)
29 {  return t1 == t2;  }
30 
31 template< class Pair1, class Pair2>
CheckEqual(const Pair1 & pair1,const Pair2 & pair2,typename boost::container::dtl::enable_if_c<boost::container::dtl::is_pair<Pair1>::value && boost::container::dtl::is_pair<Pair2>::value>::type * =0)32 bool CheckEqual( const Pair1 &pair1, const Pair2 &pair2
33                , typename boost::container::dtl::enable_if_c
34                   <boost::container::dtl::is_pair<Pair1>::value &&
35                    boost::container::dtl::is_pair<Pair2>::value
36                   >::type* = 0)
37 {
38    return CheckEqual(pair1.first, pair2.first) && CheckEqual(pair1.second, pair2.second);
39 }
40 
41 
42 //Function to check if both containers are equal
43 template<class MyShmCont
44         ,class MyStdCont>
CheckEqualContainers(MyShmCont * shmcont,MyStdCont * stdcont)45 bool CheckEqualContainers(MyShmCont *shmcont, MyStdCont *stdcont)
46 {
47    if(shmcont->size() != stdcont->size())
48       return false;
49 
50    typename MyShmCont::iterator itshm(shmcont->begin()), itshmend(shmcont->end());
51    typename MyStdCont::iterator itstd(stdcont->begin());
52    typename MyStdCont::size_type dist =
53       typename MyStdCont::size_type(boost::container::iterator_distance(itshm, itshmend));
54    if(dist != shmcont->size()){
55       return false;
56    }
57    std::size_t i = 0;
58    for(; itshm != itshmend; ++itshm, ++itstd, ++i){
59       if(!CheckEqual(*itstd, *itshm))
60          return false;
61    }
62    return true;
63 }
64 
65 template<class MyShmCont
66         ,class MyStdCont>
CheckEqualPairContainers(MyShmCont * shmcont,MyStdCont * stdcont)67 bool CheckEqualPairContainers(MyShmCont *shmcont, MyStdCont *stdcont)
68 {
69    if(shmcont->size() != stdcont->size())
70       return false;
71 
72    typedef typename MyShmCont::key_type      key_type;
73    typedef typename MyShmCont::mapped_type   mapped_type;
74 
75    typename MyShmCont::iterator itshm(shmcont->begin()), itshmend(shmcont->end());
76    typename MyStdCont::iterator itstd(stdcont->begin());
77    for(; itshm != itshmend; ++itshm, ++itstd){
78       if(itshm->first != key_type(itstd->first))
79          return false;
80 
81       if(itshm->second != mapped_type(itstd->second))
82          return false;
83    }
84    return true;
85 }
86 }  //namespace test{
87 }  //namespace interprocess{
88 }  //namespace boost{
89 
90 #include <boost/interprocess/detail/config_end.hpp>
91 
92 #endif //#ifndef BOOST_INTERPROCESS_TEST_CHECK_EQUAL_CONTAINERS_HPP
93