}
#endif
-Glib::VariantBase ConfigKey::parse_string(string value) const
+Glib::VariantBase ConfigKey::parse_string(string value, enum sr_datatype dt)
{
GVariant *variant;
uint64_t p, q;
- switch (data_type()->id())
+ switch (dt)
{
case SR_T_UINT64:
check(sr_parse_sizestring(value.c_str(), &p));
return Glib::VariantBase(variant, false);
}
+Glib::VariantBase ConfigKey::parse_string(string value) const
+{
+ enum sr_datatype dt = (enum sr_datatype)(data_type()->id());
+ return parse_string(value, dt);
+}
/** Get configuration key by string identifier. */
static const ConfigKey *get_by_identifier(string identifier);
/** Parse a string argument into the appropriate type for this key. */
+ static Glib::VariantBase parse_string(string value, enum sr_datatype dt);
Glib::VariantBase parse_string(string value) const;
return result;
}
+Glib::VariantBase Option::parse_string(string value)
+{
+ enum sr_datatype dt;
+ Glib::VariantBase dflt = default_value();
+ GVariant *tmpl = dflt.gobj();
+
+ if (g_variant_is_of_type(tmpl, G_VARIANT_TYPE_UINT64)) {
+ dt = SR_T_UINT64;
+ } else if (g_variant_is_of_type(tmpl, G_VARIANT_TYPE_STRING)) {
+ dt = SR_T_STRING;
+ } else if (g_variant_is_of_type(tmpl, G_VARIANT_TYPE_BOOLEAN)) {
+ dt = SR_T_BOOL;
+ } else if (g_variant_is_of_type(tmpl, G_VARIANT_TYPE_DOUBLE)) {
+ dt = SR_T_FLOAT;
+ } else if (g_variant_is_of_type(tmpl, G_VARIANT_TYPE_INT32)) {
+ dt = SR_T_INT32;
+ } else {
+ throw Error(SR_ERR_BUG);
+ }
+ return ConfigKey::parse_string(value, dt);
+}
+
OutputFormat::OutputFormat(const struct sr_output_module *structure) :
_structure(structure)
{
Glib::VariantBase default_value() const;
/** Possible values for this option, if a limited set. */
vector<Glib::VariantBase> values() const;
+ /** Parse a string argument into the appropriate type for this option. */
+ Glib::VariantBase parse_string(string value);
private:
Option(const struct sr_option *structure,
shared_ptr<const struct sr_option *> structure_array);