diff options
author | Aaron Rossetto <aaron.rossetto@ni.com> | 2020-07-22 12:51:21 -0500 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2020-07-24 13:15:30 -0500 |
commit | a5fe0b071d7041f0539804cd16ada27d920bc96d (patch) | |
tree | 840f254f2f2d0165681706f7c539bdc48a52e67f /host/include | |
parent | 4b01628cad132db68ec1cc8cce211f2df0f62770 (diff) | |
download | uhd-a5fe0b071d7041f0539804cd16ada27d920bc96d.tar.gz uhd-a5fe0b071d7041f0539804cd16ada27d920bc96d.tar.bz2 uhd-a5fe0b071d7041f0539804cd16ada27d920bc96d.zip |
rfnoc: Support instance overrides in set_properties()
This commit adds an enhancement to node_t::set_properties() in which
the instance argument provided to the function (which normally applies
to all properties in the key/value list) can be overridden on a
per-property basis using a special syntax.
If the key consists of the property name followed by a colon (':') and
then a number, the number following the colon is used to determine which
instance of the property this set pertains to, and the value passed via
the instance parameter is ignored for that property. For example, in the
following call:
node->set_properties("dog=10,cat:2=5,bird:0=0.5", 1)
instance 1 of node's 'dog' property is set to 10, the 1 coming from the
instance parameter, instance 2 of the node's 'cat' property is set to 5
due to the override syntax provided in the string, and instance 0 of the
node's 'bird' property is set to 0.5 due to its override.
If the name/instance pair is malformed, e.g. 'value:=10' or
'value:foobar=10', a runtime error is thrown.
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/rfnoc/node.hpp | 21 | ||||
-rw-r--r-- | host/include/uhd/rfnoc/property.hpp | 3 |
2 files changed, 24 insertions, 0 deletions
diff --git a/host/include/uhd/rfnoc/node.hpp b/host/include/uhd/rfnoc/node.hpp index b26546643..9d66c516a 100644 --- a/host/include/uhd/rfnoc/node.hpp +++ b/host/include/uhd/rfnoc/node.hpp @@ -135,6 +135,27 @@ public: * * Property resolution happens after all properties have been updated. * + * This function allows the client to override the \p instance parameter + * for each property key/value pair passed in via the \p props parameter. + * If the key consists of the property name, followed by a colon (':') and + * then a number, the number following the colon is used to determine + * which instance of the property this set pertains to, and the \p + * instance parameter is ignored for that property. (Note that if the key + * does not have the colon and instance number override syntax, then + * \p instance is still used to determine which instance of the property + * to set. For example, in the following call: + * + * node->set_properties("dog=10,cat:2=5,bird:0=0.5", 1) + * + * instance 1 of node's 'dog' property is set to 10, the 1 coming from the + * instance parameter, instance 2 of the node's 'cat' property is set to + * 5 due to the override syntax provided in the string, and instance 0 of + * the node's 'bird' property is set to 0.5 due to its override. + * + * If the instance override is malformed, that is, there is no + * number following the colon, or the number cannot be parsed as an + * integer, a value_error is thrown. + * * If a key in \p props is not a valid property of this block, a warning is * logged, but no error is raised. */ diff --git a/host/include/uhd/rfnoc/property.hpp b/host/include/uhd/rfnoc/property.hpp index a1e877440..a5c7246d1 100644 --- a/host/include/uhd/rfnoc/property.hpp +++ b/host/include/uhd/rfnoc/property.hpp @@ -36,6 +36,9 @@ public: property_base_t(const std::string& id, const res_source_info& source_info) : _id(id), _source_info(source_info) { + if(_id.find(':') != std::string::npos) { + throw uhd::value_error("Property ID `" + _id + "' contains invalid character!"); + } } //! Gets the ID (name) of this property |