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_; } Type type() const { return type_; }
const Unit *unit() const { return unit_; } 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 const char *stringValue() const; // valid for type string
float floatValue() const; // valid for type float float floatValue() const; // valid for type float
bool boolValue() const; // valid for type bool bool boolValue() const; // valid for type bool

View File

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

View File

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