added support for std::string_view for tables and fields

This commit is contained in:
Emiel Bruijntjes 2024-10-24 18:41:00 +02:00
parent ba4b8d3685
commit 6a68d56660
2 changed files with 18 additions and 1 deletions

View File

@ -2,7 +2,7 @@
* Field proxy. Returned by the table. Can be casted to the * Field proxy. Returned by the table. Can be casted to the
* relevant native type (std::string or numeric) * relevant native type (std::string or numeric)
* *
* @copyright 2014 Copernica BV * @copyright 2014 - 2024 Copernica BV
*/ */
/** /**
@ -207,6 +207,22 @@ public:
return *this; return *this;
} }
/**
* Assign a string value
*
* @param value
* @return FieldProxy
*/
FieldProxy &operator=(const std::string_view &value)
{
// in theory we should make a distinction between short and long string,
// but in practive only long strings are accepted
_source->set(_index, LongString(value));
// allow chaining
return *this;
}
/** /**
* Assign a string value * Assign a string value
* *

View File

@ -138,6 +138,7 @@ public:
Table &set(const std::string &name, uint64_t value) { return set(name, ULongLong(value)); } Table &set(const std::string &name, uint64_t value) { return set(name, ULongLong(value)); }
Table &set(const std::string &name, int64_t value) { return set(name, LongLong(value)); } Table &set(const std::string &name, int64_t value) { return set(name, LongLong(value)); }
Table &set(const std::string &name, const std::string &value) { return set(name, LongString(value)); } Table &set(const std::string &name, const std::string &value) { return set(name, LongString(value)); }
Table &set(const std::string &name, const std::string_view &value) { return set(name, LongString(value)); }
Table &set(const std::string &name, const char *value) { return set(name, LongString(std::string(value))); } Table &set(const std::string &name, const char *value) { return set(name, LongString(std::string(value))); }
Table &set(const std::string &name, std::nullptr_t) { return set(name, VoidField()); } Table &set(const std::string &name, std::nullptr_t) { return set(name, VoidField()); }