.. _program_listing_file_SeQuant_domain_mbpt_op_registry.cpp: Program Listing for File op_registry.cpp ======================================== |exhale_lsh| :ref:`Return to documentation for file ` (``SeQuant/domain/mbpt/op_registry.cpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // // Created by Ajay Melekamburath on 12/14/25. // #include #include #include namespace sequant::mbpt { void OpRegistry::validate_op(const std::wstring& op) const { if (!reserved::is_nonreserved(op)) { throw std::runtime_error("mbpt::OpRegistry::add: operator " + toUtf8(op) + " uses a reserved label"); } if (this->contains(op)) { throw std::runtime_error("mbpt::OpRegistry::add: operator " + toUtf8(op) + " already exists in registry"); } } OpRegistry& OpRegistry::operator=(const OpRegistry& other) { ops_ = other.ops_; return *this; } OpRegistry& OpRegistry::operator=(OpRegistry&& other) noexcept { ops_ = std::move(other.ops_); return *this; } OpRegistry& OpRegistry::add(const std::wstring& op, OpClass action) { this->validate_op(op); ops_->emplace(op, action); return *this; } OpRegistry& OpRegistry::remove(const std::wstring& op) { if (!this->contains(op)) { throw std::runtime_error("mbpt::OpRegistry::remove: operator " + toUtf8(op) + " does not exist in registry"); } ops_->erase(op); return *this; } bool OpRegistry::contains(const std::wstring& op) const { return ops_->contains(op); } OpClass OpRegistry::to_class(const std::wstring& op) const { auto it = ops_->find(op); if (it == ops_->end()) { throw std::runtime_error("mbpt::OpRegistry::to_class: operator " + toUtf8(op) + " does not exist in registry"); } return it->second; } OpRegistry OpRegistry::clone() const { OpRegistry result(*this); result.ops_ = std::make_shared>(*ops_); return result; } } // namespace sequant::mbpt