check_equal_containers.hpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifndef BOOST_INTERPROCESS_TEST_CHECK_EQUAL_CONTAINERS_HPP
  11. #define BOOST_INTERPROCESS_TEST_CHECK_EQUAL_CONTAINERS_HPP
  12. #include <boost/interprocess/detail/config_begin.hpp>
  13. // container/detail
  14. #include <boost/container/detail/iterator.hpp>
  15. #include <boost/container/detail/pair.hpp>
  16. namespace boost{
  17. namespace interprocess{
  18. namespace test{
  19. template< class T1, class T2>
  20. bool CheckEqual( const T1 &t1, const T2 &t2
  21. , typename boost::container::dtl::enable_if_c
  22. <!boost::container::dtl::is_pair<T1>::value &&
  23. !boost::container::dtl::is_pair<T2>::value
  24. >::type* = 0)
  25. { return t1 == t2; }
  26. template< class Pair1, class Pair2>
  27. bool CheckEqual( const Pair1 &pair1, const Pair2 &pair2
  28. , typename boost::container::dtl::enable_if_c
  29. <boost::container::dtl::is_pair<Pair1>::value &&
  30. boost::container::dtl::is_pair<Pair2>::value
  31. >::type* = 0)
  32. {
  33. return CheckEqual(pair1.first, pair2.first) && CheckEqual(pair1.second, pair2.second);
  34. }
  35. //Function to check if both containers are equal
  36. template<class MyShmCont
  37. ,class MyStdCont>
  38. bool CheckEqualContainers(MyShmCont *shmcont, MyStdCont *stdcont)
  39. {
  40. if(shmcont->size() != stdcont->size())
  41. return false;
  42. typename MyShmCont::iterator itshm(shmcont->begin()), itshmend(shmcont->end());
  43. typename MyStdCont::iterator itstd(stdcont->begin());
  44. typename MyStdCont::size_type dist =
  45. typename MyStdCont::size_type(boost::container::iterator_distance(itshm, itshmend));
  46. if(dist != shmcont->size()){
  47. return false;
  48. }
  49. std::size_t i = 0;
  50. for(; itshm != itshmend; ++itshm, ++itstd, ++i){
  51. if(!CheckEqual(*itstd, *itshm))
  52. return false;
  53. }
  54. return true;
  55. }
  56. template<class MyShmCont
  57. ,class MyStdCont>
  58. bool CheckEqualPairContainers(MyShmCont *shmcont, MyStdCont *stdcont)
  59. {
  60. if(shmcont->size() != stdcont->size())
  61. return false;
  62. typedef typename MyShmCont::key_type key_type;
  63. typedef typename MyShmCont::mapped_type mapped_type;
  64. typename MyShmCont::iterator itshm(shmcont->begin()), itshmend(shmcont->end());
  65. typename MyStdCont::iterator itstd(stdcont->begin());
  66. for(; itshm != itshmend; ++itshm, ++itstd){
  67. if(itshm->first != key_type(itstd->first))
  68. return false;
  69. if(itshm->second != mapped_type(itstd->second))
  70. return false;
  71. }
  72. return true;
  73. }
  74. } //namespace test{
  75. } //namespace interprocess{
  76. } //namespace boost{
  77. #include <boost/interprocess/detail/config_end.hpp>
  78. #endif //#ifndef BOOST_INTERPROCESS_TEST_CHECK_EQUAL_CONTAINERS_HPP