forked from organicmaps/organicmaps
[base] Removed the Must* methods from BidirectionalMap.
This commit is contained in:
parent
a5ce995882
commit
cc88076de7
2 changed files with 8 additions and 52 deletions
|
@ -12,38 +12,15 @@ UNIT_TEST(BidirectionalMap_Smoke)
|
|||
{
|
||||
BidirectionalMap<int, string> m;
|
||||
m.Add(1, "a");
|
||||
TEST_EQUAL(m.MustGetValue(1), "a", ());
|
||||
TEST_EQUAL(m.MustGetKey("a"), 1, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(BidirectionalMap_Exceptions)
|
||||
{
|
||||
// Tests that the exceptions are thrown as expected.
|
||||
// Note that it is discouraged to catch them when using Must* methods.
|
||||
BidirectionalMap<int, string> m;
|
||||
{
|
||||
bool caught = false;
|
||||
try
|
||||
{
|
||||
UNUSED_VALUE(m.MustGetValue(0));
|
||||
}
|
||||
catch (BidirectionalMap<int, string>::NoValueForKeyException const & e)
|
||||
{
|
||||
caught = true;
|
||||
}
|
||||
TEST(caught, ());
|
||||
}
|
||||
|
||||
{
|
||||
bool caught = false;
|
||||
try
|
||||
{
|
||||
UNUSED_VALUE(m.MustGetKey(""));
|
||||
}
|
||||
catch (BidirectionalMap<int, string>::NoKeyForValueException const & e)
|
||||
{
|
||||
caught = true;
|
||||
}
|
||||
TEST(caught, ());
|
||||
string value;
|
||||
TEST(m.GetValue(1, value), ());
|
||||
TEST_EQUAL(value, "a", ());
|
||||
}
|
||||
{
|
||||
int key;
|
||||
TEST(m.GetKey("a", key), ());
|
||||
TEST_EQUAL(key, 1, ());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include "base/exception.hpp"
|
||||
#include "base/logging.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
|
@ -12,10 +11,6 @@ template <typename K, typename V>
|
|||
class BidirectionalMap
|
||||
{
|
||||
public:
|
||||
DECLARE_EXCEPTION(Exception, RootException);
|
||||
DECLARE_EXCEPTION(NoKeyForValueException, Exception);
|
||||
DECLARE_EXCEPTION(NoValueForKeyException, Exception);
|
||||
|
||||
BidirectionalMap() = default;
|
||||
|
||||
size_t Size() const { return m_kToV.size(); }
|
||||
|
@ -67,22 +62,6 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
V MustGetValue(K const & key) const
|
||||
{
|
||||
V result;
|
||||
if (!GetValue(key, result))
|
||||
MYTHROW(NoValueForKeyException, (key));
|
||||
return result;
|
||||
}
|
||||
|
||||
K MustGetKey(V const & value) const
|
||||
{
|
||||
K result;
|
||||
if (!GetKey(value, result))
|
||||
MYTHROW(NoKeyForValueException, (value));
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<K, V> m_kToV;
|
||||
std::unordered_map<V, K> m_vToK;
|
||||
|
|
Loading…
Add table
Reference in a new issue