Skip to content

Commit

Permalink
Merge branch 'main' into feature/binary_service
Browse files Browse the repository at this point in the history
  • Loading branch information
floriantschopp authored Apr 3, 2024
2 parents 96825f8 + a73b556 commit f9b4184
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 31 deletions.
49 changes: 24 additions & 25 deletions modules/cli/include/hephaestus/cli/program_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ class ProgramDescription {
public:
/// @brief Creates object
/// @param brief A brief text describing the program
constexpr explicit ProgramDescription(std::string brief);
explicit ProgramDescription(std::string brief);

/// @brief Defines a required option (--key=value) on the command line
/// @tparam T Value type
/// @param key Key of the key-value pair
/// @param description A brief text describing the option
/// @return Reference to the object. Enables daisy-chained calls
template <StringStreamable T>
constexpr auto defineOption(const std::string& key, const std::string& description) -> ProgramDescription&;
auto defineOption(const std::string& key, const std::string& description) -> ProgramDescription&;

/// @brief Defines a required option (--key=value) on the command line
/// @tparam T Value type
Expand All @@ -86,8 +86,8 @@ class ProgramDescription {
/// @param description A brief text describing the option
/// @return Reference to the object. Enables daisy-chained calls
template <StringStreamable T>
constexpr auto defineOption(const std::string& key, char short_key,
const std::string& description) -> ProgramDescription&;
auto defineOption(const std::string& key, char short_key,
const std::string& description) -> ProgramDescription&;

/// @brief Defines a command line option (--key=value) that is optional
/// @tparam T Value type
Expand All @@ -96,8 +96,8 @@ class ProgramDescription {
/// @param default_value Default value to use if the option is not specified on the command line
/// @return Reference to the object. Enables daisy-chained calls
template <StringStreamable T>
constexpr auto defineOption(const std::string& key, const std::string& description,
const T& default_value) -> ProgramDescription&;
auto defineOption(const std::string& key, const std::string& description,
const T& default_value) -> ProgramDescription&;

/// @brief Defines a command line option (--key=value) that is optional
/// @tparam T Value type
Expand All @@ -107,24 +107,24 @@ class ProgramDescription {
/// @param default_value Default value to use if the option is not specified on the command line
/// @return Reference to the object. Enables daisy-chained calls
template <StringStreamable T>
constexpr auto defineOption(const std::string& key, char short_key, const std::string& description,
const T& default_value) -> ProgramDescription&;
auto defineOption(const std::string& key, char short_key, const std::string& description,
const T& default_value) -> ProgramDescription&;

/// @brief Defines a boolean option (flag) (--key=value) on the command line. If the flag is
/// passed the value of the option is true, false otherwise.
/// @param key Key of the key-value pair
/// @param short_key Single char (can be used as alias for --key)
/// @param description A brief text describing the option
/// @return Reference to the object. Enables daisy-chained calls
constexpr auto defineFlag(const std::string& key, char short_key,
const std::string& description) -> ProgramDescription&;
auto defineFlag(const std::string& key, char short_key,
const std::string& description) -> ProgramDescription&;

/// @brief Defines a boolean option (flag) (--key=value) on the command line. If the flag is
/// passed the value of the option is true, false otherwise.
/// @param key Key of the key-value pair
/// @param description A brief text describing the option
/// @return Reference to the object. Enables daisy-chained calls
constexpr auto defineFlag(const std::string& key, const std::string& description) -> ProgramDescription&;
auto defineFlag(const std::string& key, const std::string& description) -> ProgramDescription&;

/// @brief Builds the container to parse command line options.
/// @note: The resources in this object is moved into the returned object, making this object
Expand Down Expand Up @@ -155,7 +155,7 @@ class ProgramDescription {
std::vector<ProgramOptions::Option> options_;
};

constexpr ProgramDescription::ProgramDescription(std::string brief) : brief_(std::move(brief)) {
ProgramDescription::ProgramDescription(std::string brief) : brief_(std::move(brief)) {
options_.emplace_back(HELP_KEY, HELP_SHORT_KEY, "", utils::getTypeName<std::string>(), "", false, false);
}

Expand All @@ -177,47 +177,46 @@ void ProgramDescription::checkOptionAlreadyExists(const std::string& key, char k
}

template <StringStreamable T>
constexpr auto ProgramDescription::defineOption(const std::string& key,
const std::string& description) -> ProgramDescription& {
auto ProgramDescription::defineOption(const std::string& key,
const std::string& description) -> ProgramDescription& {
return defineOption<T>(key, '\0', description);
}

template <StringStreamable T>
constexpr auto ProgramDescription::defineOption(const std::string& key, char short_key,
const std::string& description) -> ProgramDescription& {
auto ProgramDescription::defineOption(const std::string& key, char short_key,
const std::string& description) -> ProgramDescription& {
checkOptionAlreadyExists(key, short_key);

options_.emplace_back(key, short_key, description, utils::getTypeName<T>(), "", true, false);
return *this;
}

template <StringStreamable T>
constexpr auto ProgramDescription::defineOption(const std::string& key, const std::string& description,
const T& default_value) -> ProgramDescription& {
auto ProgramDescription::defineOption(const std::string& key, const std::string& description,
const T& default_value) -> ProgramDescription& {
return defineOption<T>(key, '\0', description, default_value);
}

template <StringStreamable T>
constexpr auto ProgramDescription::defineOption(const std::string& key, char short_key,
const std::string& description,
const T& default_value) -> ProgramDescription& {
auto ProgramDescription::defineOption(const std::string& key, char short_key, const std::string& description,
const T& default_value) -> ProgramDescription& {
checkOptionAlreadyExists(key, short_key);

options_.emplace_back(key, short_key, description, utils::getTypeName<T>(),
fmt::format("{}", default_value), false, false);
return *this;
}

constexpr auto ProgramDescription::defineFlag(const std::string& key, char short_key,
const std::string& description) -> ProgramDescription& {
auto ProgramDescription::defineFlag(const std::string& key, char short_key,
const std::string& description) -> ProgramDescription& {
checkOptionAlreadyExists(key, short_key);

options_.emplace_back(key, short_key, description, utils::getTypeName<bool>(), "false", false, false);
return *this;
}

constexpr auto ProgramDescription::defineFlag(const std::string& key,
const std::string& description) -> ProgramDescription& {
auto ProgramDescription::defineFlag(const std::string& key,
const std::string& description) -> ProgramDescription& {
return defineFlag(key, '\0', description);
}

Expand Down
2 changes: 1 addition & 1 deletion modules/ipc/include/hephaestus/ipc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct MessageMetadata {
std::size_t sequence_id{};
};

[[nodiscard]] constexpr auto getTypeInfoServiceTopic(const std::string& topic) -> std::string {
[[nodiscard]] static inline auto getTypeInfoServiceTopic(const std::string& topic) -> std::string {
return fmt::format("type_info/{}", topic);
}

Expand Down
5 changes: 4 additions & 1 deletion modules/ipc/include/hephaestus/ipc/zenoh/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#pragma once

#include <chrono>
#include <expected>
#include <numeric>
#include <span>

Expand Down Expand Up @@ -49,6 +48,8 @@ constexpr auto toString(const Mode& mode) -> std::string_view {
case Mode::CLIENT:
return "Client";
}

__builtin_unreachable(); // TODO(C++23): replace with std::unreachable.
}

constexpr auto toMode(const zenohc::WhatAmI& me) -> Mode {
Expand All @@ -60,6 +61,8 @@ constexpr auto toMode(const zenohc::WhatAmI& me) -> Mode {
case zenohc::WhatAmI::Z_WHATAMI_CLIENT:
return Mode::CLIENT;
}

__builtin_unreachable(); // TODO(C++23): replace with std::unreachable.
}

inline auto toStringVector(const zenohc::StrArrayView& arr) -> std::vector<std::string> {
Expand Down
2 changes: 2 additions & 0 deletions modules/ipc/src/zenoh/liveliness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace {
case Z_SAMPLE_KIND_DELETE:
return PublisherStatus::DROPPED;
}

__builtin_unreachable(); // TODO(C++23): replace with std::unreachable() in C++23
}
} // namespace

Expand Down
4 changes: 2 additions & 2 deletions modules/ipc/src/zenoh/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ auto query(zenohc::Session& session, const std::string& topic,
}

const auto sample = std::get<zenohc::Sample>(r);
auto topic = std::string{ sample.get_keyexpr().as_string_view() };
auto reply_topic = std::string{ sample.get_keyexpr().as_string_view() };
auto result = std::string{ sample.get_payload().as_string_view() };

std::unique_lock<std::mutex> lock(mutex);
results.emplace_back(std::move(topic), std::move(result));
results.emplace_back(std::move(reply_topic), std::move(result));
};

auto on_done = [&sync_point] { sync_point.arrive_and_drop(); };
Expand Down
4 changes: 2 additions & 2 deletions modules/serdes/include/hephaestus/serdes/serdes.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ auto serialize(const T& data) -> std::vector<std::byte> {
if constexpr (ProtobufSerializable<T>) {
return protobuf::serialize(data);
} else {
static_assert(false, "no serialization supported");
static_assert(ProtobufSerializable<T>, "no serialization supported");
}
}

Expand All @@ -40,7 +40,7 @@ auto getSerializedTypeInfo() -> TypeInfo {
if constexpr (ProtobufSerializable<T>) {
return protobuf::getTypeInfo<T>();
} else {
static_assert(false, "no serialization supported");
static_assert(ProtobufSerializable<T>, "no serialization supported");
}
}

Expand Down
3 changes: 3 additions & 0 deletions modules/serdes/src/dynamic_deserializer.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

//=================================================================================================
// Copyright (C) 2023-2024 HEPHAESTUS Contributors
//=================================================================================================
Expand Down Expand Up @@ -30,5 +31,7 @@ auto DynamicDeserializer::toJson(const std::string& type, std::span<const std::b
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
return std::string{ reinterpret_cast<const char*>(data.data()), data.size() };
}

__builtin_unreachable(); // TODO(C++23): replace with std::unreachable() in C++23
}
} // namespace heph::serdes

0 comments on commit f9b4184

Please sign in to comment.