Use weak_ptr to hold product manager records

- When selecting a product that's expired, it successfully refreshes the data, but doesn't display unless selected again
- When old data is downloaded, the refresh timer starts at 15 seconds, even if the newest data says the timer should be longer
- Selecting a product should update the recent lists
This commit is contained in:
Dan Paulat 2023-04-08 01:06:56 -05:00
parent 871cae68dd
commit 5fbb748328
2 changed files with 124 additions and 33 deletions

View file

@ -8,10 +8,10 @@ namespace scwx
namespace util
{
template<class Key, class T, class ReturnType = std::optional<T>>
ReturnType GetBoundedElement(std::map<Key, T>& map, Key key)
template<class Key, class T, class ReturnType = std::map<Key, T>::const_pointer>
ReturnType GetBoundedElementPointer(std::map<Key, T>& map, const Key& key)
{
ReturnType element;
ReturnType elementPtr {nullptr};
// Find the first element greater than the key requested
auto it = map.upper_bound(key);
@ -24,26 +24,42 @@ ReturnType GetBoundedElement(std::map<Key, T>& map, Key key)
{
// Get the element immediately preceding, this the element we are
// looking for
element = (--it)->second;
elementPtr = &(*(--it));
}
else
{
// The current element is a good substitute
element = it->second;
elementPtr = &(*it);
}
}
else if (map.size() > 0)
{
// An element with a key greater was not found. If it exists, it must be
// the last element.
element = map.rbegin()->second;
elementPtr = &(*map.rbegin());
}
return elementPtr;
}
template<class Key, class T, class ReturnType = std::optional<T>>
ReturnType GetBoundedElement(std::map<Key, T>& map, const Key& key)
{
ReturnType element;
typename std::map<Key, T>::pointer elementPtr =
GetBoundedElementPointer<Key, T, typename std::map<Key, T>::pointer>(map,
key);
if (elementPtr != nullptr)
{
element = elementPtr->second;
}
return element;
}
template<class Key, class T>
inline T GetBoundedElementValue(std::map<Key, T>& map, Key key)
inline T GetBoundedElementValue(std::map<Key, T>& map, const Key& key)
{
return GetBoundedElement<Key, T, T>(map, key);
}