Skip to content

Commit

Permalink
Merge pull request #2407 from elBoberido/iox-846-reduce-undefs-in-pla…
Browse files Browse the repository at this point in the history
…tform-correction-header

iox-#846 Reduce undefs in platform correction header
  • Loading branch information
elBoberido authored Jan 10, 2025
2 parents 8d4afc5 + 34f7c36 commit 6794c8e
Show file tree
Hide file tree
Showing 57 changed files with 370 additions and 379 deletions.
2 changes: 1 addition & 1 deletion doc/website/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ SharedMemory still there, doing an unlink of /root
Reserving 27902400 bytes in the shared memory [/root]
While setting the acquired shared memory to zero a fatal SIGBUS signal appeared
caused by memset. The shared memory object with the following properties
[ name = /root, sizeInBytes = 27902400, access mode = AccessMode::READ_WRITE,
[ name = /root, sizeInBytes = 27902400, access mode = AccessMode::ReadWrite,
ownership = OwnerShip::MINE, baseAddressHint = (nil), permissions = 0 ] maybe
requires more memory than it is currently available in the system.
```
Expand Down
2 changes: 1 addition & 1 deletion doc/website/release-notes/iceoryx-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
iox::optional<iox::NamedSemaphore> semaphore;
auto result = iox::NamedSemaphoreBuilder()
.name("mySemaphoreName")
.openMode(iox::OpenMode::OPEN_OR_CREATE)
.openMode(iox::OpenMode::OpenOrCreate)
.permissions(iox::perms::owner_all)
.initialValue(0U)
.create(semaphore);
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/cli/include/iox/cli/option.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct OptionWithDetails : public Option // can this be melt together
struct
{
OptionDescription_t description;
OptionType type = OptionType::SWITCH;
OptionType type = OptionType::Switch;
TypeName_t typeName;
} details;
};
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/cli/include/iox/cli/option_manager.inl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ inline bool OptionManager::extractOptionArgumentValue(const Arguments& arguments
const OptionName_t& name,
const OptionType optionType)
{
if (optionType == OptionType::SWITCH)
if (optionType == OptionType::Switch)
{
return arguments.isSwitchSet(getLookupName(shortName, name));
}
Expand Down
6 changes: 3 additions & 3 deletions iceoryx_hoofs/cli/include/iox/cli/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ namespace cli
enum class OptionType : uint8_t
{
/// @brief option when provided is true
SWITCH,
Switch,
/// @brief option with value which has to be provided
REQUIRED,
Required,
/// @brief option with value which can be provided
OPTIONAL
Optional
};

static constexpr uint64_t MAX_OPTION_NAME_LENGTH = 32;
Expand Down
6 changes: 3 additions & 3 deletions iceoryx_hoofs/cli/include/iox/cli_definition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
/// @param[in] description a description of the optional value
#define IOX_CLI_OPTIONAL(type, memberName, defaultValue, shortName, longName, description) \
IOX_INTERNAL_CMD_LINE_VALUE( \
type, memberName, defaultValue, shortName, longName, description, iox::cli::OptionType::OPTIONAL)
type, memberName, defaultValue, shortName, longName, description, iox::cli::OptionType::Optional)

/// @brief Adds a required value to the command line, if it is not provided the program will print the help and
/// terminate
Expand All @@ -57,15 +57,15 @@
/// @param[in] description a description of the required value
#define IOX_CLI_REQUIRED(type, memberName, shortName, longName, description) \
IOX_INTERNAL_CMD_LINE_VALUE( \
type, memberName, type(), shortName, longName, description, iox::cli::OptionType::REQUIRED)
type, memberName, type(), shortName, longName, description, iox::cli::OptionType::Required)

/// @brief Adds a switch to the command line
/// @param[in] memberName the name under which the switch is accessible
/// @param[in] shortName a single character for the short option like '-s' for instance
/// @param[in] longName a long option name under which this can be accessed like '--some-name' for instance
/// @param[in] description a description of the switch
#define IOX_CLI_SWITCH(memberName, shortName, longName, description) \
IOX_INTERNAL_CMD_LINE_VALUE(bool, memberName, false, shortName, longName, description, iox::cli::OptionType::SWITCH)
IOX_INTERNAL_CMD_LINE_VALUE(bool, memberName, false, shortName, longName, description, iox::cli::OptionType::Switch)

/// @brief Helper macro to create a struct with full command line parsing from argc, argv.
/// @param[in] Name the name of the class/struct
Expand Down
10 changes: 5 additions & 5 deletions iceoryx_hoofs/cli/source/command_line_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ CommandLineParser::parse(const OptionDefinition& optionSet, int argc, char** arg
return m_optionValue;
}

if (optionEntry->details.type == OptionType::SWITCH)
if (optionEntry->details.type == OptionType::Switch)
{
m_optionValue.m_arguments.emplace_back(*optionEntry);
m_optionValue.m_arguments.back().value.clear();
Expand Down Expand Up @@ -271,7 +271,7 @@ void CommandLineParser::setDefaultValuesToUnsetOptions() noexcept // rename
{
for (const auto& availableOption : m_optionSet->m_availableOptions)
{
if (availableOption.details.type != OptionType::OPTIONAL)
if (availableOption.details.type != OptionType::Optional)
{
continue;
}
Expand All @@ -298,7 +298,7 @@ bool CommandLineParser::areAllRequiredValuesPresent() const noexcept
bool areAllRequiredValuesPresent = true;
for (const auto& availableOption : m_optionSet->m_availableOptions)
{
if (availableOption.details.type == OptionType::REQUIRED)
if (availableOption.details.type == OptionType::Required)
{
bool isValuePresent = false;
for (const auto& option : m_optionValue.m_arguments)
Expand Down Expand Up @@ -359,7 +359,7 @@ void CommandLineParser::printHelpAndExit() const noexcept
outLength += 2 + option.longOption.size();
}

if (option.details.type == OptionType::REQUIRED || option.details.type == OptionType::OPTIONAL)
if (option.details.type == OptionType::Required || option.details.type == OptionType::Optional)
{
std::cout << " [" << option.details.typeName << "]";
outLength += 3 + option.details.typeName.size();
Expand All @@ -373,7 +373,7 @@ void CommandLineParser::printHelpAndExit() const noexcept
}
std::cout << option.details.description << std::endl;

if (option.details.type == OptionType::OPTIONAL)
if (option.details.type == OptionType::Optional)
{
for (uint64_t i = 0; i < OPTION_OUTPUT_WIDTH; ++i)
{
Expand Down
8 changes: 4 additions & 4 deletions iceoryx_hoofs/cli/source/option_definition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ OptionDefinition::OptionDefinition(const OptionDescription_t& programDescription
, m_onFailureCallback{onFailureCallback}
{
constexpr bool IS_SWITCH = true;
std::move(*this).addOption({{'h', IS_SWITCH, {"help"}, {""}}, {"Display help."}, OptionType::SWITCH, {""}});
std::move(*this).addOption({{'h', IS_SWITCH, {"help"}, {""}}, {"Display help."}, OptionType::Switch, {""}});
}

optional<OptionWithDetails> OptionDefinition::getOption(const OptionName_t& name) const noexcept
Expand Down Expand Up @@ -100,7 +100,7 @@ OptionDefinition& OptionDefinition::addSwitch(const char shortOption,
const OptionDescription_t& description) noexcept
{
constexpr bool IS_SWITCH = true;
return addOption({{shortOption, IS_SWITCH, longOption, {""}}, description, OptionType::SWITCH, {""}});
return addOption({{shortOption, IS_SWITCH, longOption, {""}}, description, OptionType::Switch, {""}});
}

// NOLINTJUSTIFICATION this is not a user facing API but hidden in a macro
Expand All @@ -113,15 +113,15 @@ OptionDefinition& OptionDefinition::addOptional(const char shortOption,
{
constexpr bool IS_NO_SWITCH = false;
return addOption(
{{shortOption, IS_NO_SWITCH, longOption, defaultValue}, description, OptionType::OPTIONAL, typeName});
{{shortOption, IS_NO_SWITCH, longOption, defaultValue}, description, OptionType::Optional, typeName});
}
OptionDefinition& OptionDefinition::addRequired(const char shortOption,
const OptionName_t& longOption,
const OptionDescription_t& description,
const TypeName_t& typeName) noexcept
{
constexpr bool IS_NO_SWITCH = false;
return addOption({{shortOption, IS_NO_SWITCH, longOption, {""}}, description, OptionType::REQUIRED, typeName});
return addOption({{shortOption, IS_NO_SWITCH, longOption, {""}}, description, OptionType::Required, typeName});
}

std::ostream& operator<<(std::ostream& stream, const OptionWithDetails& option) noexcept
Expand Down
38 changes: 19 additions & 19 deletions iceoryx_hoofs/filesystem/include/iox/detail/filesystem.inl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ inline bool isValidPathEntry(const iox::string<StringCapacity>& name,

if ((name == currentDirectory) || (name == parentDirectory))
{
return relativePathComponents == RelativePathComponents::ACCEPT;
return relativePathComponents == RelativePathComponents::Accept;
}

const auto nameSize = name.size();
Expand Down Expand Up @@ -75,7 +75,7 @@ inline bool isValidFileName(const iox::string<StringCapacity>& name) noexcept
}

// check if the file contains only valid characters
return isValidPathEntry(name, RelativePathComponents::REJECT);
return isValidPathEntry(name, RelativePathComponents::Reject);
}

template <uint64_t StringCapacity>
Expand Down Expand Up @@ -160,7 +160,7 @@ inline bool isValidPathToDirectory(const iox::string<StringCapacity>& name) noex
}
else // we reached the last entry, if its a valid file name the path is valid
{
return isValidPathEntry(remaining, RelativePathComponents::ACCEPT);
return isValidPathEntry(remaining, RelativePathComponents::Accept);
}
}

Expand Down Expand Up @@ -191,32 +191,32 @@ inline constexpr const char* asStringLiteral(const OpenMode mode) noexcept
{
switch (mode)
{
case OpenMode::EXCLUSIVE_CREATE:
return "OpenMode::EXCLUSIVE_CREATE";
case OpenMode::PURGE_AND_CREATE:
return "OpenMode::PURGE_AND_CREATE";
case OpenMode::OPEN_OR_CREATE:
return "OpenMode::OPEN_OR_CREATE";
case OpenMode::OPEN_EXISTING:
return "OpenMode::OPEN_EXISTING";
case OpenMode::ExclusiveCreate:
return "OpenMode::ExclusiveCreate";
case OpenMode::PurgeAndCreate:
return "OpenMode::PurgeAndCreate";
case OpenMode::OpenOrCreate:
return "OpenMode::OpenOrCreate";
case OpenMode::OpenExisting:
return "OpenMode::OpenExisting";
}

return "OpenMode::UNDEFINED_VALUE";
return "OpenMode::UndefinedValue";
}

inline constexpr const char* asStringLiteral(const AccessMode mode) noexcept
{
switch (mode)
{
case AccessMode::READ_ONLY:
return "AccessMode::READ_ONLY";
case AccessMode::READ_WRITE:
return "AccessMode::READ_WRITE";
case AccessMode::WRITE_ONLY:
return "AccessMode::WRITE_ONLY";
case AccessMode::ReadOnly:
return "AccessMode::ReadOnly";
case AccessMode::ReadWrite:
return "AccessMode::ReadWrite";
case AccessMode::WriteOnly:
return "AccessMode::WriteOnly";
}

return "AccessMode::UNDEFINED_VALUE";
return "AccessMode::UndefinedValue";
}


Expand Down
18 changes: 9 additions & 9 deletions iceoryx_hoofs/filesystem/include/iox/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ constexpr char ASCII_UNDERSCORE{'_'};

enum class RelativePathComponents : uint8_t
{
REJECT,
ACCEPT
Reject,
Accept
};

/// @brief checks if the given string is a valid path entry. A path entry is the string between
Expand Down Expand Up @@ -93,22 +93,22 @@ bool doesEndWithPathSeparator(const string<StringCapacity>& name) noexcept;

enum class AccessMode : uint8_t
{
READ_ONLY = 0U,
READ_WRITE = 1U,
WRITE_ONLY = 2U
ReadOnly = 0U,
ReadWrite = 1U,
WriteOnly = 2U
};

/// @brief describes how the shared memory is opened or created
enum class OpenMode : uint8_t
{
/// @brief creates the shared memory, if it exists already the construction will fail
EXCLUSIVE_CREATE = 0U,
ExclusiveCreate = 0U,
/// @brief creates the shared memory, if it exists it will be deleted and recreated
PURGE_AND_CREATE = 1U,
PurgeAndCreate = 1U,
/// @brief creates the shared memory, if it does not exist otherwise it opens it
OPEN_OR_CREATE = 2U,
OpenOrCreate = 2U,
/// @brief opens the shared memory, if it does not exist it will fail
OPEN_EXISTING = 3U
OpenExisting = 3U
};

/// @brief converts OpenMode into a string literal
Expand Down
20 changes: 10 additions & 10 deletions iceoryx_hoofs/filesystem/source/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ int convertToOflags(const AccessMode accessMode) noexcept
{
switch (accessMode)
{
case AccessMode::READ_ONLY:
case AccessMode::ReadOnly:
return O_RDONLY;
case AccessMode::READ_WRITE:
case AccessMode::ReadWrite:
return O_RDWR;
case AccessMode::WRITE_ONLY:
case AccessMode::WriteOnly:
return O_WRONLY;
}

Expand All @@ -196,12 +196,12 @@ int convertToOflags(const OpenMode openMode) noexcept
{
switch (openMode)
{
case OpenMode::OPEN_EXISTING:
case OpenMode::OpenExisting:
return 0;
case OpenMode::OPEN_OR_CREATE:
case OpenMode::OpenOrCreate:
return O_CREAT;
case OpenMode::EXCLUSIVE_CREATE:
case OpenMode::PURGE_AND_CREATE:
case OpenMode::ExclusiveCreate:
case OpenMode::PurgeAndCreate:
// wrapped inside function so that the user does not have to use bitwise operations; operands have positive
// values and result is within integer range
// NOLINTNEXTLINE(hicpp-signed-bitwise)
Expand All @@ -216,12 +216,12 @@ int convertToProtFlags(const AccessMode accessMode) noexcept
{
switch (accessMode)
{
case AccessMode::READ_ONLY:
case AccessMode::ReadOnly:
return PROT_READ;
case AccessMode::READ_WRITE:
case AccessMode::ReadWrite:
// NOLINTNEXTLINE(hicpp-signed-bitwise) enum type is defined by POSIX, no logical fault
return PROT_READ | PROT_WRITE;
case AccessMode::WRITE_ONLY:
case AccessMode::WriteOnly:
return PROT_WRITE;
}

Expand Down
6 changes: 3 additions & 3 deletions iceoryx_hoofs/posix/filesystem/include/iox/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,16 @@ class File : public FileManagementInterface<File>
static constexpr int INVALID_FILE_DESCRIPTOR{-1};

int m_file_descriptor{INVALID_FILE_DESCRIPTOR};
AccessMode m_access_mode{AccessMode::READ_ONLY};
AccessMode m_access_mode{AccessMode::ReadOnly};
};

class FileBuilder
{
private:
IOX_BUILDER_PARAMETER(Ownership, owner, Ownership::from_process())
IOX_BUILDER_PARAMETER(access_rights, permissions, perms::owner_read)
IOX_BUILDER_PARAMETER(AccessMode, access_mode, AccessMode::READ_ONLY)
IOX_BUILDER_PARAMETER(OpenMode, open_mode, OpenMode::OPEN_EXISTING)
IOX_BUILDER_PARAMETER(AccessMode, access_mode, AccessMode::ReadOnly)
IOX_BUILDER_PARAMETER(OpenMode, open_mode, OpenMode::OpenExisting)

public:
expected<File, FileCreationError> create(const FilePath& name) noexcept;
Expand Down
10 changes: 5 additions & 5 deletions iceoryx_hoofs/posix/filesystem/source/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace iox
{
expected<File, FileCreationError> FileBuilder::create(const FilePath& name) noexcept
{
if (m_open_mode == OpenMode::PURGE_AND_CREATE)
if (m_open_mode == OpenMode::PurgeAndCreate)
{
if (File::remove(name).has_error())
{
Expand Down Expand Up @@ -59,7 +59,7 @@ expected<File, FileCreationError> FileBuilder::open(const FilePath& name) noexce
return err(FileCreationError::PermissionDenied);
}

if (m_access_mode == AccessMode::READ_ONLY || m_access_mode == AccessMode::READ_WRITE)
if (m_access_mode == AccessMode::ReadOnly || m_access_mode == AccessMode::ReadWrite)
{
if ((perms->value() & perms::owner_read.value()) == 0)
{
Expand All @@ -69,7 +69,7 @@ expected<File, FileCreationError> FileBuilder::open(const FilePath& name) noexce
}
}

if (m_access_mode == AccessMode::WRITE_ONLY || m_access_mode == AccessMode::READ_WRITE)
if (m_access_mode == AccessMode::WriteOnly || m_access_mode == AccessMode::ReadWrite)
{
if ((perms->value() & perms::owner_write.value()) == 0)
{
Expand Down Expand Up @@ -328,7 +328,7 @@ expected<uint64_t, FileReadError> File::read(uint8_t* const buffer, const uint64
expected<uint64_t, FileReadError>
File::read_at(const uint64_t offset, uint8_t* const buffer, const uint64_t buffer_len) const noexcept
{
if (m_access_mode == AccessMode::WRITE_ONLY)
if (m_access_mode == AccessMode::WriteOnly)
{
IOX_LOG(Error, "Unable to read from file since it is opened for writing only.");
return err(FileReadError::NotOpenedForReading);
Expand Down Expand Up @@ -384,7 +384,7 @@ expected<uint64_t, FileWriteError> File::write(const uint8_t* const buffer, cons
expected<uint64_t, FileWriteError>
File::write_at(const uint64_t offset, const uint8_t* const buffer, const uint64_t buffer_len) const noexcept
{
if (m_access_mode == AccessMode::READ_ONLY)
if (m_access_mode == AccessMode::ReadOnly)
{
IOX_LOG(Error, "Unable to write to file since it is opened for reading only.");
return err(FileWriteError::NotOpenedForWriting);
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/posix/filesystem/source/file_lock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ expected<FileLock, FileLockError> FileLockBuilder::create() noexcept
fileLockPath.unsafe_append(FileLock::LOCK_FILE_SUFFIX);

auto openCall = IOX_POSIX_CALL(iox_ext_open)(fileLockPath.c_str(),
convertToOflags(AccessMode::READ_ONLY, OpenMode::OPEN_OR_CREATE),
convertToOflags(AccessMode::ReadOnly, OpenMode::OpenOrCreate),
m_permission.value())
.failureReturnValue(-1)
.evaluate();
Expand Down
Loading

0 comments on commit 6794c8e

Please sign in to comment.