From da9235ed8baa83576a6d784304acd4bf9a893133 Mon Sep 17 00:00:00 2001 From: Daniel <d.hornung@indiscale.com> Date: Thu, 16 May 2024 15:57:22 +0200 Subject: [PATCH] ENH: Values can hold empty lists now. --- doc/Install_develop.rst | 5 ++++- include/caosdb/value.h | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/Install_develop.rst b/doc/Install_develop.rst index bf4fb03..1376d0a 100644 --- a/doc/Install_develop.rst +++ b/doc/Install_develop.rst @@ -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 ``-DCMAKE_CXX_FLAGS="-Wno-unused-parameter"`` 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 ^^^ -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 ^^^^^^^^^ diff --git a/include/caosdb/value.h b/include/caosdb/value.h index cffb111..6b25bbb 100644 --- a/include/caosdb/value.h +++ b/include/caosdb/value.h @@ -36,6 +36,10 @@ for (const auto &value : values) { \ 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 { @@ -385,7 +389,9 @@ public: return !IsNull() && this->wrapped->value_case() == ValueCase::kListValues; } [[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 static std::vector<ScalarValue> empty_values; return empty_values; -- GitLab