Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / interprocess / test / check_equal_containers.hpp
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 #include <functional>
16 #include <iostream>
17 #include <algorithm>
18 #include <boost/container/detail/pair.hpp>
19
20 namespace boost{
21 namespace interprocess{
22 namespace test{
23
24 template< class T1, class T2>
25 bool CheckEqual( const T1 &t1, const T2 &t2
26                , typename boost::container::container_detail::enable_if_c
27                   <!boost::container::container_detail::is_pair<T1>::value &&
28                    !boost::container::container_detail::is_pair<T2>::value
29                   >::type* = 0)
30 {  return t1 == t2;  }
31
32 template< class Pair1, class Pair2>
33 bool CheckEqual( const Pair1 &pair1, const Pair2 &pair2
34                , typename boost::container::container_detail::enable_if_c
35                   <boost::container::container_detail::is_pair<Pair1>::value &&
36                    boost::container::container_detail::is_pair<Pair2>::value
37                   >::type* = 0)
38 {
39    return CheckEqual(pair1.first, pair2.first) && CheckEqual(pair1.second, pair2.second);
40 }
41
42
43 //Function to check if both containers are equal
44 template<class MyShmCont
45         ,class MyStdCont>
46 bool CheckEqualContainers(MyShmCont *shmcont, MyStdCont *stdcont)
47 {
48    if(shmcont->size() != stdcont->size())
49       return false;
50
51    typename MyShmCont::iterator itshm(shmcont->begin()), itshmend(shmcont->end());
52    typename MyStdCont::iterator itstd(stdcont->begin());
53    typename MyStdCont::size_type dist = (typename MyStdCont::size_type)std::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>
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