Skip to content
21 changes: 11 additions & 10 deletions src/api/cpp/nixl_descriptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,19 +323,20 @@ class nixlDescList {
/**
* @brief Check if nixlDescList is empty or not
*/
inline bool
isEmpty() const {
return (descs.size() == 0);
bool
isEmpty() const noexcept {
return descs.empty();
}

/**
* @brief Operator [] overloading, get/set descriptor at [index].
* Can throw std::out_of_range exception.
*/
const T &
operator[](unsigned int index) const;
virtual T &
operator[](unsigned int index);
operator[](size_t index) const {
return descs[index];
}

T &
operator[](size_t index) {
return descs[index];
}
Comment thread
iyastreb marked this conversation as resolved.

/**
* @brief Vector like iterators for const and non-const elements
Expand Down
6 changes: 5 additions & 1 deletion src/infra/mem_section.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <array>
#include <string>
#include <set>
#include <cassert>
#include "nixl_descriptors.h"
#include "nixl.h"
#include "backend/backend_engine.h"
Expand Down Expand Up @@ -71,7 +72,10 @@ class nixlSecDescList : public nixlDescList<nixlSectionDesc> {
verifySorted() const;

nixlSectionDesc &
operator[](unsigned int index) override;
operator[](size_t index) {
assert(verifySorted());
return descs[index];
}
Comment thread
iyastreb marked this conversation as resolved.

int
getIndex(const nixlBasicDesc &query) const override;
Expand Down
23 changes: 0 additions & 23 deletions src/infra/nixl_descriptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,6 @@ nixlDescList<T>::nixlDescList(nixlSerDes* deserializer) {
}
}

// Getter
template <class T>
inline const T& nixlDescList<T>::operator[](unsigned int index) const {
// To be added only in debug mode
// if (index >= descs.size())
// throw std::out_of_range("Index is out of range");
return descs[index];
}

// Setter
template <class T>
inline T& nixlDescList<T>::operator[](unsigned int index) {
assert(index < descs.size());
Comment thread
brminich marked this conversation as resolved.
return descs[index];
}

template <class T>
void nixlDescList<T>::addDesc (const T &desc) {
descs.push_back(desc);
Expand Down Expand Up @@ -386,13 +370,6 @@ nixlSecDescList::verifySorted() const {
return true;
}

nixlSectionDesc &
nixlSecDescList::operator[](unsigned int index) {
nixlSectionDesc &ref = this->descs[index];
assert(verifySorted());
return ref;
}

int
nixlSecDescList::getIndex(const nixlBasicDesc &query) const {
auto itr = std::lower_bound(this->descs.begin(), this->descs.end(), query);
Expand Down