diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-01-20 13:29:21 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-01-20 17:04:56 +0100 |
| commit | e6ea3bd0d617a91645d96e89459f988bd67b4117 (patch) | |
| tree | fe7fa25de9f95c66b1da8e2730fdfcb253f6cd31 /windows/winnet/src | |
| parent | c0833b0589424bf21e14afec6b57ab742886a763 (diff) | |
| download | mullvadvpn-e6ea3bd0d617a91645d96e89459f988bd67b4117.tar.xz mullvadvpn-e6ea3bd0d617a91645d96e89459f988bd67b4117.zip | |
Refactor ValueMapper
Diffstat (limited to 'windows/winnet/src')
| -rw-r--r-- | windows/winnet/src/winnet/winnet.cpp | 25 |
1 files changed, 3 insertions, 22 deletions
diff --git a/windows/winnet/src/winnet/winnet.cpp b/windows/winnet/src/winnet/winnet.cpp index 3c8f133d57..55bfca5b39 100644 --- a/windows/winnet/src/winnet/winnet.cpp +++ b/windows/winnet/src/winnet/winnet.cpp @@ -7,6 +7,7 @@ #include <libshared/logging/unwind.h>
#include <libshared/network/interfaceutils.h>
#include <libcommon/error.h>
+#include <libcommon/valuemapper.h>
#include <libcommon/network.h>
#include <cstdint>
#include <stdexcept>
@@ -522,26 +523,6 @@ WinNet_DeleteRoute( }
}
-//
-// TODO: Move to libcommon.
-//
-struct ValueMapper
-{
- template<typename T, typename U, std::size_t S>
- static U map(T t, const std::pair<T, U> (&dictionary)[S])
- {
- for (const auto &entry : dictionary)
- {
- if (t == entry.first)
- {
- return entry.second;
- }
- }
-
- throw std::runtime_error("Could not map between values");
- }
-};
-
extern "C"
WINNET_LINKAGE
bool
@@ -577,7 +558,7 @@ WinNet_RegisterDefaultRouteChangedCallback( { from_t::Removed, WINNET_DEFAULT_ROUTE_CHANGED_EVENT_TYPE_REMOVED }
};
- const auto translatedEventType = ValueMapper::map<>(eventType, eventTypeMap);
+ const auto translatedEventType = common::ValueMapper::Map<>(eventType, eventTypeMap);
//
// Translate the family type.
@@ -589,7 +570,7 @@ WinNet_RegisterDefaultRouteChangedCallback( { static_cast<ADDRESS_FAMILY>(AF_INET6), WINNET_IP_FAMILY_V6 }
};
- const auto translatedFamily = ValueMapper::map<>(family, familyMap);
+ const auto translatedFamily = common::ValueMapper::Map<>(family, familyMap);
//
// Determine which LUID to forward.
|
