diff --git a/src/db/db/dbLayoutToNetlist.cc b/src/db/db/dbLayoutToNetlist.cc index 04095cb64..e8bfccf83 100644 --- a/src/db/db/dbLayoutToNetlist.cc +++ b/src/db/db/dbLayoutToNetlist.cc @@ -2055,7 +2055,7 @@ db::Region LayoutToNetlist::antenna_check (const db::Region &gate, double gate_a } db::Region -LayoutToNetlist::measure_net (const db::Region &primary, const std::map &secondary, const std::string &expression) +LayoutToNetlist::measure_net (const db::Region &primary, const std::map &secondary, const std::string &expression, const std::map &variables) { // TODO: that's basically too much .. we only need the clusters if (! m_netlist_extracted) { @@ -2065,6 +2065,25 @@ LayoutToNetlist::measure_net (const db::Region &primary, const std::mapfirst, v->second); + } + + eval.set_primary_layer (layer_of (primary)); + for (auto s = secondary.begin (); s != secondary.end (); ++s) { + if (s->second) { + eval.set_secondary_layer (s->first, layer_of (*s->second)); + } + } + + eval.init (); + + tl::Extractor ex (expression.c_str ()); + tl::Expression compiled_expr; + eval.parse (compiled_expr, ex); + db::DeepLayer dl (&dss (), m_layout_index, ly.insert_layer ()); for (db::Layout::bottom_up_const_iterator cid = ly.begin_bottom_up (); cid != ly.end_bottom_up (); ++cid) { @@ -2074,21 +2093,6 @@ LayoutToNetlist::measure_net (const db::Region &primary, const std::mapsecond) { - eval.set_secondary_layer (s->first, layer_of (*s->second)); - } - } - - eval.init (); - - tl::Extractor ex (expression.c_str ()); - tl::Expression compiled_expr; - eval.parse (compiled_expr, ex); - for (connected_clusters::all_iterator c = clusters.begin_all (); ! c.at_end (); ++c) { if (! clusters.is_root (*c)) { diff --git a/src/db/db/dbLayoutToNetlist.h b/src/db/db/dbLayoutToNetlist.h index 4eb8b86c4..5b7da320b 100644 --- a/src/db/db/dbLayoutToNetlist.h +++ b/src/db/db/dbLayoutToNetlist.h @@ -1146,9 +1146,9 @@ public: * * "perimeter(name)": the perimeter of the secondary-layer shapes. 'name' is a symbol with the name given in the secondary-layer map * * "put(name, value)": places the value as property 'name' on the output shapes * * "skip(flag)": will skip the primary shapes of that net when called with a true value - * * "net_name": the name of the net + * * "net": the Net object of the current net */ - db::Region measure_net (const db::Region &primary, const std::map &secondary, const std::string &expression); + db::Region measure_net (const db::Region &primary, const std::map &secondary, const std::string &expression, const std::map &variables); /** * @brief Saves the database to the given path diff --git a/src/db/db/dbMeasureEval.cc b/src/db/db/dbMeasureEval.cc index 071b9636c..0f95c8cfb 100644 --- a/src/db/db/dbMeasureEval.cc +++ b/src/db/db/dbMeasureEval.cc @@ -21,6 +21,7 @@ */ #include "dbMeasureEval.h" +#include "gsiClassBase.h" namespace db { @@ -372,11 +373,11 @@ private: MeasureNetEval *mp_eval; }; -class NetNameFunction +class NetFunction : public tl::EvalFunction { public: - NetNameFunction (MeasureNetEval *eval) + NetFunction (MeasureNetEval *eval) : mp_eval (eval) { // .. nothing yet .. @@ -385,9 +386,9 @@ public: virtual void execute (const tl::ExpressionParserContext &context, tl::Variant &out, const std::vector &args, const std::map * /*kwargs*/) const { if (args.size () != 1) { - throw tl::EvalError (tl::to_string (tr ("'net_name' function does not take and argument")), context); + throw tl::EvalError (tl::to_string (tr ("'net' function does not take and argument")), context); } - out = mp_eval->net_name_func (); + out = mp_eval->net_func (); } private: @@ -465,7 +466,7 @@ MeasureNetEval::init () define_function ("skip", new NetSkipFunction (this)); define_function ("area", new NetAreaFunction (this)); define_function ("perimeter", new NetPerimeterFunction (this)); - define_function ("net_name", new NetNameFunction (this)); + define_function ("net", new NetFunction (this)); } void @@ -531,7 +532,7 @@ MeasureNetEval::skip_func (bool f) const } tl::Variant -MeasureNetEval::net_name_func () const +MeasureNetEval::net_func () const { const db::Netlist *nl = mp_l2n->netlist (); if (! nl) { @@ -552,7 +553,7 @@ MeasureNetEval::net_name_func () const auto n = m_nets_per_cell_and_cluster_id->find (std::make_pair (m_cell_index, m_cluster_id)); if (n != m_nets_per_cell_and_cluster_id->end ()) { - return tl::Variant (n->second->name ()); + return tl::Variant::make_variant_ref (n.operator-> ()); } else { return tl::Variant (); } diff --git a/src/db/db/dbMeasureEval.h b/src/db/db/dbMeasureEval.h index a0957ed2c..aaf899138 100644 --- a/src/db/db/dbMeasureEval.h +++ b/src/db/db/dbMeasureEval.h @@ -137,7 +137,7 @@ private: friend class NetPutFunction; friend class NetAreaFunction; friend class NetPerimeterFunction; - friend class NetNameFunction; + friend class NetFunction; friend class NetSkipFunction; struct AreaAndPerimeter @@ -162,7 +162,7 @@ private: tl::Variant area_func (int layer_index) const; tl::Variant perimeter_func (int layer_index) const; void skip_func (bool f) const; - tl::Variant net_name_func () const; + tl::Variant net_func () const; }; } diff --git a/src/db/db/gsiDeclDbEdgePairs.cc b/src/db/db/gsiDeclDbEdgePairs.cc index 7ece0e1e8..137425533 100644 --- a/src/db/db/gsiDeclDbEdgePairs.cc +++ b/src/db/db/gsiDeclDbEdgePairs.cc @@ -90,9 +90,9 @@ static gsi::EdgePairFilterBase *make_pg (const tl::Variant &name, const std::str return new EdgePairPropertiesFilter (name, pattern, inverse); } -static gsi::EdgePairFilterBase *make_pe (const std::string &expression, bool inverse, double dbu) +static gsi::EdgePairFilterBase *make_pe (const std::string &expression, bool inverse, double dbu, const std::map &variables) { - return new gsi::expression_filter (expression, inverse, dbu); + return new gsi::expression_filter (expression, inverse, dbu, variables); } Class decl_EdgePairFilterBase ("db", "EdgePairFilterBase", @@ -136,11 +136,12 @@ Class decl_EdgePairFilterBase ("db", "EdgePairFilterBas "\n" "This feature has been introduced in version 0.30." ) + - gsi::constructor ("expression_filter", &make_pe, gsi::arg ("expression"), gsi::arg ("inverse", false), gsi::arg ("dbu", 0.0), + gsi::constructor ("expression_filter", &make_pe, gsi::arg ("expression"), gsi::arg ("inverse", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map (), "{}"), "@brief Creates an expression-based filter\n" "@param expression The expression to evaluate.\n" "@param inverse If true, inverts the selection - i.e. all edge pairs without a property with the given name and value range are selected.\n" "@param dbu If given and greater than zero, the shapes delivered by the 'shape' function will be in micrometer units.\n" + "@param variables Arbitrary values that are available as variables inside the expressions.\n" "\n" "Creates a filter that will evaluate the given expression on every shape and select the shape " "when the expression renders a boolean true value. " @@ -256,37 +257,39 @@ Class > decl_EdgePairProcessor ( static property_computation_processor * -new_pcp (const db::EdgePairs *container, const std::map &expressions, bool copy_properties, double dbu) +new_pcp (const db::EdgePairs *container, const std::map &expressions, bool copy_properties, double dbu, const std::map &variables) { - return new property_computation_processor (container, expressions, copy_properties, dbu); + return new property_computation_processor (container, expressions, copy_properties, dbu, variables); } static property_computation_processor * -new_pcps (const db::EdgePairs *container, const std::string &expression, bool copy_properties, double dbu) +new_pcps (const db::EdgePairs *container, const std::string &expression, bool copy_properties, double dbu, const std::map &variables) { std::map expressions; expressions.insert (std::make_pair (tl::Variant (), expression)); - return new property_computation_processor (container, expressions, copy_properties, dbu); + return new property_computation_processor (container, expressions, copy_properties, dbu, variables); } Class > decl_EdgePairPropertiesExpressions (decl_EdgePairProcessorBase, "db", "EdgePairPropertiesExpressions", property_computation_processor::method_decls (true) + - gsi::constructor ("new", &new_pcp, gsi::arg ("edge_pairs"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), + gsi::constructor ("new", &new_pcp, gsi::arg ("edge_pairs"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map (), "{}"), "@brief Creates a new properties expressions operator\n" "\n" "@param edge_pairs The edge pair collection, the processor will be used on. Can be nil, but if given, allows some optimization.\n" "@param expressions A map of property names and expressions used to generate the values of the properties (see class description for details).\n" "@param copy_properties If true, new properties will be added to existing ones.\n" "@param dbu If not zero, this value specifies the database unit to use. If given, the shapes returned by the 'shape' function will be micrometer-unit objects.\n" + "@param variables Arbitrary values that are available as variables inside the expressions.\n" ) + - gsi::constructor ("new", &new_pcps, gsi::arg ("edge_pairs"), gsi::arg ("expression"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), + gsi::constructor ("new", &new_pcps, gsi::arg ("edge_pairs"), gsi::arg ("expression"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map (), "{}"), "@brief Creates a new properties expressions operator\n" "\n" "@param edge_pairs The edge pair collection, the processor will be used on. Can be nil, but if given, allows some optimization.\n" "@param expression A single expression evaluated for each shape (see class description for details).\n" "@param copy_properties If true, new properties will be added to existing ones.\n" "@param dbu If not zero, this value specifies the database unit to use. If given, the shapes returned by the 'shape' function will be micrometer-unit objects.\n" + "@param variables Arbitrary values that are available as variables inside the expressions.\n" ), "@brief An operator attaching computed properties to the edge pairs\n" "\n" diff --git a/src/db/db/gsiDeclDbEdges.cc b/src/db/db/gsiDeclDbEdges.cc index 2455b1abf..c928aee06 100644 --- a/src/db/db/gsiDeclDbEdges.cc +++ b/src/db/db/gsiDeclDbEdges.cc @@ -91,9 +91,9 @@ static gsi::EdgeFilterBase *make_pg (const tl::Variant &name, const std::string return new EdgePropertiesFilter (name, pattern, inverse); } -static gsi::EdgeFilterBase *make_pe (const std::string &expression, bool inverse, double dbu) +static gsi::EdgeFilterBase *make_pe (const std::string &expression, bool inverse, double dbu, const std::map &variables) { - return new gsi::expression_filter (expression, inverse, dbu); + return new gsi::expression_filter (expression, inverse, dbu, variables); } Class decl_EdgeFilterBase ("db", "EdgeFilterBase", @@ -137,11 +137,12 @@ Class decl_EdgeFilterBase ("db", "EdgeFilterBase", "\n" "This feature has been introduced in version 0.30." ) + - gsi::constructor ("expression_filter", &make_pe, gsi::arg ("expression"), gsi::arg ("inverse", false), gsi::arg ("dbu", 0.0), + gsi::constructor ("expression_filter", &make_pe, gsi::arg ("expression"), gsi::arg ("inverse", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map (), "{}"), "@brief Creates an expression-based filter\n" "@param expression The expression to evaluate.\n" "@param inverse If true, inverts the selection - i.e. all edges without a property with the given name and value range are selected.\n" "@param dbu If given and greater than zero, the shapes delivered by the 'shape' function will be in micrometer units.\n" + "@param variables Arbitrary values that are available as variables inside the expressions.\n" "\n" "Creates a filter that will evaluate the given expression on every shape and select the shape " "when the expression renders a boolean true value. " @@ -261,37 +262,39 @@ Class > decl_EdgeOperator (decl_Edge static property_computation_processor * -new_pcp (const db::Edges *container, const std::map &expressions, bool copy_properties, double dbu) +new_pcp (const db::Edges *container, const std::map &expressions, bool copy_properties, double dbu, const std::map &variables) { - return new property_computation_processor (container, expressions, copy_properties, dbu); + return new property_computation_processor (container, expressions, copy_properties, dbu, variables); } static property_computation_processor * -new_pcps (const db::Edges *container, const std::string &expression, bool copy_properties, double dbu) +new_pcps (const db::Edges *container, const std::string &expression, bool copy_properties, double dbu, const std::map &variables) { std::map expressions; expressions.insert (std::make_pair (tl::Variant (), expression)); - return new property_computation_processor (container, expressions, copy_properties, dbu); + return new property_computation_processor (container, expressions, copy_properties, dbu, variables); } Class > decl_EdgePropertiesExpressions (decl_EdgeProcessorBase, "db", "EdgePropertiesExpressions", property_computation_processor::method_decls (true) + - gsi::constructor ("new", &new_pcp, gsi::arg ("edges"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), + gsi::constructor ("new", &new_pcp, gsi::arg ("edges"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map (), "{}"), "@brief Creates a new properties expressions operator\n" "\n" "@param edges The edge collection, the processor will be used on. Can be nil, but if given, allows some optimization.\n" "@param expressions A map of property names and expressions used to generate the values of the properties (see class description for details).\n" "@param copy_properties If true, new properties will be added to existing ones.\n" "@param dbu If not zero, this value specifies the database unit to use. If given, the shapes returned by the 'shape' function will be micrometer-unit objects.\n" + "@param variables Arbitrary values that are available as variables inside the expressions.\n" ) + - gsi::constructor ("new", &new_pcps, gsi::arg ("edges"), gsi::arg ("expression"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), + gsi::constructor ("new", &new_pcps, gsi::arg ("edges"), gsi::arg ("expression"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map (), "{}"), "@brief Creates a new properties expressions operator\n" "\n" "@param edges The edge collection, the processor will be used on. Can be nil, but if given, allows some optimization.\n" "@param expression A single expression evaluated for each shape (see class description for details).\n" "@param copy_properties If true, new properties will be added to existing ones.\n" "@param dbu If not zero, this value specifies the database unit to use. If given, the shapes returned by the 'shape' function will be micrometer-unit objects.\n" + "@param variables Arbitrary values that are available as variables inside the expressions.\n" ), "@brief An operator attaching computed properties to the edge pairs\n" "\n" diff --git a/src/db/db/gsiDeclDbLayoutToNetlist.cc b/src/db/db/gsiDeclDbLayoutToNetlist.cc index 91d5ca21d..6158e16d4 100644 --- a/src/db/db/gsiDeclDbLayoutToNetlist.cc +++ b/src/db/db/gsiDeclDbLayoutToNetlist.cc @@ -216,9 +216,9 @@ static db::Region antenna_check (db::LayoutToNetlist *l2n, const db::Region &pol return antenna_check3 (l2n, poly, 1, 0, metal, 1, 0, ratio, diodes, texts); } -static db::Region measure_net (db::LayoutToNetlist *l2n, const db::Region &primary, const std::map &secondary, const std::string &expression) +static db::Region measure_net (db::LayoutToNetlist *l2n, const db::Region &primary, const std::map &secondary, const std::string &expression, const std::map &variables) { - return l2n->measure_net (primary, secondary, expression); + return l2n->measure_net (primary, secondary, expression, variables); } static void join_net_names (db::LayoutToNetlist *l2n, const std::string &s) @@ -1215,10 +1215,12 @@ Class decl_dbLayoutToNetlist ("db", "LayoutToNetlist", "\n" "This variant has been introduced in version 0.26.6.\n" ) + - gsi::method_ext ("measure_net", &measure_net, gsi::arg ("primary"), gsi::arg ("secondary"), gsi::arg ("expression"), + gsi::method_ext ("measure_net", &measure_net, gsi::arg ("primary"), gsi::arg ("secondary"), gsi::arg ("expression"), gsi::arg ("variables", std::map (), "{}"), "@brief Runs a generic net measurement function\n" "\n" "This method accepts some primary layer, a number of secondary layers with names and an expression.\n" + "It also accepts variables which become available as variables inside the expression. This allows passing " + "arbitrary values without having to encode them into the expression string.\n" "\n" "It will look at nets connecting to shapes on the primary layer and execute the expression for each\n" "of those nets. After that it will copy the primary shapes of the net to the output with the properties\n" @@ -1236,7 +1238,7 @@ Class decl_dbLayoutToNetlist ("db", "LayoutToNetlist", "@li 'perimeter(name)': the perimeter of the secondary-layer shapes. 'name' is a symbol with the name given in the secondary-layer map @/li\n" "@li 'put(name, value)': places the value as property 'name' on the output shapes @/li\n" "@li 'skip(flag)': will skip the primary shapes of that net when called with a true value @/li\n" - "@li 'net_name': the name of the net @/li\n" + "@li 'net': the \\Net object of the current net @/li\n" "@/ul\n" ) + // test API diff --git a/src/db/db/gsiDeclDbMeasureHelpers.h b/src/db/db/gsiDeclDbMeasureHelpers.h index 2ed72114e..d31445288 100644 --- a/src/db/db/gsiDeclDbMeasureHelpers.h +++ b/src/db/db/gsiDeclDbMeasureHelpers.h @@ -98,7 +98,7 @@ public: typedef typename ProcessorBase::shape_type shape_type; typedef typename ProcessorBase::result_type result_type; - property_computation_processor (const Container *container, const std::map &expressions, bool copy_properties, double dbu) + property_computation_processor (const Container *container, const std::map &expressions, bool copy_properties, double dbu, const std::map &variables) : m_eval (dbu, true /*with_put*/), m_copy_properties (copy_properties), m_expression_strings (expressions) { if (container) { @@ -107,6 +107,10 @@ public: m_eval.init (); + for (auto v = variables.begin (); v != variables.end (); ++v) { + m_eval.set_var (v->first, v->second); + } + // compile the expressions for (auto e = m_expression_strings.begin (); e != m_expression_strings.end (); ++e) { m_expressions.push_back (std::make_pair (e->first.is_nil () ? db::property_names_id_type (0) : db::property_names_id (e->first), tl::Expression ())); @@ -170,11 +174,15 @@ class expression_filter public: typedef typename FilterBase::shape_type shape_type; - expression_filter (const std::string &expression, bool inverse, double dbu) + expression_filter (const std::string &expression, bool inverse, double dbu, const std::map &variables) : m_eval (dbu, false /*without put func*/), m_inverse (inverse), m_expression_string (expression) { m_eval.init (); + for (auto v = variables.begin (); v != variables.end (); ++v) { + m_eval.set_var (v->first, v->second); + } + // compile the expression tl::Extractor ex (m_expression_string.c_str ()); m_eval.parse (m_expression, ex); diff --git a/src/db/db/gsiDeclDbRegion.cc b/src/db/db/gsiDeclDbRegion.cc index c70228f17..2eb4604e9 100644 --- a/src/db/db/gsiDeclDbRegion.cc +++ b/src/db/db/gsiDeclDbRegion.cc @@ -109,9 +109,9 @@ static gsi::PolygonFilterBase *make_pg (const tl::Variant &name, const std::stri return new PolygonPropertiesFilter (name, pattern, inverse); } -static gsi::PolygonFilterBase *make_pe (const std::string &expression, bool inverse, double dbu) +static gsi::PolygonFilterBase *make_pe (const std::string &expression, bool inverse, double dbu, const std::map &variables) { - return new gsi::expression_filter (expression, inverse, dbu); + return new gsi::expression_filter (expression, inverse, dbu, variables); } Class decl_PolygonFilterBase ("db", "PolygonFilterBase", @@ -155,11 +155,12 @@ Class decl_PolygonFilterBase ("db", "PolygonFilterBase", "\n" "This feature has been introduced in version 0.30." ) + - gsi::constructor ("expression_filter", &make_pe, gsi::arg ("expression"), gsi::arg ("inverse", false), gsi::arg ("dbu", 0.0), + gsi::constructor ("expression_filter", &make_pe, gsi::arg ("expression"), gsi::arg ("inverse", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map (), "{}"), "@brief Creates an expression-based filter\n" "@param expression The expression to evaluate.\n" "@param inverse If true, inverts the selection - i.e. all polygons without a property with the given name and value range are selected.\n" "@param dbu If given and greater than zero, the shapes delivered by the 'shape' function will be in micrometer units.\n" + "@param variables Arbitrary values that are available as variables inside the expressions.\n" "\n" "Creates a filter that will evaluate the given expression on every shape and select the shape " "when the expression renders a boolean true value. " @@ -277,36 +278,38 @@ Class > decl_PolygonOperator (dec static property_computation_processor * -new_pcp (const db::Region *container, const std::map &expressions, bool copy_properties, double dbu) +new_pcp (const db::Region *container, const std::map &expressions, bool copy_properties, double dbu, const std::map &variables) { - return new property_computation_processor (container, expressions, copy_properties, dbu); + return new property_computation_processor (container, expressions, copy_properties, dbu, variables); } property_computation_processor * -new_pcps (const db::Region *container, const std::string &expression, bool copy_properties, double dbu) +new_pcps (const db::Region *container, const std::string &expression, bool copy_properties, double dbu, const std::map &variables) { std::map expressions; expressions.insert (std::make_pair (tl::Variant (), expression)); - return new property_computation_processor (container, expressions, copy_properties, dbu); + return new property_computation_processor (container, expressions, copy_properties, dbu, variables); } Class > decl_PolygonPropertiesExpressions (decl_PolygonProcessorBase, "db", "PolygonPropertiesExpressions", property_computation_processor::method_decls (true) + - gsi::constructor ("new", &new_pcp, gsi::arg ("region"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), + gsi::constructor ("new", &new_pcp, gsi::arg ("region"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map (), "{}"), "@brief Creates a new properties expressions operator\n" "\n" "@param region The region, the processor will be used on. Can be nil, but if given, allows some optimization.\n" "@param expressions A map of property names and expressions used to generate the values of the properties (see class description for details).\n" "@param copy_properties If true, new properties will be added to existing ones.\n" "@param dbu If not zero, this value specifies the database unit to use. If given, the shapes returned by the 'shape' function will be micrometer-unit objects.\n" + "@param variables Arbitrary values that are available as variables inside the expressions.\n" ) + - gsi::constructor ("new", &new_pcps, gsi::arg ("region"), gsi::arg ("expression"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), + gsi::constructor ("new", &new_pcps, gsi::arg ("region"), gsi::arg ("expression"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map (), "{}"), "@brief Creates a new properties expressions operator\n" "\n" "@param region The region, the processor will be used on. Can be nil, but if given, allows some optimization.\n" "@param expression A single expression evaluated for each shape (see class description for details).\n" "@param copy_properties If true, new properties will be added to existing ones.\n" "@param dbu If not zero, this value specifies the database unit to use. If given, the shapes returned by the 'shape' function will be micrometer-unit objects.\n" + "@param variables Arbitrary values that are available as variables inside the expressions.\n" ), "@brief An operator attaching computed properties to the edge pairs\n" "\n" diff --git a/src/db/db/gsiDeclDbTexts.cc b/src/db/db/gsiDeclDbTexts.cc index d68043fe3..42304eafc 100644 --- a/src/db/db/gsiDeclDbTexts.cc +++ b/src/db/db/gsiDeclDbTexts.cc @@ -87,9 +87,9 @@ static gsi::TextFilterBase *make_pg (const tl::Variant &name, const std::string return new TextPropertiesFilter (name, pattern, inverse); } -static gsi::TextFilterBase *make_pe (const std::string &expression, bool inverse, double dbu) +static gsi::TextFilterBase *make_pe (const std::string &expression, bool inverse, double dbu, const std::map &variables) { - return new gsi::expression_filter (expression, inverse, dbu); + return new gsi::expression_filter (expression, inverse, dbu, variables); } Class decl_TextFilterBase ("db", "TextFilterBase", @@ -133,11 +133,12 @@ Class decl_TextFilterBase ("db", "TextFilterBase", "\n" "This feature has been introduced in version 0.30." ) + - gsi::constructor ("expression_filter", &make_pe, gsi::arg ("expression"), gsi::arg ("inverse", false), gsi::arg ("dbu", 0.0), + gsi::constructor ("expression_filter", &make_pe, gsi::arg ("expression"), gsi::arg ("inverse", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map (), "{}"), "@brief Creates an expression-based filter\n" "@param expression The expression to evaluate.\n" "@param inverse If true, inverts the selection - i.e. all texts without a property with the given name and value range are selected.\n" "@param dbu If given and greater than zero, the shapes delivered by the 'shape' function will be in micrometer units.\n" + "@param variables Arbitrary values that are available as variables inside the expressions.\n" "\n" "Creates a filter that will evaluate the given expression on every shape and select the shape " "when the expression renders a boolean true value. " @@ -256,36 +257,38 @@ Class > decl_TextProcessor (decl_Tex static property_computation_processor * -new_pcp (const db::Texts *container, const std::map &expressions, bool copy_properties, double dbu) +new_pcp (const db::Texts *container, const std::map &expressions, bool copy_properties, double dbu, const std::map &variables) { - return new property_computation_processor (container, expressions, copy_properties, dbu); + return new property_computation_processor (container, expressions, copy_properties, dbu, variables); } property_computation_processor * -new_pcps (const db::Texts *container, const std::string &expression, bool copy_properties, double dbu) +new_pcps (const db::Texts *container, const std::string &expression, bool copy_properties, double dbu, const std::map &variables) { std::map expressions; expressions.insert (std::make_pair (tl::Variant (), expression)); - return new property_computation_processor (container, expressions, copy_properties, dbu); + return new property_computation_processor (container, expressions, copy_properties, dbu, variables); } Class > decl_TextPropertiesExpressions (decl_TextProcessorBase, "db", "TextPropertiesExpressions", property_computation_processor::method_decls (true) + - gsi::constructor ("new", &new_pcp, gsi::arg ("texts"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), + gsi::constructor ("new", &new_pcp, gsi::arg ("texts"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map (), "{}"), "@brief Creates a new properties expressions operator\n" "\n" "@param texts The text collection, the processor will be used on. Can be nil, but if given, allows some optimization.\n" "@param expressions A map of property names and expressions used to generate the values of the properties (see class description for details).\n" "@param copy_properties If true, new properties will be added to existing ones.\n" "@param dbu If not zero, this value specifies the database unit to use. If given, the shapes returned by the 'shape' function will be micrometer-unit objects.\n" + "@param variables Arbitrary values that are available as variables inside the expressions.\n" ) + - gsi::constructor ("new", &new_pcps, gsi::arg ("texts"), gsi::arg ("expression"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), + gsi::constructor ("new", &new_pcps, gsi::arg ("texts"), gsi::arg ("expression"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map (), "{}"), "@brief Creates a new properties expressions operator\n" "\n" "@param texts The text collection, the processor will be used on. Can be nil, but if given, allows some optimization.\n" "@param expression A single expression evaluated for each shape (see class description for details).\n" "@param copy_properties If true, new properties will be added to existing ones.\n" "@param dbu If not zero, this value specifies the database unit to use. If given, the shapes returned by the 'shape' function will be micrometer-unit objects.\n" + "@param variables Arbitrary values that are available as variables inside the expressions.\n" ), "@brief An operator attaching computed properties to the edge pairs\n" "\n"