diff --git a/include/podio/Frame.h b/include/podio/Frame.h index de05932ad..eb44e3c54 100644 --- a/include/podio/Frame.h +++ b/include/podio/Frame.h @@ -233,7 +233,7 @@ class Frame { /// @param value The value of the parameter. A copy will be put into the Frame template > inline void putParameter(const std::string& key, T value) { - m_self->parameters().set(key, std::move(value)); + m_self->parameters().setValue(key, std::move(value)); } /// Add a string value to the parameters of the Frame. @@ -284,7 +284,7 @@ class Frame { /// @returns An optional holding the value if it was present template > inline auto getParameter(const std::string& key) const { - return m_self->parameters().get(key); + return m_self->parameters().getValue(key); } /// Retrieve all parameters stored in this Frame. diff --git a/include/podio/GenericParameters.h b/include/podio/GenericParameters.h index 6eb6634c9..3d08b5bfd 100644 --- a/include/podio/GenericParameters.h +++ b/include/podio/GenericParameters.h @@ -73,26 +73,26 @@ class GenericParameters { ~GenericParameters() = default; template > - std::optional get(const std::string& key) const; + std::optional getValue(const std::string& key) const; /// Store (a copy of) the passed value under the given key template > - void set(const std::string& key, T value); + void setValue(const std::string& key, T value); /// Overload for catching const char* setting for string values - void set(const std::string& key, std::string value) { - set(key, std::move(value)); + void setValue(const std::string& key, std::string value) { + setValue(key, std::move(value)); } /// Overload for catching initializer list setting of string vector values - void set(const std::string& key, std::vector values) { - set>(key, std::move(values)); + void setValue(const std::string& key, std::vector values) { + setValue>(key, std::move(values)); } /// Overload for catching initializer list setting for vector values template >> - void set(const std::string& key, std::initializer_list&& values) { - set>(key, std::move(values)); + void setValue(const std::string& key, std::initializer_list&& values) { + setValue>(key, std::move(values)); } /// Get the number of elements stored under the given key for a type @@ -183,7 +183,7 @@ class GenericParameters { }; template -std::optional GenericParameters::get(const std::string& key) const { +std::optional GenericParameters::getValue(const std::string& key) const { const auto& map = getMap(); auto& mtx = getMutex(); std::lock_guard lock{mtx}; @@ -202,7 +202,7 @@ std::optional GenericParameters::get(const std::string& key) const { } template -void GenericParameters::set(const std::string& key, T value) { +void GenericParameters::setValue(const std::string& key, T value) { auto& map = getMap(); auto& mtx = getMutex(); diff --git a/tests/unittests/unittest.cpp b/tests/unittests/unittest.cpp index 9188c0d44..b4b797e1e 100644 --- a/tests/unittests/unittest.cpp +++ b/tests/unittests/unittest.cpp @@ -980,35 +980,35 @@ TEST_CASE("GenericParameters", "[generic-parameters]") { // Check that GenericParameters work as intended auto gp = podio::GenericParameters{}; - gp.set("anInt", 42); - REQUIRE(*gp.get("anInt") == 42); + gp.setValue("anInt", 42); + REQUIRE(*gp.getValue("anInt") == 42); // Make sure that resetting a value with the same key works - gp.set("anInt", -42); - REQUIRE(*gp.get("anInt") == -42); + gp.setValue("anInt", -42); + REQUIRE(*gp.getValue("anInt") == -42); // Make sure that passing a string literal is converted to a string on the fly - gp.set("aString", "const char initialized"); - REQUIRE(*gp.get("aString") == "const char initialized"); + gp.setValue("aString", "const char initialized"); + REQUIRE(*gp.getValue("aString") == "const char initialized"); - gp.set("aStringVec", {"init", "from", "const", "chars"}); - const auto stringVec = gp.get>("aStringVec").value(); + gp.setValue("aStringVec", {"init", "from", "const", "chars"}); + const auto stringVec = gp.getValue>("aStringVec").value(); REQUIRE(stringVec.size() == 4); REQUIRE(stringVec[0] == "init"); REQUIRE(stringVec[3] == "chars"); // Check that storing double values works - gp.set("double", 1.234); - gp.set("manyDoubles", {1.23, 4.56, 7.89}); - REQUIRE(gp.get("double") == 1.234); - const auto storedDoubles = gp.get>("manyDoubles").value(); + gp.setValue("double", 1.234); + gp.setValue("manyDoubles", {1.23, 4.56, 7.89}); + REQUIRE(gp.getValue("double") == 1.234); + const auto storedDoubles = gp.getValue>("manyDoubles").value(); REQUIRE(storedDoubles.size() == 3); REQUIRE(storedDoubles[0] == 1.23); REQUIRE(storedDoubles[1] == 4.56); REQUIRE(storedDoubles[2] == 7.89); // Check that passing an initializer_list creates the vector on the fly - gp.set("manyInts", {1, 2, 3, 4}); - const auto ints = gp.get>("manyInts").value(); + gp.setValue("manyInts", {1, 2, 3, 4}); + const auto ints = gp.getValue>("manyInts").value(); REQUIRE(ints.size() == 4); for (int i = 0; i < 4; ++i) { REQUIRE(ints[i] == i + 1); @@ -1016,71 +1016,71 @@ TEST_CASE("GenericParameters", "[generic-parameters]") { auto floats = std::vector{3.14f, 2.718f}; // This stores a copy of the current value - gp.set("someFloats", floats); + gp.setValue("someFloats", floats); // Hence, modifying the original vector will not be reflected floats.push_back(42.f); REQUIRE(floats.size() == 3); - const auto storedFloats = gp.get>("someFloats").value(); + const auto storedFloats = gp.getValue>("someFloats").value(); REQUIRE(storedFloats.size() == 2); REQUIRE(storedFloats[0] == 3.14f); REQUIRE(storedFloats[1] == 2.718f); // We can at this point reset this to a single value with the same key even if // it has been a vector before - gp.set("someFloats", 12.34f); - REQUIRE(*gp.get("someFloats") == 12.34f); + gp.setValue("someFloats", 12.34f); + REQUIRE(*gp.getValue("someFloats") == 12.34f); // Missing values return an empty optional - REQUIRE_FALSE(gp.get("Missing")); - REQUIRE_FALSE(gp.get("Missing")); - REQUIRE_FALSE(gp.get("Missing")); + REQUIRE_FALSE(gp.getValue("Missing")); + REQUIRE_FALSE(gp.getValue("Missing")); + REQUIRE_FALSE(gp.getValue("Missing")); // Same for vectors - REQUIRE_FALSE(gp.get>("Missing")); - REQUIRE_FALSE(gp.get>("Missing")); - REQUIRE_FALSE(gp.get>("Missing")); + REQUIRE_FALSE(gp.getValue>("Missing")); + REQUIRE_FALSE(gp.getValue>("Missing")); + REQUIRE_FALSE(gp.getValue>("Missing")); } TEST_CASE("GenericParameters constructors", "[generic-parameters]") { // Tests for making sure that generic parameters can be moved / copied correctly auto originalParams = podio::GenericParameters{}; - originalParams.set("int", 42); - originalParams.set("ints", {1, 2}); - originalParams.set("float", 3.14f); - originalParams.set("double", 2 * 3.14); - originalParams.set("strings", {"one", "two", "three"}); + originalParams.setValue("int", 42); + originalParams.setValue("ints", {1, 2}); + originalParams.setValue("float", 3.14f); + originalParams.setValue("double", 2 * 3.14); + originalParams.setValue("strings", {"one", "two", "three"}); SECTION("Copy constructor") { auto copiedParams = originalParams; - REQUIRE(*copiedParams.get("int") == 42); - REQUIRE(copiedParams.get>("ints").value()[1] == 2); - REQUIRE(*copiedParams.get("float") == 3.14f); - REQUIRE(*copiedParams.get("double") == 2 * 3.14); - REQUIRE(copiedParams.get>("strings").value()[0] == "one"); + REQUIRE(*copiedParams.getValue("int") == 42); + REQUIRE(copiedParams.getValue>("ints").value()[1] == 2); + REQUIRE(*copiedParams.getValue("float") == 3.14f); + REQUIRE(*copiedParams.getValue("double") == 2 * 3.14); + REQUIRE(copiedParams.getValue>("strings").value()[0] == "one"); // Make sure these are truly independent copies now - copiedParams.set("anotherDouble", 1.2345); - REQUIRE_FALSE(originalParams.get("anotherDouble")); + copiedParams.setValue("anotherDouble", 1.2345); + REQUIRE_FALSE(originalParams.getValue("anotherDouble")); } SECTION("Move constructor") { auto copiedParams = std::move(originalParams); - REQUIRE(copiedParams.get("int") == 42); - REQUIRE(copiedParams.get>("ints").value()[1] == 2); - REQUIRE(copiedParams.get("float") == 3.14f); - REQUIRE(copiedParams.get("double") == 2 * 3.14); - REQUIRE(copiedParams.get>("strings").value()[0] == "one"); + REQUIRE(copiedParams.getValue("int") == 42); + REQUIRE(copiedParams.getValue>("ints").value()[1] == 2); + REQUIRE(copiedParams.getValue("float") == 3.14f); + REQUIRE(copiedParams.getValue("double") == 2 * 3.14); + REQUIRE(copiedParams.getValue>("strings").value()[0] == "one"); } SECTION("Move assignment") { auto copiedParams = podio::GenericParameters{}; copiedParams = std::move(originalParams); - REQUIRE(copiedParams.get("int") == 42); - REQUIRE(copiedParams.get>("ints").value()[1] == 2); - REQUIRE(copiedParams.get("float") == 3.14f); - REQUIRE(copiedParams.get("double") == 2 * 3.14); - REQUIRE(copiedParams.get>("strings").value()[0] == "one"); + REQUIRE(copiedParams.getValue("int") == 42); + REQUIRE(copiedParams.getValue>("ints").value()[1] == 2); + REQUIRE(copiedParams.getValue("float") == 3.14f); + REQUIRE(copiedParams.getValue("double") == 2 * 3.14); + REQUIRE(copiedParams.getValue>("strings").value()[0] == "one"); } }