Skip to content

Commit

Permalink
Move toString into utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
lhruby committed Sep 27, 2024
1 parent c641e58 commit a31cf01
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions modules/ipc/apps/zenoh_topic_echo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
#include "hephaestus/ipc/zenoh/session.h"
#include "hephaestus/serdes/dynamic_deserializer.h"
#include "hephaestus/serdes/type_info.h"
#include "hephaestus/types/type_formatting.h"
#include "hephaestus/utils/exception.h"
#include "hephaestus/utils/signal_handler.h"
#include "hephaestus/utils/stack_trace.h"
#include "hephaestus/utils/string/type_formatting.h"

namespace {
constexpr auto DEFAULT_MAX_ARRAY_LENGTH = 100;
Expand Down Expand Up @@ -95,7 +95,7 @@ class TopicEcho {
truncateLongItems(msg_json, noarr_, max_array_length_);
fmt::println("From: {}. Topic: {}\nSequence: {} | Timestamp: {}\n{}", metadata.sender_id, metadata.topic,
metadata.sequence_id,
types::toString(std::chrono::time_point<std::chrono::system_clock>(
utils::string::toString(std::chrono::time_point<std::chrono::system_clock>(
std::chrono::duration_cast<std::chrono::system_clock::duration>(metadata.timestamp))),
msg_json);
}
Expand Down
2 changes: 2 additions & 0 deletions modules/serdes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set(SOURCES
src/serdes.cpp
src/type_info.cpp
src/dynamic_deserializer.cpp
src/protobuf/buffers.cpp
src/protobuf/dynamic_deserializer.cpp
src/protobuf/buffers.cpp
src/protobuf/protobuf.cpp
Expand All @@ -27,6 +28,7 @@ set(SOURCES
include/hephaestus/serdes/dynamic_deserializer.h
include/hephaestus/serdes/serdes.h
include/hephaestus/serdes/type_info.h
include/hephaestus/serdes/protobuf/buffers.h
include/hephaestus/serdes/protobuf/concepts.h
include/hephaestus/serdes/protobuf/buffers.h
include/hephaestus/serdes/protobuf/dynamic_deserializer.h
Expand Down
10 changes: 2 additions & 8 deletions modules/types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ find_package(magic_enum REQUIRED)
find_package(range-v3 REQUIRED)

# library sources
set(SOURCES
src/bounds.cpp
src/dummy_type.cpp
src/type_formatting.cpp
README.md
include/hephaestus/types/bounds.h
include/hephaestus/types/dummy_type.h
include/hephaestus/types/type_formatting.h
set(SOURCES src/bounds.cpp src/dummy_type.cpp README.md include/hephaestus/types/bounds.h
include/hephaestus/types/dummy_type.h
)

# library target
Expand Down
7 changes: 3 additions & 4 deletions modules/types/src/dummy_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <magic_enum.hpp>

#include "hephaestus/random/random_object_creator.h"
#include "hephaestus/types/type_formatting.h"
#include "hephaestus/utils/string/type_formatting.h"

namespace heph::types {

Expand Down Expand Up @@ -54,12 +54,11 @@ auto DummyType::random(std::mt19937_64& mt) -> DummyType {
}

auto operator<<(std::ostream& os, const DummyType& dummy_type) -> std::ostream& {
return os << "DummyType{"
<< "\n"
return os << "DummyType{\n"
<< " dummy_primitives_type={" << dummy_type.dummy_primitives_type << "}\n"
<< " dummy_enum=" << magic_enum::enum_name(dummy_type.dummy_enum) << "\n"
<< " dummy_string=" << dummy_type.dummy_string << "\n"
<< " dummy_vector=" << toString(dummy_type.dummy_vector) << "\n"
<< " dummy_vector=" << utils::string::toString(dummy_type.dummy_vector) << "\n"
<< "}";
}

Expand Down
5 changes: 0 additions & 5 deletions modules/types/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,3 @@ define_module_test(
NAME tests
SOURCES tests.cpp
)

define_module_test(
NAME type_formatting_tests
SOURCES type_formatting_tests.cpp
)
2 changes: 2 additions & 0 deletions modules/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(SOURCES
src/filesystem/scoped_path.cpp
src/string/string_literal.cpp
src/string/string_utils.cpp
src/string/type_formatting.cpp
src/timing/watchdog.cpp
src/bit_flag.cpp
src/concepts.cpp
Expand All @@ -35,6 +36,7 @@ set(SOURCES
include/hephaestus/utils/filesystem/scoped_path.h
include/hephaestus/utils/string/string_literal.h
include/hephaestus/utils/string/string_utils.h
include/hephaestus/utils/string/type_formatting.h
include/hephaestus/utils/timing/watchdog.h
include/hephaestus/utils/bit_flag.h
include/hephaestus/utils/concepts.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include "hephaestus/utils/concepts.h"

namespace heph::types {
namespace heph::utils::string {

//=================================================================================================
// Array and Vector
Expand Down Expand Up @@ -46,7 +46,8 @@ template <UnorderedMapType T>
std::stringstream ss;

for (const auto& [key, value] : umap) {
ss << " Key: " << key << ", Value: " << value << '\n';
const std::string str = fmt::format(" Key: {}, Value: {}\n", key, value);
ss << str;
}

return ss.str();
Expand Down Expand Up @@ -86,4 +87,4 @@ template <ChronoSteadyClockType T>
return fmt::format("{}d {:02}h:{:02}m:{:02}.{:09}s", days, hours, minutes, seconds, sub_seconds * SCALER);
}

}; // namespace heph::types
}; // namespace heph::utils::string
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// Copyright (C) 2023-2024 HEPHAESTUS Contributors
//=================================================================================================

#include "hephaestus/types/type_formatting.h" // NOLINT(misc-include-cleaner)
#include "hephaestus/utils/string/type_formatting.h" // NOLINT(misc-include-cleaner)
11 changes: 9 additions & 2 deletions modules/utils/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
# Copyright (C) 2023-2024 HEPHAESTUS Contributors
# =================================================================================================

define_module_test(
NAME bit_flag_tests
SOURCES bit_flag_tests.cpp
PUBLIC_INCLUDE_PATHS $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
PUBLIC_LINK_LIBS ""
)

define_module_test(
NAME concepts_tests
SOURCES concepts_tests.cpp
Expand Down Expand Up @@ -38,8 +45,8 @@ define_module_test(
)

define_module_test(
NAME bit_flag_tests
SOURCES bit_flag_tests.cpp
NAME type_formatting_tests
SOURCES type_formatting_tests.cpp
PUBLIC_INCLUDE_PATHS $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
PUBLIC_LINK_LIBS ""
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#include <fmt/core.h>
#include <gtest/gtest.h>

#include "hephaestus/types/type_formatting.h"
#include "hephaestus/utils/string/type_formatting.h"

using namespace ::testing; // NOLINT(google-build-using-namespace)

namespace heph::types::tests {
namespace heph::utils::string::tests {

//=================================================================================================
// Array
Expand Down Expand Up @@ -175,4 +175,4 @@ TEST(TypeFormattingTests, ChronoTimestampFormattingSystemClock) {
ASSERT_EQ(str[19], '.');
}

} // namespace heph::types::tests
} // namespace heph::utils::string::tests

0 comments on commit a31cf01

Please sign in to comment.