diff --git a/src/db/db/dbPCellDeclaration.cc b/src/db/db/dbPCellDeclaration.cc index 66b76238a..009f8db80 100644 --- a/src/db/db/dbPCellDeclaration.cc +++ b/src/db/db/dbPCellDeclaration.cc @@ -48,6 +48,34 @@ PCellDeclaration::release_ref () } } +const std::vector & +PCellDeclaration::parameter_declarations () const +{ + if (! m_has_parameter_declarations || ! wants_parameter_declaration_caching ()) { + std::vector pcp = get_parameter_declarations (); + // NOTE: this ensures that reallocation of the vector only happens if the parameters + // change. This makes the returned reference more stable and iterators over this reference + // don't get invalidated so easily if wants_parameter_declaration_caching is false. + if (m_parameter_declarations != pcp) { + m_parameter_declarations = pcp; + } + m_has_parameter_declarations = true; + } + return m_parameter_declarations; +} + +const std::string & +PCellDeclaration::parameter_name (size_t index) +{ + const std::vector &pcp = parameter_declarations (); + if (index < pcp.size ()) { + return pcp [index].get_name (); + } else { + static std::string empty; + return empty; + } +} + pcell_parameters_type PCellDeclaration::map_parameters (const std::map ¶m_by_name) const { diff --git a/src/db/db/dbPCellDeclaration.h b/src/db/db/dbPCellDeclaration.h index fa2362962..dd1c9d299 100644 --- a/src/db/db/dbPCellDeclaration.h +++ b/src/db/db/dbPCellDeclaration.h @@ -266,6 +266,22 @@ public: m_choice_descriptions = choice_descriptions; } + /** + * @brief Equality + */ + bool operator== (const db::PCellParameterDeclaration &d) const + { + return m_choices == d.m_choices && + m_choice_descriptions == d.m_choice_descriptions && + m_default == d.m_default && + m_hidden == d.m_hidden && + m_readonly == d.m_readonly && + m_type == d.m_type && + m_name == d.m_name && + m_description == d.m_description && + m_unit == d.m_unit; + } + private: std::vector m_choices; std::vector m_choice_descriptions; @@ -451,28 +467,12 @@ public: * the cached declarations and therefore is much faster, in particular if the actual * implementation is done in a script. */ - const std::vector ¶meter_declarations () const - { - if (! m_has_parameter_declarations || ! wants_parameter_declaration_caching ()) { - m_parameter_declarations = get_parameter_declarations (); - m_has_parameter_declarations = true; - } - return m_parameter_declarations; - } + const std::vector ¶meter_declarations () const; /** * @brief Gets the parameter name for the given parameter index */ - const std::string ¶meter_name (size_t index) - { - const std::vector &pcp = parameter_declarations (); - if (index < pcp.size ()) { - return pcp [index].get_name (); - } else { - static std::string empty; - return empty; - } - } + const std::string ¶meter_name (size_t index); /** * @brief Return the parameter declarations