Skip to content
Snippets Groups Projects
Verified Commit da9235ed authored by Daniel Hornung's avatar Daniel Hornung
Browse files

ENH: Values can hold empty lists now.

parent a1af0a28
No related branches found
No related tags found
2 merge requests!61Release 0.3.0,!50ENH: Values can hold empty vector
Pipeline #51083 failed
This commit is part of merge request !50. Comments created here will be created in the context of that merge request.
...@@ -189,11 +189,14 @@ For the tests there is a slightly different setup required (with option ...@@ -189,11 +189,14 @@ For the tests there is a slightly different setup required (with option
- Depending on the clang version it may be necessary to also add - Depending on the clang version it may be necessary to also add
``-DCMAKE_CXX_FLAGS="-Wno-unused-parameter"`` ``-DCMAKE_CXX_FLAGS="-Wno-unused-parameter"``
4. ``cmake --build .`` 4. ``cmake --build .``
- If this fails with ``Error running '': No such file or directory``, you may want to try
CMake's ``-D SKIP_LINTING=ON``. (See previous step.)
Run Run
^^^ ^^^
In the build directory, run ``ctest`` In the build directory, run ``ctest``. For more verbose output of a single test:
``ctest -R test_value.test_list -V``
Framework Framework
^^^^^^^^^ ^^^^^^^^^
......
...@@ -36,6 +36,10 @@ ...@@ -36,6 +36,10 @@
for (const auto &value : values) { \ for (const auto &value : values) { \
this->wrapped->mutable_list_values()->add_values()->SETTER(value); \ this->wrapped->mutable_list_values()->add_values()->SETTER(value); \
} \ } \
if (values.empty()) { \
this->wrapped->mutable_list_values()->add_values()->set_special_value \
(ProtoSpecialValue::SPECIAL_VALUE_UNSPECIFIED); \
} \
} }
namespace caosdb::entity { namespace caosdb::entity {
...@@ -385,7 +389,9 @@ public: ...@@ -385,7 +389,9 @@ public:
return !IsNull() && this->wrapped->value_case() == ValueCase::kListValues; return !IsNull() && this->wrapped->value_case() == ValueCase::kListValues;
} }
[[nodiscard]] inline auto GetAsVector() const noexcept -> const std::vector<ScalarValue> & { [[nodiscard]] inline auto GetAsVector() const noexcept -> const std::vector<ScalarValue> & {
if (!IsVector()) { if (!IsVector() || (this->wrapped->list_values().values(0).has_special_value()
&& this->wrapped->list_values().values(0).special_value()
== ProtoSpecialValue::SPECIAL_VALUE_UNSPECIFIED)) {
// create empty list // create empty list
static std::vector<ScalarValue> empty_values; static std::vector<ScalarValue> empty_values;
return empty_values; return empty_values;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment