Skip to content

Commit 4a82879

Browse files
committed
[#301] Adjust naming for structs
1 parent b2ca3aa commit 4a82879

File tree

8 files changed

+42
-44
lines changed

8 files changed

+42
-44
lines changed

iceoryx2-bb/cxx/include/iox2/bb/into.hpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,47 @@ namespace bb {
2323

2424
/// @brief Helper struct to indicate a lossy conversion, e.g. from an unbounded type into a bounded type
2525
template <typename D>
26-
struct lossy { };
26+
struct Lossy { };
2727

2828
namespace detail {
2929
/// @brief Helper struct to get the actual destination type 'T' for 'into' with an additional indirection like
30-
/// 'into<lossy<T>>'
30+
/// 'into<Lossy<T>>'
3131
template <typename T>
32-
struct extract_into_type {
32+
struct ExtractIntoType {
3333
using TargetType = T;
3434
};
3535

36-
/// @brief Helper struct to get the actual destination type 'T' for 'into<lossy<T>>'
36+
/// @brief Helper struct to get the actual destination type 'T' for 'into<Lossy<T>>'
3737
template <typename T>
38-
struct extract_into_type<lossy<T>> {
38+
struct ExtractIntoType<Lossy<T>> {
3939
using TargetType = T;
4040
};
4141
} // namespace detail
4242

4343
// Using a struct as impl, as free functions do not support partially specialized templates
4444
template <typename SourceType, typename DestinationType>
45-
struct FromTrait {
45+
struct From {
4646
// AXIVION Next Construct AutosarC++19_03-A7.1.5 : 'auto' is only used for the generic implementation which will always result in a compile error
4747
static auto from(const SourceType& value IOX2_MAYBE_UNUSED) noexcept {
4848
static_assert(legacy::always_false_v<SourceType> && legacy::always_false_v<DestinationType>, "\n \
4949
Conversion for the specified types is not implemented!\n \
50-
Please specialize 'FromTrait::from'!\n \
50+
Please specialize 'From::from'!\n \
5151
-------------------------------------------------------------------------\n \
5252
template <typename SourceType, typename DestinationType>\n \
53-
constexpr DestinationType FromTrait::from(const SourceType&) noexcept;\n \
53+
constexpr DestinationType From::from(const SourceType&) noexcept;\n \
5454
-------------------------------------------------------------------------");
5555
}
5656
};
5757

5858
/// @brief Converts a value of type SourceType to a corresponding value of type DestinationType. This function needs to
5959
/// be specialized by the user for the types to be converted. If a partial specialization is needed, please have a look
60-
/// at 'FromTrait'.
60+
/// at 'From'.
6161
/// @note If the conversion is potentially lossy 'Destination from<Source, Destination>(...)' should not be used but
6262
/// instead either one or both of:
63-
/// - 'Destination from<Source, lossy<Destination>>(...)'
63+
/// - 'Destination from<Source, Lossy<Destination>>(...)'
6464
/// - 'optional<Destination> from<Source, optional<Destination>>(...)'
6565
/// The 'Destination from<Source, Destination>(...)' implementation should have a 'static_assert' with a hint of the
66-
/// reason, e.g. lossy conversion and a hint to use 'Destination into<lossy<Destination>>(...)' or
66+
/// reason, e.g. lossy conversion and a hint to use 'Destination into<Lossy<Destination>>(...)' or
6767
/// 'optional<Destination> into<optional<Destination>>(...)'. The 'std_string_support.hpp' can be used as a source of
6868
/// inspiration for an implementation and error message.
6969
/// @code
@@ -102,9 +102,8 @@ constexpr DestinationType FromTrait::from(const SourceType&) noexcept;\n \
102102
/// @param[in] value of type SourceType to convert to DestinationType
103103
/// @return converted value of SourceType to corresponding value of DestinationType
104104
template <typename SourceType, typename DestinationType>
105-
constexpr auto from(const SourceType value) noexcept ->
106-
typename detail::extract_into_type<DestinationType>::TargetType {
107-
return FromTrait<SourceType, DestinationType>::from(value);
105+
constexpr auto from(const SourceType value) noexcept -> typename detail::ExtractIntoType<DestinationType>::TargetType {
106+
return From<SourceType, DestinationType>::from(value);
108107
}
109108

110109
/// @brief Converts a value of type SourceType to a corresponding value of type DestinationType. This is a convenience
@@ -118,8 +117,7 @@ constexpr auto from(const SourceType value) noexcept ->
118117
/// @param[in] value of type SourceType to convert to DestinationType
119118
/// @return converted value of SourceType to corresponding value of DestinationType
120119
template <typename DestinationType, typename SourceType>
121-
constexpr auto into(const SourceType value) noexcept ->
122-
typename detail::extract_into_type<DestinationType>::TargetType {
120+
constexpr auto into(const SourceType value) noexcept -> typename detail::ExtractIntoType<DestinationType>::TargetType {
123121
return from<SourceType, DestinationType>(value);
124122
}
125123

iceoryx2-bb/cxx/include/iox2/legacy/cli/option_manager.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ inline T OptionManager::defineOption(T& referenceToMember,
5454
T defaultArgumentValue) {
5555
constexpr bool IS_NO_SWITCH = false;
5656
m_optionSet.addOption(OptionWithDetails {
57-
{ shortName, IS_NO_SWITCH, name, bb::into<bb::lossy<Argument_t>>(convert::toString(defaultArgumentValue)) },
57+
{ shortName, IS_NO_SWITCH, name, bb::into<bb::Lossy<Argument_t>>(convert::toString(defaultArgumentValue)) },
5858
description,
5959
optionType,
6060
{ TypeInfo<T>::NAME } });

iceoryx2-bb/cxx/include/iox2/legacy/detail/std_chrono_support.inl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ namespace iox2 {
2020
namespace bb {
2121

2222
inline legacy::units::Duration
23-
FromTrait<std::chrono::nanoseconds, legacy::units::Duration>::from(const std::chrono::nanoseconds& value) noexcept {
23+
From<std::chrono::nanoseconds, legacy::units::Duration>::from(const std::chrono::nanoseconds& value) noexcept {
2424
return legacy::units::Duration::fromNanoseconds(value.count());
2525
}
2626
inline legacy::units::Duration
27-
FromTrait<std::chrono::microseconds, legacy::units::Duration>::from(const std::chrono::microseconds& value) noexcept {
27+
From<std::chrono::microseconds, legacy::units::Duration>::from(const std::chrono::microseconds& value) noexcept {
2828
return legacy::units::Duration::fromMicroseconds(value.count());
2929
}
3030

3131
inline legacy::units::Duration
32-
FromTrait<std::chrono::milliseconds, legacy::units::Duration>::from(const std::chrono::milliseconds& value) noexcept {
32+
From<std::chrono::milliseconds, legacy::units::Duration>::from(const std::chrono::milliseconds& value) noexcept {
3333
return legacy::units::Duration::fromMilliseconds(value.count());
3434
}
3535

3636
inline legacy::units::Duration
37-
FromTrait<std::chrono::seconds, legacy::units::Duration>::from(const std::chrono::seconds& value) noexcept {
37+
From<std::chrono::seconds, legacy::units::Duration>::from(const std::chrono::seconds& value) noexcept {
3838
return legacy::units::Duration::fromSeconds(value.count());
3939
}
4040

iceoryx2-bb/cxx/include/iox2/legacy/detail/std_string_support.inl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@
1919
namespace iox2 {
2020
namespace bb {
2121
template <uint64_t N>
22-
inline std::string FromTrait<legacy::string<N>, std::string>::from(const legacy::string<N>& value) noexcept {
22+
inline std::string From<legacy::string<N>, std::string>::from(const legacy::string<N>& value) noexcept {
2323
return std::string(value.c_str(), static_cast<size_t>(value.size()));
2424
}
2525

2626
template <uint64_t N>
27-
inline legacy::string<N> FromTrait<std::string, legacy::string<N>>::from(const std::string&) noexcept {
27+
inline legacy::string<N> From<std::string, legacy::string<N>>::from(const std::string&) noexcept {
2828
static_assert(legacy::always_false_v<std::string> && legacy::always_false_v<legacy::string<N>>, "\n \
2929
The conversion from 'std::string' to 'iox2::legacy::string<N>' is potentially lossy!\n \
3030
This happens when the size of source string exceeds the capacity of the destination string!\n \
3131
Please use either: \n \
3232
- 'iox2::bb::into<iox2::legacy::optional<iox2::legacy::string<N>>>' which returns a 'iox2::legacy::optional<iox2::legacy::string<N>>'\n \
3333
with a 'nullopt' if the size of the source string exceeds the capacity of the destination string\n \
34-
- 'iox2::bb::into<iox2::bb::lossy<iox2::legacy::string<N>>>' which returns a 'iox2::legacy::string<N>' and truncates the\n \
34+
- 'iox2::bb::into<iox2::bb::Lossy<iox2::legacy::string<N>>>' which returns a 'iox2::legacy::string<N>' and truncates the\n \
3535
source string if its size exceeds the capacity of the destination string");
3636
}
3737

3838
template <uint64_t N>
3939
inline legacy::optional<legacy::string<N>>
40-
FromTrait<std::string, legacy::optional<legacy::string<N>>>::from(const std::string& value) noexcept {
40+
From<std::string, legacy::optional<legacy::string<N>>>::from(const std::string& value) noexcept {
4141
const auto stringLength = value.size();
4242
if (stringLength <= N) {
4343
return legacy::string<N>(legacy::TruncateToCapacity, value.c_str(), stringLength);
@@ -46,7 +46,7 @@ FromTrait<std::string, legacy::optional<legacy::string<N>>>::from(const std::str
4646
}
4747

4848
template <uint64_t N>
49-
inline legacy::string<N> FromTrait<std::string, lossy<legacy::string<N>>>::from(const std::string& value) noexcept {
49+
inline legacy::string<N> From<std::string, Lossy<legacy::string<N>>>::from(const std::string& value) noexcept {
5050
return legacy::string<N>(legacy::TruncateToCapacity, value.c_str(), value.size());
5151
}
5252
} // namespace bb

iceoryx2-bb/cxx/include/iox2/legacy/std_chrono_support.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,31 @@ namespace bb {
2525
/// @param[in] value as nanoseconds
2626
/// @attention Since negative durations are not allowed, the duration will be clamped to 0
2727
template <>
28-
struct FromTrait<std::chrono::nanoseconds, legacy::units::Duration> {
28+
struct From<std::chrono::nanoseconds, legacy::units::Duration> {
2929
static legacy::units::Duration from(const std::chrono::nanoseconds& value) noexcept;
3030
};
3131

3232
/// @brief Construct a Duration object from std::chrono::microseconds
3333
/// @param[in] value as microseconds
3434
/// @attention Since negative durations are not allowed, the duration will be clamped to 0
3535
template <>
36-
struct FromTrait<std::chrono::microseconds, legacy::units::Duration> {
36+
struct From<std::chrono::microseconds, legacy::units::Duration> {
3737
static legacy::units::Duration from(const std::chrono::microseconds& value) noexcept;
3838
};
3939

4040
/// @brief Construct a Duration object from std::chrono::milliseconds
4141
/// @param[in] value as milliseconds
4242
/// @attention Since negative durations are not allowed, the duration will be clamped to 0
4343
template <>
44-
struct FromTrait<std::chrono::milliseconds, legacy::units::Duration> {
44+
struct From<std::chrono::milliseconds, legacy::units::Duration> {
4545
static legacy::units::Duration from(const std::chrono::milliseconds& value) noexcept;
4646
};
4747

4848
/// @brief Construct a Duration object from std::chrono::seconds
4949
/// @param[in] value as seconds
5050
/// @attention Since negative durations are not allowed, the duration will be clamped to 0
5151
template <>
52-
struct FromTrait<std::chrono::seconds, legacy::units::Duration> {
52+
struct From<std::chrono::seconds, legacy::units::Duration> {
5353
static legacy::units::Duration from(const std::chrono::seconds& value) noexcept;
5454
};
5555
} // namespace bb

iceoryx2-bb/cxx/include/iox2/legacy/std_string_support.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ namespace iox2 {
2727

2828
namespace bb {
2929
template <uint64_t N>
30-
struct FromTrait<legacy::string<N>, std::string> {
30+
struct From<legacy::string<N>, std::string> {
3131
static std::string from(const legacy::string<N>& value) noexcept;
3232
};
3333

3434
template <uint64_t N>
35-
struct FromTrait<std::string, legacy::string<N>> {
35+
struct From<std::string, legacy::string<N>> {
3636
static legacy::string<N> from(const std::string& value) noexcept;
3737
};
3838

3939
template <uint64_t N>
40-
struct FromTrait<std::string, legacy::optional<legacy::string<N>>> {
40+
struct From<std::string, legacy::optional<legacy::string<N>>> {
4141
static legacy::optional<legacy::string<N>> from(const std::string& value) noexcept;
4242
};
4343

4444
template <uint64_t N>
45-
struct FromTrait<std::string, bb::lossy<legacy::string<N>>> {
45+
struct From<std::string, bb::Lossy<legacy::string<N>>> {
4646
static legacy::string<N> from(const std::string& value) noexcept;
4747
};
4848
} // namespace bb

iceoryx2-bb/cxx/tests/src/legacy/moduletests/test_cli_command_line_parser.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ void FailureTest(const std::vector<std::string>& options,
8989
{
9090
OptionDefinition optionSet("", [&] { wasErrorHandlerCalled = true; });
9191
for (const auto& o : optionsToRegister) {
92-
optionSet.addOptional(o[0], into<lossy<OptionName_t>>(o), "", "int", "0");
92+
optionSet.addOptional(o[0], into<Lossy<OptionName_t>>(o), "", "int", "0");
9393
}
9494
for (const auto& s : switchesToRegister) {
95-
optionSet.addSwitch(s[0], into<lossy<OptionName_t>>(s), "");
95+
optionSet.addSwitch(s[0], into<Lossy<OptionName_t>>(s), "");
9696
}
9797
for (const auto& r : requiredValuesToRegister) {
98-
optionSet.addRequired(r[0], into<lossy<OptionName_t>>(r), "", "int");
98+
optionSet.addRequired(r[0], into<Lossy<OptionName_t>>(r), "", "int");
9999
}
100100

101101
IOX2_DISCARD_RESULT(parseCommandLineArguments(optionSet, args.argc, args.argv, 1U));
@@ -834,13 +834,13 @@ Arguments SuccessTest(const std::vector<std::string>& options,
834834
{
835835
OptionDefinition optionSet("");
836836
for (const auto& o : optionsToRegister) {
837-
optionSet.addOptional(o[0], into<lossy<OptionName_t>>(o), "", "int", CommandLineParser_test::defaultValue);
837+
optionSet.addOptional(o[0], into<Lossy<OptionName_t>>(o), "", "int", CommandLineParser_test::defaultValue);
838838
}
839839
for (const auto& s : switchesToRegister) {
840-
optionSet.addSwitch(s[0], into<lossy<OptionName_t>>(s), "");
840+
optionSet.addSwitch(s[0], into<Lossy<OptionName_t>>(s), "");
841841
}
842842
for (const auto& r : requiredValuesToRegister) {
843-
optionSet.addRequired(r[0], into<lossy<OptionName_t>>(r), "", "int");
843+
optionSet.addRequired(r[0], into<Lossy<OptionName_t>>(r), "", "int");
844844
}
845845

846846
{

iceoryx2-bb/cxx/tests/src/legacy/moduletests/test_utility_std_string_support.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ TYPED_TEST(StdString_test, STDStringToLossyStringConvConstrWithSize0ResultsInSiz
4040
using MyString = typename TestFixture::stringType;
4141
constexpr auto STRINGCAP = MyString::capacity();
4242
std::string testString;
43-
string<STRINGCAP> fuu = into<lossy<MyString>>(testString);
43+
string<STRINGCAP> fuu = into<Lossy<MyString>>(testString);
4444
EXPECT_THAT(fuu.capacity(), Eq(STRINGCAP));
4545
EXPECT_THAT(fuu.size(), Eq(0U));
4646
EXPECT_THAT(fuu.c_str(), StrEq(""));
@@ -51,7 +51,7 @@ TYPED_TEST(StdString_test, STDStringToLossyStringConvConstrWithSizeSmallerCapaRe
5151
using MyString = typename TestFixture::stringType;
5252
constexpr auto STRINGCAP = MyString::capacity();
5353
std::string testString(STRINGCAP - 1U, 'M');
54-
string<STRINGCAP> fuu = into<lossy<MyString>>(testString);
54+
string<STRINGCAP> fuu = into<Lossy<MyString>>(testString);
5555
EXPECT_THAT(fuu.capacity(), Eq(STRINGCAP));
5656
EXPECT_THAT(fuu.size(), Eq(STRINGCAP - 1U));
5757
EXPECT_THAT(fuu.c_str(), Eq(testString));
@@ -62,7 +62,7 @@ TYPED_TEST(StdString_test, STDStringToLossyStringConvConstrWithSizeCapaResultsIn
6262
using MyString = typename TestFixture::stringType;
6363
constexpr auto STRINGCAP = MyString::capacity();
6464
std::string testString(STRINGCAP, 'M');
65-
string<STRINGCAP> fuu = into<lossy<MyString>>(testString);
65+
string<STRINGCAP> fuu = into<Lossy<MyString>>(testString);
6666
EXPECT_THAT(fuu.capacity(), Eq(STRINGCAP));
6767
EXPECT_THAT(fuu.size(), Eq(STRINGCAP));
6868
EXPECT_THAT(fuu.c_str(), Eq(testString));
@@ -73,7 +73,7 @@ TYPED_TEST(StdString_test, STDStringToLossyStringConvConstrWithSizeGreaterCapaRe
7373
using MyString = typename TestFixture::stringType;
7474
constexpr auto STRINGCAP = MyString::capacity();
7575
std::string testString(STRINGCAP + 1U, 'M');
76-
string<STRINGCAP> fuu = into<lossy<MyString>>(testString);
76+
string<STRINGCAP> fuu = into<Lossy<MyString>>(testString);
7777
EXPECT_THAT(fuu.capacity(), Eq(STRINGCAP));
7878
EXPECT_THAT(fuu.size(), Eq(STRINGCAP));
7979
EXPECT_THAT(fuu.c_str(), Eq(testString.substr(0U, STRINGCAP)));

0 commit comments

Comments
 (0)