diff --git a/block.cc b/block.cc index a450b99cdd..7871c92abd 100644 --- a/block.cc +++ b/block.cc @@ -13,20 +13,19 @@ Block::Block(uint64_t b_id, {} uint64_t Block::detach_object_id(uint64_t o_id) { - try { + if(auto search = this->attached_object_ids.find(o_id); + search != this->attached_object_ids.end()) { this->attached_object_ids.erase(o_id); } - catch(const nb::type_error e) { - std::cerr << e.what() << '\n'; + else { + throw nb::type_error( + "object id " + std::to_string(o_id) + + " is not attached to block " + std::to_string(this->get_id()) + ); } return this->attached_object_ids.size(); } -void Block::attach_object_id(uint64_t o_id) { - this->attached_object_ids.insert(o_id); -} - - std::string Block::to_string() const { std::string out; out += "Block id: " + std::to_string(this->get_id()) diff --git a/block.h b/block.h index 931980d6e6..b8661d8036 100644 --- a/block.h +++ b/block.h @@ -12,7 +12,6 @@ #include #include #include -#include #include namespace nb = nanobind; @@ -29,14 +28,37 @@ struct Block uint64_t home_id; double size = 0; std::unordered_set attached_object_ids; + + /** + * Return block object ids. + */ + std::unordered_set get_attached_object_ids() const { return this->attached_object_ids; }; public: + /** + * Return block ID. + */ uint64_t get_id() const { return this->index; }; + + /** + * Return block home ID. + */ uint64_t get_home_id() const { return this->home_id; }; + + /** + * Return block size. + */ double get_size() const { return this->size; }; - std::unordered_set get_attached_object_ids() const { return this->attached_object_ids; }; + + /** + * Try to detach object ID from block and return length. + */ uint64_t detach_object_id(uint64_t); - void attach_object_id(uint64_t); + + /** + * Attach object ID to block. + */ + void attach_object_id(uint64_t o_id) { this->attached_object_ids.insert(o_id); }; std::string to_string() const;