Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1560 Move left-overs in 'helplets.hpp' to separat…
Browse files Browse the repository at this point in the history
…e files

Signed-off-by: Simon Hoinkis <[email protected]>
  • Loading branch information
mossmaurice committed Jan 30, 2023
1 parent c9ee555 commit efaabe7
Show file tree
Hide file tree
Showing 48 changed files with 132 additions and 104 deletions.
2 changes: 1 addition & 1 deletion doc/design/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ int32_t myAlgorithm(int32_t* ptr) {
}
```

Note that in the case of ``nullptr`` checks it is also an option to use references in arguments (or ``not_null`` if it is supposed to be stored since references are not copyable). It should be considered that ``not_null`` incurs a runtime cost, which may be undesirable.
Note that in the case of ``nullptr`` checks it is also an option to use references in arguments (or ``iox::not_null`` if it is supposed to be stored since references are not copyable). It should be considered that ``iox::not_null`` incurs a runtime cost, which may be undesirable.
When Expects and Ensures are implemented to leave no trace in release mode, we do not incur a runtime cost using them. For this reason, it is advised to use them to document and verify assumptions where appropriate.

### `expected`
Expand Down
8 changes: 4 additions & 4 deletions doc/website/release-notes/iceoryx-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@
std::cout << SOME_ENUM_STRINGS[static_cast<uint64_t>(someEnum)] << std::endl;
```

17. Replace `strlen2` with more generic `arrayCapacity`
17. Replace `strlen2` with more generic `iox::size`

```cpp
constexpr const char LITERAL1[] {"FOO"};
Expand All @@ -430,9 +430,9 @@
std::cout << iox::cxx::strlen2(LITERAL2) << std::endl; // prints 19

// after
std::cout << arrayCapacity(LITERAL1) << std::endl; // prints 4
std::cout << arrayCapacity(LITERAL2) << std::endl; // prints 20
std::cout << arrayCapacity(ARRAY) << std::endl; // prints 42
std::cout << iox::size(LITERAL1) << std::endl; // prints 4
std::cout << iox::size(LITERAL2) << std::endl; // prints 20
std::cout << iox::size(ARRAY) << std::endl; // prints 42
```

18. Rename `cxx::GenericRAII` to `cxx::ScopeGuard`
Expand Down
4 changes: 2 additions & 2 deletions iceoryx_examples/iceperf/uds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
// SPDX-License-Identifier: Apache-2.0

#include "uds.hpp"
#include "iceoryx_hoofs/cxx/helplets.hpp"
#include "iceoryx_hoofs/cxx/requires.hpp"
#include "iceoryx_hoofs/posix_wrapper/posix_call.hpp"
#include "iox/size.hpp"

