From ea7cc9db8c91bbe4fb2c156df491995d994cdbd0 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Fri, 15 May 2020 10:52:23 +0200 Subject: [PATCH] less public headers --- CMakeLists.txt | 1 + slsDetectorSoftware/include/Result.h | 1 - slsDetectorSoftware/include/detectorData.h | 5 ++- slsSupportLib/CMakeLists.txt | 26 ++++++++----- slsSupportLib/include/StaticVector.h | 44 ++++------------------ slsSupportLib/include/ToString.h | 7 +--- slsSupportLib/include/sls_detector_funcs.h | 7 ++-- slsSupportLib/include/string_utils.h | 26 +------------ slsSupportLib/src/string_utils.cpp | 33 ---------------- slsSupportLib/tests/test-StaticVector.cpp | 18 +++++++++ slsSupportLib/tests/test-ToString.cpp | 16 -------- slsSupportLib/tests/test-string_utils.cpp | 35 ----------------- 12 files changed, 52 insertions(+), 167 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e19bf60d3..09a649b92 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ option(SLS_USE_CTBGUI "ctb GUI" OFF) option(SLS_BUILD_DOCS "docs" OFF) option(SLS_BUILD_EXAMPLES "examples" OFF) option(SLS_TUNE_LOCAL "tune to local machine" OFF) +option(SLS_DEVEL_HEADERS "install headers for devel" OFF) # set(ClangFormat_BIN_NAME clang-format) set(ClangFormat_EXCLUDE_PATTERNS "build/" diff --git a/slsDetectorSoftware/include/Result.h b/slsDetectorSoftware/include/Result.h index 08386677c..cb5724334 100644 --- a/slsDetectorSoftware/include/Result.h +++ b/slsDetectorSoftware/include/Result.h @@ -13,7 +13,6 @@ #include #include -#include "TimeHelper.h" #include "ToString.h" #include "container_utils.h" diff --git a/slsDetectorSoftware/include/detectorData.h b/slsDetectorSoftware/include/detectorData.h index 56b63ac72..777debb5f 100644 --- a/slsDetectorSoftware/include/detectorData.h +++ b/slsDetectorSoftware/include/detectorData.h @@ -1,6 +1,7 @@ -#include -#include #pragma once +#include +#include + /** @short data structure to hold the detector data after postprocessing */ diff --git a/slsSupportLib/CMakeLists.txt b/slsSupportLib/CMakeLists.txt index 74b282708..10e1cb626 100755 --- a/slsSupportLib/CMakeLists.txt +++ b/slsSupportLib/CMakeLists.txt @@ -18,24 +18,30 @@ set(HEADERS set(PUBLICHEADERS include/sls_detector_defs.h include/sls_detector_funcs.h - include/versionAPI.h include/sls_detector_exceptions.h - include/file_utils.h include/container_utils.h include/string_utils.h - include/ClientSocket.h - include/DataSocket.h - include/ServerSocket.h - include/ServerInterface.h include/network_utils.h - include/StaticVector.h include/ToString.h - include/TimeHelper.h include/TypeTraits.h - include/Timer.h - include/UdpRxSocket.h + include/TimeHelper.h ) +if(SLS_DEVEL_HEADERS) + set(PUBLICHEADERS + ${PUBLICHEADERS} + include/file_utils.h + include/ClientSocket.h + include/DataSocket.h + include/ServerSocket.h + include/ServerInterface.h + include/Timer.h + include/StaticVector.h + include/UdpRxSocket.h + include/versionAPI.h + ) +endif() + add_library(slsSupportLib SHARED ${SOURCES} ${HEADERS} diff --git a/slsSupportLib/include/StaticVector.h b/slsSupportLib/include/StaticVector.h index ea5c027e4..1202207be 100644 --- a/slsSupportLib/include/StaticVector.h +++ b/slsSupportLib/include/StaticVector.h @@ -1,5 +1,6 @@ #pragma once #include "TypeTraits.h" +#include "ToString.h" #include #include #include @@ -47,28 +48,6 @@ template class StaticVector { return *this; } - /** Compare StaticVector with any other container*/ - // template - // typename std::enable_if::value, bool>::type - // operator==(const V &other) const noexcept { - // if (current_size != other.size()) { - // return false; - // } else { - // for (size_t i = 0; i != current_size; ++i) { - // if (data_[i] != other[i]) { - // return false; - // } - // } - // } - // return true; - // } - - // template - // typename std::enable_if::value, bool>::type - // operator!=(const V &other) const noexcept { - // return !(*this == other); - // } - operator std::vector() { return std::vector(begin(), end()); } T &operator[](size_t i) { return data_[i]; } @@ -204,20 +183,13 @@ bool operator!=(const std::vector &lhs, return !rhs.is_equal(lhs); } -/** support flipped order compare */ -// template -// typename std::enable_if::value, bool>::type operator==( -// const C &container, -// const StaticVector &fixed_container) noexcept { -// return fixed_container.operator==(container); -// } +template +std::ostream &operator<<(std::ostream &os, + const sls::StaticVector &c) { + return os << ToString(c); +} -// /** support flipped order compare */ -// template -// typename std::enable_if::value, bool>::type operator!=( -// const C &container, -// const StaticVector &fixed_container) noexcept { -// return fixed_container.operator!=(container); -// } } // namespace sls + + diff --git a/slsSupportLib/include/ToString.h b/slsSupportLib/include/ToString.h index b066b878d..6e20f69dc 100644 --- a/slsSupportLib/include/ToString.h +++ b/slsSupportLib/include/ToString.h @@ -7,7 +7,6 @@ * */ -#include "StaticVector.h" #include "TimeHelper.h" #include "TypeTraits.h" #include "sls_detector_defs.h" @@ -40,11 +39,7 @@ std::string ToString(const defs::timingSourceType s); std::string ToString(const slsDetectorDefs::ROI &roi); std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::ROI &roi); -template -std::ostream &operator<<(std::ostream &os, - const sls::StaticVector &c) { - return os << ToString(c); -} + const std::string &ToString(const std::string &s); diff --git a/slsSupportLib/include/sls_detector_funcs.h b/slsSupportLib/include/sls_detector_funcs.h index 1eb1c8b94..fafa2fbf6 100755 --- a/slsSupportLib/include/sls_detector_funcs.h +++ b/slsSupportLib/include/sls_detector_funcs.h @@ -584,7 +584,8 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) { case NUM_REC_FUNCTIONS: return "NUM_REC_FUNCTIONS"; default: return "Unknown Function"; } -}; -#endif -// clang-format on \ No newline at end of file + // clang-format on +} + +#endif diff --git a/slsSupportLib/include/string_utils.h b/slsSupportLib/include/string_utils.h index 2cfb90768..b11877ccd 100755 --- a/slsSupportLib/include/string_utils.h +++ b/slsSupportLib/include/string_utils.h @@ -50,29 +50,5 @@ implementation should not be used in a performance critical place. */ std::vector split(const std::string &strToSplit, char delimeter); -/* -Concatenate the non empty strings in the vector using + -*/ -std::string concatenateNonEmptyStrings(const std::vector &vec); - -/* -Concatenate strings using + if the strings are different -*/ -std::string concatenateIfDifferent(const std::vector &container); - -/* -Concatenate vector of things with str method using + if the strings are -different -*/ -template -std::string concatenateIfDifferent(const std::vector &container); - -/* -Convert an ip address string to a string in hex format. (removing dots) -*/ -std::string stringIpToHex(const std::string &ip); - -// remove the end of the string starting with the first aplhabetic character -// return the end std::string RemoveUnit(std::string &str); -}; // namespace sls +} // namespace sls diff --git a/slsSupportLib/src/string_utils.cpp b/slsSupportLib/src/string_utils.cpp index 290020ca6..145f5936e 100755 --- a/slsSupportLib/src/string_utils.cpp +++ b/slsSupportLib/src/string_utils.cpp @@ -17,36 +17,6 @@ std::vector split(const std::string &strToSplit, char delimeter) { return splittedStrings; } -std::string concatenateNonEmptyStrings(const std::vector &vec) { - std::string ret; - for (const auto &s : vec) - if (!s.empty()) - ret += s + '+'; - return ret; -} - -std::string concatenateIfDifferent(const std::vector &container) { - if (allEqual(container)) { - return container.front(); - } else { - std::string result; - for (const auto &s : container) - result += s + '+'; - return result; - } -} -template -std::string concatenateIfDifferent(const std::vector &container) { - if (allEqual(container)) { - return container.front().str(); - } else { - std::string result; - for (const auto &s : container) - result += s.str() + '+'; - return result; - } -} - std::string RemoveUnit(std::string &str) { auto it = str.begin(); while (it != str.end()) { @@ -60,7 +30,4 @@ std::string RemoveUnit(std::string &str) { return unit; } -template std::string concatenateIfDifferent(const std::vector &); -template std::string concatenateIfDifferent(const std::vector &); - }; // namespace sls \ No newline at end of file diff --git a/slsSupportLib/tests/test-StaticVector.cpp b/slsSupportLib/tests/test-StaticVector.cpp index bf6bba5df..f466f6e0e 100644 --- a/slsSupportLib/tests/test-StaticVector.cpp +++ b/slsSupportLib/tests/test-StaticVector.cpp @@ -4,6 +4,7 @@ #include #include +#include using sls::StaticVector; TEST_CASE("StaticVector is a container") { @@ -313,3 +314,20 @@ SCENARIO("Converting to vector", "[support]") { } } } + +TEST_CASE("sls::StaticVector") { + sls::StaticVector vec; + vec.push_back(3); + vec.push_back(8); + REQUIRE(sls::ToString(vec) == "[3, 8]"); +} + +TEST_CASE("sls::StaticVector stream") { + sls::StaticVector vec; + vec.push_back(33); + vec.push_back(85667); + vec.push_back(2); + std::ostringstream oss; + oss << vec; + REQUIRE(oss.str() == "[33, 85667, 2]"); +} diff --git a/slsSupportLib/tests/test-ToString.cpp b/slsSupportLib/tests/test-ToString.cpp index 8ce0ddd48..70151bf73 100644 --- a/slsSupportLib/tests/test-ToString.cpp +++ b/slsSupportLib/tests/test-ToString.cpp @@ -232,19 +232,3 @@ TEST_CASE("Streaming of slsDetectorDefs::ROI") { REQUIRE(oss.str() == "[-10, 1]"); } -TEST_CASE("sls::StaticVector") { - sls::StaticVector vec; - vec.push_back(3); - vec.push_back(8); - REQUIRE(ToString(vec) == "[3, 8]"); -} - -TEST_CASE("sls::StaticVector stream") { - sls::StaticVector vec; - vec.push_back(33); - vec.push_back(85667); - vec.push_back(2); - std::ostringstream oss; - oss << vec; - REQUIRE(oss.str() == "[33, 85667, 2]"); -} \ No newline at end of file diff --git a/slsSupportLib/tests/test-string_utils.cpp b/slsSupportLib/tests/test-string_utils.cpp index 8f297e052..53edcdd77 100644 --- a/slsSupportLib/tests/test-string_utils.cpp +++ b/slsSupportLib/tests/test-string_utils.cpp @@ -30,22 +30,7 @@ TEST_CASE("copy a long string") { REQUIRE(dst[2] == '\0'); } #endif -TEST_CASE("Concat") { - std::vector v{"one", "one", "one"}; - std::vector v2{"one", "one", "one"}; - auto r = sls::concatenateIfDifferent(v); - REQUIRE(r == std::string("one")); - r.clear(); - // make sure we didn't modify the string - REQUIRE(v == v2); - - SECTION("add a different value") { - v.emplace_back("two"); - REQUIRE(v != v2); - REQUIRE(sls::concatenateIfDifferent(v) == "one+one+one+two+"); - } -} TEST_CASE("split a string with end delimiter") { std::string s("abra+kadabra+"); @@ -64,26 +49,6 @@ TEST_CASE("split a string without end delimiter") { REQUIRE(r[2] == "filibom"); } -TEST_CASE("concatenate non empty strings") { - std::vector vec{"hej", "kalas", "", "foto"}; - REQUIRE(vec.size() == 4); - auto ret = sls::concatenateNonEmptyStrings(vec); - REQUIRE(ret == "hej+kalas+foto+"); -} - -TEST_CASE("concatenate non empty strings with only emty") { - std::vector vec{"", "", ""}; - REQUIRE(vec.size() == 3); - auto ret = sls::concatenateNonEmptyStrings(vec); - REQUIRE(ret.empty()); -} - -TEST_CASE("concatenate non empty strings with one element") { - std::vector vec{"", "hej", "", "", ""}; - REQUIRE(vec.size() == 5); - auto ret = sls::concatenateNonEmptyStrings(vec); - REQUIRE(ret == "hej+"); -} TEST_CASE("Remove char from string") { char str[] = "sometest";