More robustness for PCell declarations on mutable parameter declarations.

This commit is contained in:
Matthias Koefferlein 2017-11-02 07:37:05 +01:00
parent 0cfc43d297
commit dbc5079bb4
2 changed files with 46 additions and 18 deletions

View File

@ -48,6 +48,34 @@ PCellDeclaration::release_ref ()
} }
} }
const std::vector<PCellParameterDeclaration> &
PCellDeclaration::parameter_declarations () const
{
if (! m_has_parameter_declarations || ! wants_parameter_declaration_caching ()) {
std::vector<PCellParameterDeclaration> 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<db::PCellParameterDeclaration> &pcp = parameter_declarations ();
if (index < pcp.size ()) {
return pcp [index].get_name ();
} else {
static std::string empty;
return empty;
}
}
pcell_parameters_type pcell_parameters_type
PCellDeclaration::map_parameters (const std::map<size_t, tl::Variant> &param_by_name) const PCellDeclaration::map_parameters (const std::map<size_t, tl::Variant> &param_by_name) const
{ {

View File

@ -266,6 +266,22 @@ public:
m_choice_descriptions = choice_descriptions; 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: private:
std::vector<tl::Variant> m_choices; std::vector<tl::Variant> m_choices;
std::vector<std::string> m_choice_descriptions; std::vector<std::string> m_choice_descriptions;
@ -451,28 +467,12 @@ public:
* the cached declarations and therefore is much faster, in particular if the actual * the cached declarations and therefore is much faster, in particular if the actual
* implementation is done in a script. * implementation is done in a script.
*/ */
const std::vector<PCellParameterDeclaration> &parameter_declarations () const const std::vector<PCellParameterDeclaration> &parameter_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;
}
/** /**
* @brief Gets the parameter name for the given parameter index * @brief Gets the parameter name for the given parameter index
*/ */
const std::string &parameter_name (size_t index) const std::string &parameter_name (size_t index);
{
const std::vector<db::PCellParameterDeclaration> &pcp = parameter_declarations ();
if (index < pcp.size ()) {
return pcp [index].get_name ();
} else {
static std::string empty;
return empty;
}
}
/** /**
* @brief Return the parameter declarations * @brief Return the parameter declarations