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.
This commit is contained in:
John Colvin committed 2021-02-01 22:56:21 -06:00
1 parent 8df420c37c
commit 2447da3c08
3 files changed
+26 -8

No files matched your search

@@ -1,9 +1,10 @@
#include <map>
#include <unordered_map>
#include "MapUtils.h"
namespace bts {
namespace bts::utils {
template <class K, class V>
inline const V *find_value(K key, const std::unordered_map<K, V> &umap) {
inline const V *MapUtils::find_value(
const std::unordered_map<K, V> &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<K, V> &umap) {
}
template <class K, class V>
inline V *find_value(K key, std::unordered_map<K, V> &umap) {
inline V *MapUtils::find_value(std::unordered_map<K, V> &umap, K key) {
auto it = umap.find(key);
if (it == umap.end())
return nullptr;
return &(it->second);
}
} // namespace bts::utils
} // namespace bts
+16
View File
@@ -0,0 +1,16 @@
#pragma once
#include <unordered_map>
namespace bts {
struct MapUtils {
template <class K, class V>
static const V *find_value(const std::unordered_map<K, V> &, K);
template <class K, class V>
static V *find_value(std::unordered_map<K, V> &, K);
};
} // namespace bts
#include "MapUtils.cc"
@@ -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<OrderKey, IcebergInput> &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);
}