Skip to content

Commit

Permalink
Merge pull request #191 from JeffersonLab/davidl_StringParameters
Browse files Browse the repository at this point in the history
Skip parsing from std::string type
  • Loading branch information
faustus123 authored Feb 16, 2023
2 parents b74abf7 + ff0f162 commit 5d2f85e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/libraries/JANA/Services/JParameterManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ inline T JParameterManager::RegisterParameter(std::string name, const T default_


/// @brief Logic for parsing different types in a generic way
/// @throws JException in case parsing fails.
template <typename T>
inline T JParameterManager::Parse(const std::string& value) {
std::stringstream ss(value);
Expand All @@ -301,6 +300,12 @@ inline T JParameterManager::Parse(const std::string& value) {
return val;
}

/// @brief Specialization for handling strings that don't need parsing
template <>
inline std::string JParameterManager::Parse(const std::string& value) {
return std::string(value);
}

/// @brief Specialization for bool
template <>
inline bool JParameterManager::Parse(const std::string& value) {
Expand Down
20 changes: 20 additions & 0 deletions src/programs/tests/JParameterManagerTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,26 @@ TEST_CASE("JParameterManager::SetDefaultParameter") {
jpm.SetDefaultParameter("testing:dummy_var_2", zz);
REQUIRE(zz == 77);
}

SECTION("Multiple calls to check strings with spaces") {

// basic string test
std::string x = "MyStringValue";
jpm.SetDefaultParameter("testing:dummy_var", x);
REQUIRE(x == "MyStringValue");

// string with spaces
std::string y = "My String Value With Spaces";
auto p = jpm.SetDefaultParameter("testing:dummy_var2", y);
REQUIRE(p->GetValue() == "My String Value With Spaces");

// Stringify returns identical string
REQUIRE( jpm.Stringify("My String Value With Spaces") == "My String Value With Spaces" );

// Parse returns identical string
std::string z = "My String Value With Spaces";
REQUIRE( jpm.Parse<std::string>(z) == "My String Value With Spaces" );
}
}


Expand Down

0 comments on commit 5d2f85e

Please sign in to comment.