Property::to_string

Signed-off-by: James Cherry <cherry@parallaxsw.com>
This commit is contained in:
James Cherry 2025-04-24 11:09:30 -07:00
parent 03d2a48f46
commit 8ba75fdb9c
3 changed files with 12 additions and 11 deletions

View File

@ -85,7 +85,7 @@ public:
Type type() const { return type_; }
const Unit *unit() const { return unit_; }
const char *asString(const Network *network) const;
std::string to_string(const Network *network) const;
const char *stringValue() const; // valid for type string
float floatValue() const; // valid for type float
bool boolValue() const; // valid for type bool

View File

@ -1227,12 +1227,13 @@ filter_objects(const char *property,
bool not_pattern_match = stringEq(op, "!~");
for (T *object : *objects) {
PropertyValue value(getProperty(object, property, sta));
const char *prop = value.asString(sta->network());
if (prop &&
((exact_match && stringEq(prop, pattern))
|| (not_match && !stringEq(prop, pattern))
|| (pattern_match && patternMatch(pattern, prop))
|| (not_pattern_match && !patternMatch(pattern, prop))))
string prop_str = value.to_string(sta->network());
const char *prop = prop_str.c_str();
if (!prop_str.empty()
&& ((exact_match && stringEq(prop, pattern))
|| (not_match && !stringEq(prop, pattern))
|| (pattern_match && patternMatch(pattern, prop))
|| (not_pattern_match && !patternMatch(pattern, prop))))
filtered_objects.push_back(object);
}
delete objects;

View File

@ -613,8 +613,8 @@ PropertyValue::operator=(PropertyValue &&value)
return *this;
}
const char *
PropertyValue::asString(const Network *network) const
string
PropertyValue::to_string(const Network *network) const
{
switch (type_) {
case Type::type_string:
@ -652,9 +652,9 @@ PropertyValue::asString(const Network *network) const
case Type::type_clks:
case Type::type_paths:
case Type::type_pwr_activity:
return nullptr;
return "";
}
return nullptr;
return "";
}
const char *