#include <chrono>
#include <thread>
Expand All @@ -36,7 +36,7 @@ void UDS::initSocketAddress(sockaddr_un& socketAddr, const std::string& socketNa
memset(&socketAddr, 0, sizeof(sockaddr_un));
socketAddr.sun_family = AF_LOCAL;
constexpr uint64_t NULL_TERMINATION_SIZE{1};
const uint64_t maxDestinationLength = iox::cxx::arrayCapacity(socketAddr.sun_path) - NULL_TERMINATION_SIZE;
const uint64_t maxDestinationLength = iox::size(socketAddr.sun_path) - NULL_TERMINATION_SIZE;
iox::cxx::Ensures(maxDestinationLength >= socketName.size() && "Socketname too large!");
strncpy(socketAddr.sun_path, socketName.c_str(), socketName.size());
}
Expand Down
3 changes: 2 additions & 1 deletion iceoryx_hoofs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ cc_library(
"source/**/*.hpp",
"memory/source/*.cpp",
]),
hdrs = glob(["include/**"]) + glob(["legacy/**"]) + glob(["memory/**"]) + glob(["container/**"]) + glob(["vocabulary/**"]) + glob(["utility/**"]) + [
hdrs = glob(["include/**"]) + glob(["legacy/**"]) + glob(["memory/**"]) + glob(["container/**"]) + glob(["vocabulary/**"]) + glob(["utility/**"]) + glob(["primitives/**"]) + [
":iceoryx_hoofs_deployment_hpp",
],
includes = [
"container/include/",
"include/",
"legacy/include/",
"memory/include/",
"primitives/include/",
"utility/include/",
"vocabulary/include/",
],
Expand Down
2 changes: 2 additions & 0 deletions iceoryx_hoofs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ iox_add_library(
${PROJECT_SOURCE_DIR}/container/include
${PROJECT_SOURCE_DIR}/vocabulary/include
${PROJECT_SOURCE_DIR}/utility/include
${PROJECT_SOURCE_DIR}/primitives/include
${CMAKE_BINARY_DIR}/generated/iceoryx_hoofs/include
INSTALL_INTERFACE include/${PREFIX}
EXPORT_INCLUDE_DIRS include/
Expand All @@ -60,6 +61,7 @@ iox_add_library(
container/include/
vocabulary/include/
utility/include/
primitives/include/
FILES
source/concurrent/loffli.cpp
source/cxx/adaptive_wait.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#ifndef IOX_HOOFS_CONCURRENT_LOFFLI_HPP
#define IOX_HOOFS_CONCURRENT_LOFFLI_HPP

#include "iceoryx_hoofs/cxx/helplets.hpp"
#include "iceoryx_hoofs/memory/relative_pointer.hpp"
#include "iox/not_null.hpp"

#include <atomic>
#include <cstdint>
Expand Down Expand Up @@ -80,7 +80,7 @@ class LoFFLi
/// Initializes the lock-free free-list
/// @param [in] freeIndicesMemory pointer to a memory with the capacity calculated by requiredMemorySize()
/// @param [in] capacity is the number of elements of the free-list; must be the same used at requiredMemorySize()
void init(cxx::not_null<Index_t*> freeIndicesMemory, const uint32_t capacity) noexcept;
void init(not_null<Index_t*> freeIndicesMemory, const uint32_t capacity) noexcept;

/// Pop a value from the free-list
/// @param [out] index for an element to use
Expand Down
42 changes: 42 additions & 0 deletions iceoryx_hoofs/primitives/include/iox/size.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 - 2022 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_PRIMITIVES_SIZE_HPP
#define IOX_HOOFS_PRIMITIVES_SIZE_HPP

#include <cstdint>

namespace iox
{
/// @brief Get the capacity of a C array at compile time
/// @code
/// constexpr uint32_t FOO[42]{};
/// IOX_LOG(INFO) << size(FOO); // will print 42
/// @endcode
/// @tparam T the type of the array filled out by the compiler.
/// @tparam CapacityValue the capacity of the array filled out by the compiler.
/// @param[in] The actual content of the array is not of interest. Its just the capacity of the array that matters.
/// @return Returns the capacity of the array at compile time.
template <typename T, uint64_t CapacityValue>
// AXIVION Next Construct AutosarC++19_03-A18.1.1:returning capacity of C array at compile time is safe, no
// possibility of out of bounds access
// NOLINTNEXTLINE(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)
static constexpr uint64_t size(T const (&/*notInterested*/)[CapacityValue]) noexcept
{
return CapacityValue;
}
} // namespace iox
#endif // IOX_HOOFS_PRIMITIVES_SIZE_HPP
2 changes: 1 addition & 1 deletion iceoryx_hoofs/source/concurrent/loffli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace iox
{
namespace concurrent
{
void LoFFLi::init(cxx::not_null<Index_t*> freeIndicesMemory, const uint32_t capacity) noexcept
void LoFFLi::init(not_null<Index_t*> freeIndicesMemory, const uint32_t capacity) noexcept
{
cxx::Expects(capacity > 0 && "A capacity of 0 is not supported!");
constexpr uint32_t INTERNALLY_RESERVED_INDICES{1U};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_hoofs/cxx/helplets.hpp"
#include "iox/string.hpp"
#include "iox/size.hpp"
#include "test.hpp"

#include <type_traits>

namespace
{
using namespace ::testing;

class Helplets_test : public Test
class Size_test : public Test
{
public:
void SetUp() override
Expand All @@ -37,15 +34,15 @@ class Helplets_test : public Test
}
};

TEST_F(Helplets_test, ArrayCapacityReturnsCorrectValues)
TEST_F(Size_test, ArrayCapacityReturnsCorrectValues)
{
::testing::Test::RecordProperty("TEST_ID", "8392b2ba-04ef-45e6-8b47-4c0c90d98f61");
constexpr uint64_t CAPACITY{42};
// NOLINTJUSTIFICATION Used only for test purposes
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays)
constexpr uint32_t SUT[CAPACITY]{};

EXPECT_EQ(iox::cxx::arrayCapacity(SUT), CAPACITY);
EXPECT_EQ(iox::size(SUT), CAPACITY);
}

} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_HOOFS_CXX_HELPLETS_HPP
#define IOX_HOOFS_CXX_HELPLETS_HPP
#ifndef IOX_HOOFS_VOCABULARY_NOT_NULL_HPP
#define IOX_HOOFS_VOCABULARY_NOT_NULL_HPP

#include "iceoryx_hoofs/cxx/type_traits.hpp"
#include "iox/string.hpp"

namespace iox
{
namespace cxx
{
template <typename T, typename = typename std::enable_if<std::is_pointer<T>::value, void>::type>
struct not_null
{
Expand All @@ -34,7 +30,7 @@ struct not_null
not_null(T t) noexcept
: m_value(t)
{
Expects(t != nullptr);
cxx::Expects(t != nullptr);
}

// AXIVION Next Construct AutosarC++19_03-A13.5.2,AutosarC++19_03-A13.5.3:this should behave like a pointer which never can be nullptr,
Expand All @@ -48,25 +44,5 @@ struct not_null
private:
T m_value;
};

/// @brief Get the capacity of a C array at compile time
/// @code
/// constexpr uint32_t FOO[42]{};
/// IOX_LOG(INFO) << arrayCapacity(FOO); // will print 42
/// @endcode
/// @tparam T the type of the array filled out by the compiler.
/// @tparam CapacityValue the capacity of the array filled out by the compiler.
/// @param[in] The actual content of the array is not of interest. Its just the capacity of the array that matters.
/// @return Returns the capacity of the array at compile time.
template <typename T, uint64_t CapacityValue>
// AXIVION Next Construct AutosarC++19_03-A18.1.1:returning capacity of C array at compile time is safe, no
// possibility of out of bounds access
// NOLINTNEXTLINE(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)
static constexpr uint64_t arrayCapacity(T const (&/*notInterested*/)[CapacityValue]) noexcept
{
return CapacityValue;
}
} // namespace cxx
} // namespace iox

#endif // IOX_HOOFS_CXX_HELPLETS_HPP
#endif // IOX_HOOFS_VOCABULARY_NOT_NULL_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#ifndef IOX_POSH_MEPOO_CHUNK_MANAGEMENT_HPP
#define IOX_POSH_MEPOO_CHUNK_MANAGEMENT_HPP

#include "iceoryx_hoofs/cxx/helplets.hpp"
#include "iceoryx_hoofs/memory/relative_pointer.hpp"
#include "iox/not_null.hpp"

#include <atomic>
#include <cstdint>
Expand All @@ -36,9 +36,9 @@ struct ChunkManagement
using referenceCounterBase_t = uint64_t;
using referenceCounter_t = std::atomic<referenceCounterBase_t>;

ChunkManagement(const cxx::not_null<base_t*> chunkHeader,
const cxx::not_null<MemPool*> mempool,
const cxx::not_null<MemPool*> chunkManagementPool) noexcept;
ChunkManagement(const not_null<base_t*> chunkHeader,
const not_null<MemPool*> mempool,
const not_null<MemPool*> chunkManagementPool) noexcept;

iox::memory::RelativePointer<base_t> m_chunkHeader;
referenceCounter_t m_referenceCounter{1U};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "iceoryx_posh/internal/mepoo/shared_chunk.hpp"
#include "iceoryx_posh/internal/popo/building_blocks/chunk_distributor_data.hpp"
#include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_pusher.hpp"
#include "iox/not_null.hpp"

#include <thread>

Expand Down Expand Up @@ -66,7 +67,7 @@ class ChunkDistributor
using ChunkQueueData_t = typename ChunkDistributorDataType::ChunkQueueData_t;
using ChunkQueuePusher_t = typename ChunkDistributorDataType::ChunkQueuePusher_t;

explicit ChunkDistributor(cxx::not_null<MemberType_t* const> chunkDistrubutorDataPtr) noexcept;
explicit ChunkDistributor(not_null<MemberType_t* const> chunkDistrubutorDataPtr) noexcept;

ChunkDistributor(const ChunkDistributor& other) = delete;
ChunkDistributor& operator=(const ChunkDistributor&) = delete;
Expand All @@ -80,13 +81,13 @@ class ChunkDistributor
/// @param[in] requestedHistory number of last chunks from history to send if available. If history size is smaller
/// then the available history size chunks are provided
/// @return if the queue could be added it returns success, otherwiese a ChunkDistributor error
expected<ChunkDistributorError> tryAddQueue(cxx::not_null<ChunkQueueData_t* const> queueToAdd,
expected<ChunkDistributorError> tryAddQueue(not_null<ChunkQueueData_t* const> queueToAdd,
const uint64_t requestedHistory = 0U) noexcept;

/// @brief Remove a queue from the internal list of chunk queues
/// @param[in] queueToRemove is the queue to remove from the list
/// @return if the queue could be removed it returns success, otherwiese a ChunkDistributor error
expected<ChunkDistributorError> tryRemoveQueue(cxx::not_null<ChunkQueueData_t* const> queueToRemove) noexcept;
expected<ChunkDistributorError> tryRemoveQueue(not_null<ChunkQueueData_t* const> queueToRemove) noexcept;

/// @brief Delete all the stored chunk queues
void removeAllQueues() noexcept;
Expand Down Expand Up @@ -142,7 +143,7 @@ class ChunkDistributor
const MemberType_t* getMembers() const noexcept;
MemberType_t* getMembers() noexcept;

bool pushToQueue(cxx::not_null<ChunkQueueData_t* const> queue, mepoo::SharedChunk chunk) noexcept;
bool pushToQueue(not_null<ChunkQueueData_t* const> queue, mepoo::SharedChunk chunk) noexcept;

private:
MemberType_t* m_chunkDistrubutorDataPtr{nullptr};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace popo
{
template <typename ChunkDistributorDataType>
inline ChunkDistributor<ChunkDistributorDataType>::ChunkDistributor(
cxx::not_null<MemberType_t* const> chunkDistrubutorDataPtr) noexcept
not_null<MemberType_t* const> chunkDistrubutorDataPtr) noexcept
: m_chunkDistrubutorDataPtr(chunkDistrubutorDataPtr)
{
}
Expand All @@ -46,7 +46,7 @@ ChunkDistributor<ChunkDistributorDataType>::getMembers() noexcept

template <typename ChunkDistributorDataType>
inline expected<ChunkDistributorError>
ChunkDistributor<ChunkDistributorDataType>::tryAddQueue(cxx::not_null<ChunkQueueData_t* const> queueToAdd,
ChunkDistributor<ChunkDistributorDataType>::tryAddQueue(not_null<ChunkQueueData_t* const> queueToAdd,
const uint64_t requestedHistory) noexcept
{
typename MemberType_t::LockGuard_t lock(*getMembers());
Expand Down Expand Up @@ -98,8 +98,8 @@ ChunkDistributor<ChunkDistributorDataType>::tryAddQueue(cxx::not_null<ChunkQueue
}

template <typename ChunkDistributorDataType>
inline expected<ChunkDistributorError> ChunkDistributor<ChunkDistributorDataType>::tryRemoveQueue(
cxx::not_null<ChunkQueueData_t* const> queueToRemove) noexcept
inline expected<ChunkDistributorError>
ChunkDistributor<ChunkDistributorDataType>::tryRemoveQueue(not_null<ChunkQueueData_t* const> queueToRemove) noexcept
{
typename MemberType_t::LockGuard_t lock(*getMembers());

Expand Down Expand Up @@ -219,7 +219,7 @@ inline uint64_t ChunkDistributor<ChunkDistributorDataType>::deliverToAllStoredQu
}

template <typename ChunkDistributorDataType>
inline bool ChunkDistributor<ChunkDistributorDataType>::pushToQueue(cxx::not_null<ChunkQueueData_t* const> queue,
inline bool ChunkDistributor<ChunkDistributorDataType>::pushToQueue(not_null<ChunkQueueData_t* const> queue,
mepoo::SharedChunk chunk) noexcept
{
return ChunkQueuePusher_t(queue).push(chunk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "iceoryx_posh/internal/mepoo/shared_chunk.hpp"
#include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_data.hpp"
#include "iceoryx_posh/internal/popo/building_blocks/condition_notifier.hpp"
#include "iox/not_null.hpp"
#include "iox/optional.hpp"

namespace iox
Expand All @@ -37,7 +38,7 @@ class ChunkQueuePopper
public:
using MemberType_t = ChunkQueueDataType;

explicit ChunkQueuePopper(cxx::not_null<MemberType_t* const> chunkQueueDataPtr) noexcept;
explicit ChunkQueuePopper(not_null<MemberType_t* const> chunkQueueDataPtr) noexcept;

ChunkQueuePopper(const ChunkQueuePopper& other) = delete;
ChunkQueuePopper& operator=(const ChunkQueuePopper&) = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ namespace iox
namespace popo
{
template <typename ChunkQueueDataType>
inline ChunkQueuePopper<ChunkQueueDataType>::ChunkQueuePopper(
cxx::not_null<MemberType_t* const> chunkQueueDataPtr) noexcept
inline ChunkQueuePopper<ChunkQueueDataType>::ChunkQueuePopper(not_null<MemberType_t* const> chunkQueueDataPtr) noexcept
: m_chunkQueueDataPtr(chunkQueueDataPtr)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_data.hpp"
#include "iceoryx_posh/internal/popo/building_blocks/condition_notifier.hpp"
#include "iox/expected.hpp"
#include "iox/not_null.hpp"

namespace iox
{
Expand All @@ -36,7 +37,7 @@ class ChunkQueuePusher
public:
using MemberType_t = ChunkQueueDataType;

explicit ChunkQueuePusher(cxx::not_null<MemberType_t* const> chunkQueueDataPtr) noexcept;
explicit ChunkQueuePusher(not_null<MemberType_t* const> chunkQueueDataPtr) noexcept;

ChunkQueuePusher(const ChunkQueuePusher& other) = delete;
ChunkQueuePusher& operator=(const ChunkQueuePusher&) = delete;
Expand Down
Loading

0 comments on commit efaabe7

Please sign in to comment.