LCOV - code coverage report
Current view: top level - cereal/types/concepts - pair_associative_container.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 15 15 100.0 %
Date: 2017-02-12 13:57:59 Functions: 184 184 100.0 %

          Line data    Source code
       1             : /*! \file pair_associative_container.hpp
       2             :     \brief Support for the PairAssociativeContainer refinement of the
       3             :     AssociativeContainer concept.
       4             :     \ingroup TypeConcepts */
       5             : /*
       6             :   Copyright (c) 2014, Randolph Voorhies, Shane Grant
       7             :   All rights reserved.
       8             : 
       9             :   Redistribution and use in source and binary forms, with or without
      10             :   modification, are permitted provided that the following conditions are met:
      11             :       * Redistributions of source code must retain the above copyright
      12             :         notice, this list of conditions and the following disclaimer.
      13             :       * Redistributions in binary form must reproduce the above copyright
      14             :         notice, this list of conditions and the following disclaimer in the
      15             :         documentation and/or other materials provided with the distribution.
      16             :       * Neither the name of cereal nor the
      17             :         names of its contributors may be used to endorse or promote products
      18             :         derived from this software without specific prior written permission.
      19             : 
      20             :   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
      21             :   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
      22             :   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
      23             :   DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY
      24             :   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
      25             :   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
      26             :   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
      27             :   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      28             :   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
      29             :   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      30             : */
      31             : #ifndef CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_
      32             : #define CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_
      33             : 
      34             : #include "cereal/cereal.hpp"
      35             : 
      36             : namespace cereal
      37             : {
      38             :   //! Saving for std-like pair associative containers
      39             :   template <class Archive, template <typename...> class Map, typename... Args, typename = typename Map<Args...>::mapped_type> inline
      40        9200 :   void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, Map<Args...> const & map )
      41             :   {
      42        9200 :     ar( make_size_tag( static_cast<size_type>(map.size()) ) );
      43             : 
      44     1279554 :     for( const auto & i : map )
      45     1270354 :       ar( make_map_item(i.first, i.second) );
      46        9200 :   }
      47             : 
      48             :   //! Loading for std-like pair associative containers
      49             :   template <class Archive, template <typename...> class Map, typename... Args, typename = typename Map<Args...>::mapped_type> inline
      50        9200 :   void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, Map<Args...> & map )
      51             :   {
      52             :     size_type size;
      53        9200 :     ar( make_size_tag( size ) );
      54             : 
      55        9200 :     map.clear();
      56             : 
      57        9200 :     auto hint = map.begin();
      58     1279554 :     for( size_t i = 0; i < size; ++i )
      59             :     {
      60      480000 :       typename Map<Args...>::key_type key;
      61     1114354 :       typename Map<Args...>::mapped_type value;
      62             : 
      63     1270354 :       ar( make_map_item(key, value) );
      64             :       #ifdef CEREAL_OLDER_GCC
      65             :       hint = map.insert( hint, std::make_pair(std::move(key), std::move(value)) );
      66             :       #else // NOT CEREAL_OLDER_GCC
      67     1270354 :       hint = map.emplace_hint( hint, std::move( key ), std::move( value ) );
      68             :       #endif // NOT CEREAL_OLDER_GCC
      69             :     }
      70        9200 :   }
      71             : } // namespace cereal
      72             : 
      73             : #endif // CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_

Generated by: LCOV version 1.11