Skip to content
Snippets Groups Projects
Commit 1330c185 authored by Joscha Schmiedt's avatar Joscha Schmiedt
Browse files

Merge branch 'f-empty-vector' into 'dev'

ENH: Values can hold empty vector

See merge request !50
parents d1e6250c 8bfc898e
No related branches found
No related tags found
2 merge requests!61Release 0.3.0,!50ENH: Values can hold empty vector
Pipeline #53744 passed
Pipeline: caosdb-julialib

#53748

    Pipeline: CaosDB Octave library

    #53747

      Pipeline: caosdb-cppinttest

      #53746

        ......@@ -80,6 +80,7 @@ conan: conan-install-deps conan-create
        .PHONY: conan
        doc:
        @doxygen --version || ( echo "Doxygen not found. Please install Doxygen first." ; exit 1 )
        mkdir -p build && cd build && conan install .. --build=missing -s $(CONAN_SETTINGS) \
        && cmake .. && cmake --build . --target doc-sphinx \
        && echo "The documentation starts at build/doc/sphinx_out/index.html ."
        ......
        ......@@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
        ### Fixed
        - Values can now hold empty vectors and do not silently convert them into a scalar.
        ### Security
        ### Documentation
        ......
        ......@@ -28,6 +28,8 @@ package manager. The compiler must support the C++17 standard.
        1. clone/update the subrepo ``git submodule update --init proto``
        2. ``mkdir build && cd build``
        3. ``conan install .. -s "compiler.libcxx=libstdc++11"``
        - When there are missing dependencies, it may help to run this with ``--build=missing``.
        4. ``cmake -B . ..``
        5. ``cmake --build .``
        ......@@ -189,11 +191,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
        ^^^^^^^^^
        ......
        ......@@ -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;
        ......
        ......@@ -136,6 +136,14 @@ TEST(test_value, test_list) {
        EXPECT_EQ(item.IsString(), true);
        EXPECT_EQ(item.GetAsString(), "id" + std::to_string(counter++));
        }
        // Test empty lists
        auto empty_content = std::vector<int>();
        Value value_0(empty_content);
        EXPECT_TRUE(value_0.IsVector());
        auto const &list_value_0 = value_0.GetAsVector();
        EXPECT_EQ(list_value_0.size(), 0);
        EXPECT_TRUE(list_value_0.empty());
        }
        TEST(test_value, test_scalar_value_to_value) {
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment