Skip to content

Commit

Permalink
Merge pull request #1943 from ApexAI/iox-1942-introduce-semantic-string
Browse files Browse the repository at this point in the history
Iox 1942 introduce semantic string
  • Loading branch information
elfenpiff authored Mar 27, 2023
2 parents f42c003 + c15a449 commit 207d419
Show file tree
Hide file tree
Showing 8 changed files with 1,121 additions and 4 deletions.
2 changes: 2 additions & 0 deletions doc/website/release-notes/iceoryx-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
- Implement BumpAllocator [\#1732](https://github.com/eclipse-iceoryx/iceoryx/issues/1732)
- Expand cmake configuration options to enable reducing shared memory consumption. [\#1803](https://github.com/eclipse-iceoryx/iceoryx/issues/1803)
- Implement PolymorphicHandler [\#1640](https://github.com/eclipse-iceoryx/iceoryx/issues/1640)
- Implement SemanticString as base class for strong string types. [\#1942](https://github.com/eclipse-iceoryx/iceoryx/issues/1942)
- Implement UserName as strong string type to represent posix user names. [\#1942](https://github.com/eclipse-iceoryx/iceoryx/issues/1942)

**Bugfixes:**

Expand Down
2 changes: 2 additions & 0 deletions iceoryx_hoofs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ cc_library(
"filesystem/source/*.cpp",
"memory/source/*.cpp",
"posix/time/source/*.cpp",
"posix/vocabulary/source/*.cpp",
"primitives/source/*.cpp",
"reporting/source/log/building_blocks/*.cpp",
"source/**/*.cpp",
Expand All @@ -54,6 +55,7 @@ cc_library(
"legacy/include/",
"memory/include/",
"posix/time/include/",
"posix/vocabulary/include/",
"primitives/include/",
"reporting/include/",
"time/include/",
Expand Down
15 changes: 11 additions & 4 deletions iceoryx_hoofs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,14 @@ iox_add_library(
${PROJECT_SOURCE_DIR}/primitives/include
${PROJECT_SOURCE_DIR}/design/include
${PROJECT_SOURCE_DIR}/time/include
${PROJECT_SOURCE_DIR}/posix/time/include
${PROJECT_SOURCE_DIR}/buffer/include
${PROJECT_SOURCE_DIR}/filesystem/include
${PROJECT_SOURCE_DIR}/functional/include
${PROJECT_SOURCE_DIR}/reporting/include

${PROJECT_SOURCE_DIR}/posix/time/include
${PROJECT_SOURCE_DIR}/posix/vocabulary/include

${CMAKE_BINARY_DIR}/generated/iceoryx_hoofs/include
INSTALL_INTERFACE include/${PREFIX}
EXPORT_INCLUDE_DIRS include/
Expand All @@ -71,19 +74,19 @@ iox_add_library(
primitives/include/
design/include/
time/include/
posix/time/include/
buffer/include/
filesystem/include/
functional/include/
reporting/include/

posix/time/include/
posix/vocabulary/include/
FILES
design/source/functional_interface.cpp
filesystem/source/filesystem.cpp
memory/source/bump_allocator.cpp
memory/source/memory.cpp
memory/source/relative_pointer_data.cpp
posix/time/source/adaptive_wait.cpp
posix/time/source/deadline_timer.cpp
primitives/source/type_traits.cpp
reporting/source/log/building_blocks/console_logger.cpp
reporting/source/log/building_blocks/logger.cpp
Expand All @@ -109,6 +112,10 @@ iox_add_library(
source/posix_wrapper/unix_domain_socket.cpp
time/source/duration.cpp
utility/source/unique_id.cpp

posix/time/source/adaptive_wait.cpp
posix/time/source/deadline_timer.cpp
posix/vocabulary/source/user_name.cpp
)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/iceoryx_hoofs_deployment.hpp.in"
Expand Down
43 changes: 43 additions & 0 deletions iceoryx_hoofs/posix/vocabulary/include/iox/user_name.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2023 by Apex.AI Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_HOOFS_POSIX_VOCABULARY_USER_NAME_HPP
#define IOX_HOOFS_POSIX_VOCABULARY_USER_NAME_HPP

#include "iox/semantic_string.hpp"

namespace iox
{
namespace details
{
bool user_name_does_contain_invalid_characters(const string<platform::MAX_USER_NAME_LENGTH>& value) noexcept;
bool user_name_does_contain_invalid_content(const string<platform::MAX_USER_NAME_LENGTH>& value) noexcept;
} // namespace details

class UserName : public SemanticString<UserName,
platform::MAX_USER_NAME_LENGTH,
details::user_name_does_contain_invalid_content,
details::user_name_does_contain_invalid_characters>
{
using Parent = SemanticString<UserName,
platform::MAX_USER_NAME_LENGTH,
details::user_name_does_contain_invalid_content,
details::user_name_does_contain_invalid_characters>;
using Parent::Parent;
};
} // namespace iox

#endif
58 changes: 58 additions & 0 deletions iceoryx_hoofs/posix/vocabulary/source/user_name.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2023 by Apex.AI Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_platform/platform_settings.hpp"
#include "iox/string.hpp"

namespace iox
{
namespace details
{
bool user_name_does_contain_invalid_characters(const string<platform::MAX_USER_NAME_LENGTH>& value) noexcept
{
for (uint64_t i = 0; i < value.size(); ++i)
{
const bool contains_a_to_z = 'a' <= value[i] && value[i] <= 'z';
const bool contains_0_to_9 = '0' <= value[i] && value[i] <= '9';
const bool contains_dash = value[i] == '-';

if (!contains_a_to_z && !contains_0_to_9 && !contains_dash)
{
return true;
}
}

return false;
}

bool user_name_does_contain_invalid_content(const string<platform::MAX_USER_NAME_LENGTH>& value) noexcept
{
// user name is not allowed to be empty
if (value.empty())
{
return true;
}

// a user name is not allowed to start with a number or dash
if (value[0] == '-' || ('0' <= value[0] && value[0] <= '9'))
{
return true;
}

return false;
}
} // namespace details
} // namespace iox
Loading

0 comments on commit 207d419

Please sign in to comment.