Add some missing functions to CCMap
This commit is contained in:
parent
acba0ba40b
commit
114cd22f76
1 changed files with 16 additions and 4 deletions
|
|
@ -22,7 +22,10 @@ namespace sfz {
|
|||
template <class ValueType>
|
||||
class CCMap {
|
||||
public:
|
||||
CCMap() = delete;
|
||||
CCMap()
|
||||
: defaultValue(ValueType {})
|
||||
{
|
||||
}
|
||||
/**
|
||||
* @brief Construct a new CCMap object with the specified default value.
|
||||
*
|
||||
|
|
@ -44,7 +47,7 @@ public:
|
|||
*/
|
||||
const ValueType& getWithDefault(int index) const noexcept
|
||||
{
|
||||
auto it = absl::c_lower_bound(container, index, CCDataComparator<ValueType>{});
|
||||
auto it = absl::c_lower_bound(container, index, CCDataComparator<ValueType> {});
|
||||
if (it == container.end() || it->cc != index) {
|
||||
return defaultValue;
|
||||
} else {
|
||||
|
|
@ -60,7 +63,7 @@ public:
|
|||
*/
|
||||
ValueType& operator[](const int& index) noexcept
|
||||
{
|
||||
auto it = absl::c_lower_bound(container, index, CCDataComparator<ValueType>{});
|
||||
auto it = absl::c_lower_bound(container, index, CCDataComparator<ValueType> {});
|
||||
if (it == container.end() || it->cc != index) {
|
||||
auto inserted = container.insert(it, { index, defaultValue });
|
||||
return inserted->data;
|
||||
|
|
@ -85,10 +88,19 @@ public:
|
|||
*/
|
||||
bool contains(int index) const noexcept
|
||||
{
|
||||
return absl::c_binary_search(container, index, CCDataComparator<ValueType>{});
|
||||
return absl::c_binary_search(container, index, CCDataComparator<ValueType> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Container size
|
||||
*
|
||||
* @return size_t
|
||||
*/
|
||||
size_t size() const noexcept { return container.size(); }
|
||||
|
||||
typename std::vector<CCData<ValueType>>::const_iterator begin() const { return container.cbegin(); }
|
||||
typename std::vector<CCData<ValueType>>::const_iterator end() const { return container.cend(); }
|
||||
|
||||
private:
|
||||
// typename std::vector<std::pair<int, ValueType>>::iterator begin() { return container.begin(); }
|
||||
// typename std::vector<std::pair<int, ValueType>>::iterator end() { return container.end(); }
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue