• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #867

15 Jan 2023 08:00PM UTC coverage: 86.487% (+0.5%) from 85.951%
#867

push

StellarBot
Merge #6135

6135: Fixing warnings reported by MSVC analysis r=hkaiser a=hkaiser

- adding MSVC specific #pragma's to suppress the benign warnings


Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>

120 of 120 new or added lines in 33 files covered. (100.0%)

174599 of 201880 relevant lines covered (86.49%)

1945607.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

17.33
/libs/core/serialization/src/detail/polymorphic_id_factory.cpp
1
//  Copyright (c) 2015 Anton Bikineev
2
//  Copyright (c) 2014 Thomas Heller
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0.
6
//  See accompanying file LICENSE_1_0.txt or copy at
7
//  http://www.boost.org/LICENSE_1_0.txt)
8

9
#include <hpx/config.hpp>
10
#include <hpx/assert.hpp>
11
#include <hpx/serialization/detail/polymorphic_id_factory.hpp>
12

13
#include <cstddef>
14
#include <cstdint>
15
#include <map>
16
#include <string>
17
#include <utility>
18
#include <vector>
19

20
namespace hpx::serialization::detail {
21

22
    ///////////////////////////////////////////////////////////////////////////
23
    id_registry& id_registry::instance()
878✔
24
    {
25
        util::static_<id_registry> inst;
878✔
26
        return inst.get();
878✔
27
    }
28

29
    void id_registry::cache_id(std::uint32_t id, ctor_t ctor)
×
30
    {
31
        if (id >= cache.size())    //-V104
×
32
        {
33
            cache.resize(std::size_t(id) + 1, nullptr);
×
34
            cache[id] = ctor;    //-V108
×
35
        }
×
36
        else if (cache[id] == nullptr)    //-V108
×
37
        {
38
            cache[id] = ctor;    //-V108
×
39
        }
×
40
    }
×
41

42
    void id_registry::register_factory_function(
×
43
        std::string const& type_name, ctor_t ctor)
44
    {
45
        HPX_ASSERT(ctor != nullptr);
×
46

47
        typename_to_ctor.emplace(type_name, ctor);
×
48

49
        // populate cache
50
        typename_to_id_t::const_iterator it = typename_to_id.find(type_name);
×
51
        if (it != typename_to_id.end())
×
52
            cache_id(it->second, ctor);
×
53
    }
×
54

55
    void id_registry::register_typename(
×
56
        std::string const& type_name, std::uint32_t id)
57
    {
58
        HPX_ASSERT(id != invalid_id);
×
59

60
        std::pair<typename_to_id_t::iterator, bool> p =
61
            typename_to_id.emplace(type_name, id);
×
62

63
        if (!p.second)
×
64
        {
65
            HPX_THROW_EXCEPTION(hpx::error::invalid_status,
×
66
                "polymorphic_id_factory::register_typename",
67
                "failed to insert {} into typename_to_id_t registry",
68
                type_name);
69
            return;
70
        }
71

72
        // populate cache
73
        typename_to_ctor_t::const_iterator it =
74
            typename_to_ctor.find(type_name);
×
75
        if (it != typename_to_ctor.end())
×
76
            cache_id(id, it->second);
×
77

78
        if (id > max_id)
×
79
            max_id = id;
×
80
    }
×
81

82
    // This makes sure that the registries are consistent.
83
    void id_registry::fill_missing_typenames()
594✔
84
    {
85
        // Register all type-names and assign missing ids
86
        for (std::string const& str : get_unassigned_typenames())
594✔
87
            register_typename(str, ++max_id);
×
88

89
        // Go over all registered mappings from type-names to ids and
90
        // fill in missing id to constructor mappings.
91
        for (auto const& d : typename_to_id)
594✔
92
        {
93
            typename_to_ctor_t::const_iterator it =
94
                typename_to_ctor.find(d.first);
×
95
            if (it != typename_to_ctor.end())
×
96
                cache_id(d.second, it->second);
×
97
        }
98

99
        // Go over all registered mappings from type-names to
100
        // constructors and fill in missing id to constructor mappings.
101
        for (auto const& d : typename_to_ctor)
594✔
102
        {
103
            typename_to_id_t::const_iterator it = typename_to_id.find(d.first);
×
104
            HPX_ASSERT(it != typename_to_id.end());
×
105
            cache_id(it->second, d.second);    //-V783
×
106
        }
107
    }
594✔
108

109
    std::uint32_t id_registry::try_get_id(std::string const& type_name) const
×
110
    {
111
        typename_to_id_t::const_iterator it = typename_to_id.find(type_name);
×
112
        if (it == typename_to_id.end())
×
113
            return invalid_id;
×
114

115
        return it->second;
×
116
    }
×
117

118
    std::vector<std::string> id_registry::get_unassigned_typenames() const
878✔
119
    {
120
        std::vector<std::string> result;
878✔
121

122
        // O(Nlog(M)) ?
123
        for (auto const& v : typename_to_ctor)
878✔
124
        {
125
            if (!typename_to_id.count(v.first))
×
126
            {
127
                result.push_back(v.first);
×
128
            }
×
129
        }
130

131
        return result;
878✔
132
    }
878✔
133

134
    ///////////////////////////////////////////////////////////////////////////
135
    polymorphic_id_factory& polymorphic_id_factory::instance()
×
136
    {
137
        hpx::util::static_<polymorphic_id_factory> factory;
×
138
        return factory.get();
×
139
    }
140

141
    std::uint32_t polymorphic_id_factory::get_id(std::string const& type_name)
×
142
    {
143
        std::uint32_t id = id_registry::instance().try_get_id(type_name);
×
144

145
        if (id == id_registry::invalid_id)
×
146
        {
147
            HPX_THROW_EXCEPTION(hpx::error::serialization_error,
×
148
                "polymorphic_id_factory::get_id", "Unknown typename: {}",
149
                type_name);
150
        }
151

152
        return id;
×
153
    }
×
154

155
    std::string polymorphic_id_factory::collect_registered_typenames()
×
156
    {
157
#if defined(HPX_DEBUG)
158
        std::string msg("known constructors:\n");
×
159

160
        for (auto const& desc : id_registry::instance().typename_to_ctor)
×
161
        {
162
            msg += desc.first + "\n";
×
163
        }
164

165
        msg += "\nknown typenames:\n";
×
166
        for (auto const& desc : id_registry::instance().typename_to_id)
×
167
        {
168
            msg += desc.first + " (";
×
169
            msg += std::to_string(desc.second) + ")\n";
×
170
        }
171

172
        return msg;
×
173
#else
174
        return std::string();
175
#endif
176
    }
×
177
}    // namespace hpx::serialization::detail
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc