Web Wispers 1.2.2 C++ Unit Test Coverage
Current view: top level - ssrc/wispers/utility - unordered_map.h (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.2 C++ Unit Tests Lines: 12 12 100.0 %
Date: 2012-04-09 Functions: 1 1 100.0 %
Branches: 3 4 75.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright 2006-2009 Savarese Software Research Corporation
       3                 :            :  *
       4                 :            :  * Licensed under the Apache License, Version 2.0 (the "License");
       5                 :            :  * you may not use this file except in compliance with the License.
       6                 :            :  * You may obtain a copy of the License at
       7                 :            :  *
       8                 :            :  *     https://www.savarese.com/software/ApacheLicense-2.0
       9                 :            :  *
      10                 :            :  * Unless required by applicable law or agreed to in writing, software
      11                 :            :  * distributed under the License is distributed on an "AS IS" BASIS,
      12                 :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13                 :            :  * See the License for the specific language governing permissions and
      14                 :            :  * limitations under the License.
      15                 :            :  */
      16                 :            : 
      17                 :            : /**
      18                 :            :  * @file
      19                 :            :  * This header includes <unordered_map> with serialization support.
      20                 :            :  */
      21                 :            : 
      22                 :            : #ifndef __SSRC_WSPR_UTILITY_UNORDERED_MAP_H
      23                 :            : #define __SSRC_WSPR_UTILITY_UNORDERED_MAP_H
      24                 :            : 
      25                 :            : // This is a horrible kluge to work around boost serialization not
      26                 :            : // supporting <unordered_map>.  As soon as boost serialization supports
      27                 :            : // unordered_map, get rid of all of the hacks.
      28                 :            : 
      29                 :            : #include <unordered_map>
      30                 :            : #include <boost/serialization/serialization.hpp>
      31                 :            : 
      32                 :            : #define hash_map unordered_map
      33                 :            : #define hash_multimap unordered_multimap
      34                 :            : 
      35                 :            : #ifdef BOOST_HASH_MAP_HEADER
      36                 :            : #undef BOOST_HASH_MAP_HEADER
      37                 :            : #endif
      38                 :            : #ifdef BOOST_STD_EXTENSION_NAMESPACE
      39                 :            : #undef BOOST_STD_EXTENSION_NAMESPACE 
      40                 :            : #endif
      41                 :            : #ifdef BOOST_SERIALIZATION_HASH_COLLECTIONS_LOAD_IMP_HPP
      42                 :            : #undef BOOST_SERIALIZATION_HASH_COLLECTIONS_LOAD_IMP_HPP
      43                 :            : #endif
      44                 :            : 
      45                 :            : #define BOOST_HASH_MAP_HEADER <unordered_map>
      46                 :            : #define BOOST_STD_EXTENSION_NAMESPACE std
      47                 :            : #define BOOST_SERIALIZATION_HASH_COLLECTIONS_LOAD_IMP_HPP
      48                 :            : #include <boost/serialization/nvp.hpp>
      49                 :            : #include <boost/serialization/collections_load_imp.hpp>
      50                 :            : 
      51                 :            : namespace boost{
      52                 :            :   namespace serialization {
      53                 :            :     namespace stl {
      54                 :            :       template<class Archive, class Container, class InputFunction>
      55                 :          1 :       inline void load_hash_collection(Archive & ar, Container &s)
      56                 :            :       {
      57                 :          1 :         s.clear();
      58                 :            :         // retrieve number of elements
      59                 :          1 :         collection_size_type count;
      60                 :          1 :         collection_size_type bucket_count;
      61                 :          1 :         boost::serialization::item_version_type item_version(0);
      62                 :          1 :         ar >> BOOST_SERIALIZATION_NVP(count);
      63         [ +  - ]:          1 :         if(3 < ar.get_library_version()){
      64                 :          1 :           ar >> BOOST_SERIALIZATION_NVP(bucket_count)
      65                 :            :              >> BOOST_SERIALIZATION_NVP(item_version);
      66                 :            :         }
      67                 :            : 
      68                 :          1 :         s.rehash(bucket_count);
      69                 :            : 
      70                 :            :         InputFunction ifunc;
      71         [ +  + ]:          4 :         while(count-- > 0){
      72                 :          2 :           ifunc(ar, s, item_version);
      73                 :            :         }
      74                 :          1 :       }
      75                 :            :     }
      76                 :            :   }
      77                 :            : }
      78                 :            : 
      79                 :            : #include <boost/serialization/hash_map.hpp>
      80                 :            : #undef hash_map
      81                 :            : #undef hash_multimap
      82                 :            : 
      83                 :            : #endif