From 2447da3c08616bdb3bcdbf781b06b101c3353017 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 20 Jan 2021 12:43:59 -0600 Subject: [PATCH] refactor: Rename 'map_utils.h' -> 'MapUtils.h/cc' Also refactor the relevant namespace 'bts::utils' methods to be static methods in the newly created class 'MapUtils.' This is part of the effort to favor static class methods over namespaced functions. --- src/lib/utils/{map_utils.h => MapUtils.cc} | 14 ++++++++------ src/lib/utils/MapUtils.h | 16 ++++++++++++++++ .../back_testing/matcher/iceberg_helper.cpp | 4 ++-- 3 files changed, 26 insertions(+), 8 deletions(-) rename src/lib/utils/{map_utils.h => MapUtils.cc} (54%) create mode 100644 src/lib/utils/MapUtils.h diff --git a/src/lib/utils/map_utils.h b/src/lib/utils/MapUtils.cc similarity index 54% rename from src/lib/utils/map_utils.h rename to src/lib/utils/MapUtils.cc index 296216e96..4b9cb35bb 100644 --- a/src/lib/utils/map_utils.h +++ b/src/lib/utils/MapUtils.cc @@ -1,9 +1,10 @@ -#include -#include +#include "MapUtils.h" + +namespace bts { -namespace bts::utils { template -inline const V *find_value(K key, const std::unordered_map &umap) { +inline const V *MapUtils::find_value( + const std::unordered_map &umap, K key) { auto it = umap.find(key); if (it == umap.end()) return nullptr; @@ -11,10 +12,11 @@ inline const V *find_value(K key, const std::unordered_map &umap) { } template -inline V *find_value(K key, std::unordered_map &umap) { +inline V *MapUtils::find_value(std::unordered_map &umap, K key) { auto it = umap.find(key); if (it == umap.end()) return nullptr; return &(it->second); } -} // namespace bts::utils \ No newline at end of file + +} // namespace bts diff --git a/src/lib/utils/MapUtils.h b/src/lib/utils/MapUtils.h new file mode 100644 index 000000000..8ef5cfbae --- /dev/null +++ b/src/lib/utils/MapUtils.h @@ -0,0 +1,16 @@ +#pragma once +#include + +namespace bts { + +struct MapUtils { + template + static const V *find_value(const std::unordered_map &, K); + + template + static V *find_value(std::unordered_map &, K); +}; + +} // namespace bts + +#include "MapUtils.cc" diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/iceberg_helper.cpp b/src/server/sparkd/cmds/spartan/back_testing/matcher/iceberg_helper.cpp index dc98fe14e..57a7cc292 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/iceberg_helper.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/iceberg_helper.cpp @@ -1,6 +1,6 @@ #include "iceberg_helper.h" #include "lib/orderman/orderman_utils/Formatter.h" -#include "lib/utils/map_utils.h" +#include "lib/utils/MapUtils.h" #include "domain/SecuritySnapshot.h" namespace bts::spartan::mdp3::iceberg_helper { @@ -15,7 +15,7 @@ void add_iceberg_annotation( const std::unordered_map &icebergs, size_t event_id, bool set_exact_state) { - const auto *ib = find_value(o.key, icebergs); + const auto *ib = MapUtils::find_value(icebergs, o.key); if (ib != nullptr) add_iceberg_annotation(o, change_type, *ib, event_id, set_exact_state); }