Skip to content

Commit

Permalink
Bring back original function names
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Apr 10, 2024
1 parent fc541c7 commit 5e95c36
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 58 deletions.
4 changes: 2 additions & 2 deletions include/podio/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class Frame {
/// @param value The value of the parameter. A copy will be put into the Frame
template <typename T, typename = podio::EnableIfValidGenericDataType<T>>
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.
Expand Down Expand Up @@ -284,7 +284,7 @@ class Frame {
/// @returns An optional holding the value if it was present
template <typename T, typename = podio::EnableIfValidGenericDataType<T>>
inline auto getParameter(const std::string& key) const {
return m_self->parameters().get<T>(key);
return m_self->parameters().getValue<T>(key);
}

/// Retrieve all parameters stored in this Frame.
Expand Down
20 changes: 10 additions & 10 deletions include/podio/GenericParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,26 @@ class GenericParameters {
~GenericParameters() = default;

template <typename T, typename = EnableIfValidGenericDataType<T>>
std::optional<T> get(const std::string& key) const;
std::optional<T> getValue(const std::string& key) const;

/// Store (a copy of) the passed value under the given key
template <typename T, typename = EnableIfValidGenericDataType<T>>
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<std::string>(key, std::move(value));
void setValue(const std::string& key, std::string value) {
setValue<std::string>(key, std::move(value));
}

/// Overload for catching initializer list setting of string vector values
void set(const std::string& key, std::vector<std::string> values) {
set<std::vector<std::string>>(key, std::move(values));
void setValue(const std::string& key, std::vector<std::string> values) {
setValue<std::vector<std::string>>(key, std::move(values));
}

/// Overload for catching initializer list setting for vector values
template <typename T, typename = std::enable_if_t<detail::isInTuple<T, SupportedGenericDataTypes>>>
void set(const std::string& key, std::initializer_list<T>&& values) {
set<std::vector<T>>(key, std::move(values));
void setValue(const std::string& key, std::initializer_list<T>&& values) {
setValue<std::vector<T>>(key, std::move(values));
}

/// Get the number of elements stored under the given key for a type
Expand Down Expand Up @@ -183,7 +183,7 @@ class GenericParameters {
};

template <typename T, typename>
std::optional<T> GenericParameters::get(const std::string& key) const {
std::optional<T> GenericParameters::getValue(const std::string& key) const {
const auto& map = getMap<T>();
auto& mtx = getMutex<T>();
std::lock_guard lock{mtx};
Expand All @@ -202,7 +202,7 @@ std::optional<T> GenericParameters::get(const std::string& key) const {
}

template <typename T, typename>
void GenericParameters::set(const std::string& key, T value) {
void GenericParameters::setValue(const std::string& key, T value) {
auto& map = getMap<T>();
auto& mtx = getMutex<T>();

Expand Down
92 changes: 46 additions & 46 deletions tests/unittests/unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,107 +980,107 @@ TEST_CASE("GenericParameters", "[generic-parameters]") {
// Check that GenericParameters work as intended
auto gp = podio::GenericParameters{};

gp.set("anInt", 42);
REQUIRE(*gp.get<int>("anInt") == 42);
gp.setValue("anInt", 42);
REQUIRE(*gp.getValue<int>("anInt") == 42);
// Make sure that resetting a value with the same key works
gp.set("anInt", -42);
REQUIRE(*gp.get<int>("anInt") == -42);
gp.setValue("anInt", -42);
REQUIRE(*gp.getValue<int>("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<std::string>("aString") == "const char initialized");
gp.setValue("aString", "const char initialized");
REQUIRE(*gp.getValue<std::string>("aString") == "const char initialized");

gp.set("aStringVec", {"init", "from", "const", "chars"});
const auto stringVec = gp.get<std::vector<std::string>>("aStringVec").value();
gp.setValue("aStringVec", {"init", "from", "const", "chars"});
const auto stringVec = gp.getValue<std::vector<std::string>>("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>("double") == 1.234);
const auto storedDoubles = gp.get<std::vector<double>>("manyDoubles").value();
gp.setValue("double", 1.234);
gp.setValue("manyDoubles", {1.23, 4.56, 7.89});
REQUIRE(gp.getValue<double>("double") == 1.234);
const auto storedDoubles = gp.getValue<std::vector<double>>("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<std::vector<int>>("manyInts").value();
gp.setValue("manyInts", {1, 2, 3, 4});
const auto ints = gp.getValue<std::vector<int>>("manyInts").value();
REQUIRE(ints.size() == 4);
for (int i = 0; i < 4; ++i) {
REQUIRE(ints[i] == i + 1);
}

auto floats = std::vector<float>{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<std::vector<float>>("someFloats").value();
const auto storedFloats = gp.getValue<std::vector<float>>("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<float>("someFloats") == 12.34f);
gp.setValue("someFloats", 12.34f);
REQUIRE(*gp.getValue<float>("someFloats") == 12.34f);

// Missing values return an empty optional
REQUIRE_FALSE(gp.get<int>("Missing"));
REQUIRE_FALSE(gp.get<float>("Missing"));
REQUIRE_FALSE(gp.get<std::string>("Missing"));
REQUIRE_FALSE(gp.getValue<int>("Missing"));
REQUIRE_FALSE(gp.getValue<float>("Missing"));
REQUIRE_FALSE(gp.getValue<std::string>("Missing"));

// Same for vectors
REQUIRE_FALSE(gp.get<std::vector<int>>("Missing"));
REQUIRE_FALSE(gp.get<std::vector<float>>("Missing"));
REQUIRE_FALSE(gp.get<std::vector<std::string>>("Missing"));
REQUIRE_FALSE(gp.getValue<std::vector<int>>("Missing"));
REQUIRE_FALSE(gp.getValue<std::vector<float>>("Missing"));
REQUIRE_FALSE(gp.getValue<std::vector<std::string>>("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>("int") == 42);
REQUIRE(copiedParams.get<std::vector<int>>("ints").value()[1] == 2);
REQUIRE(*copiedParams.get<float>("float") == 3.14f);
REQUIRE(*copiedParams.get<double>("double") == 2 * 3.14);
REQUIRE(copiedParams.get<std::vector<std::string>>("strings").value()[0] == "one");
REQUIRE(*copiedParams.getValue<int>("int") == 42);
REQUIRE(copiedParams.getValue<std::vector<int>>("ints").value()[1] == 2);
REQUIRE(*copiedParams.getValue<float>("float") == 3.14f);
REQUIRE(*copiedParams.getValue<double>("double") == 2 * 3.14);
REQUIRE(copiedParams.getValue<std::vector<std::string>>("strings").value()[0] == "one");

// Make sure these are truly independent copies now
copiedParams.set("anotherDouble", 1.2345);
REQUIRE_FALSE(originalParams.get<double>("anotherDouble"));
copiedParams.setValue("anotherDouble", 1.2345);
REQUIRE_FALSE(originalParams.getValue<double>("anotherDouble"));
}

SECTION("Move constructor") {
auto copiedParams = std::move(originalParams);
REQUIRE(copiedParams.get<int>("int") == 42);
REQUIRE(copiedParams.get<std::vector<int>>("ints").value()[1] == 2);
REQUIRE(copiedParams.get<float>("float") == 3.14f);
REQUIRE(copiedParams.get<double>("double") == 2 * 3.14);
REQUIRE(copiedParams.get<std::vector<std::string>>("strings").value()[0] == "one");
REQUIRE(copiedParams.getValue<int>("int") == 42);
REQUIRE(copiedParams.getValue<std::vector<int>>("ints").value()[1] == 2);
REQUIRE(copiedParams.getValue<float>("float") == 3.14f);
REQUIRE(copiedParams.getValue<double>("double") == 2 * 3.14);
REQUIRE(copiedParams.getValue<std::vector<std::string>>("strings").value()[0] == "one");
}

SECTION("Move assignment") {
auto copiedParams = podio::GenericParameters{};
copiedParams = std::move(originalParams);
REQUIRE(copiedParams.get<int>("int") == 42);
REQUIRE(copiedParams.get<std::vector<int>>("ints").value()[1] == 2);
REQUIRE(copiedParams.get<float>("float") == 3.14f);
REQUIRE(copiedParams.get<double>("double") == 2 * 3.14);
REQUIRE(copiedParams.get<std::vector<std::string>>("strings").value()[0] == "one");
REQUIRE(copiedParams.getValue<int>("int") == 42);
REQUIRE(copiedParams.getValue<std::vector<int>>("ints").value()[1] == 2);
REQUIRE(copiedParams.getValue<float>("float") == 3.14f);
REQUIRE(copiedParams.getValue<double>("double") == 2 * 3.14);
REQUIRE(copiedParams.getValue<std::vector<std::string>>("strings").value()[0] == "one");
}
}

Expand Down

0 comments on commit 5e95c36

Please sign in to comment.