Skip to content

Commit

Permalink
Release v5.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
arobenko committed Dec 7, 2023
2 parents 923e459 + 0212d43 commit d2aaffc
Show file tree
Hide file tree
Showing 23 changed files with 1,121 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/actions_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ jobs:
fail-fast: false
matrix:
type: [Debug, Release, MinSizeRel]
cc_ver: [12, 13, 14]
cc_ver: [12, 13, 14, 15]
cpp: [11, 14, 17, 20]

steps:
Expand Down
214 changes: 156 additions & 58 deletions doxygen/doxygen.conf

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doxygen/main.dox
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
/// for custom binary protocol, which can be used in any application in the future,
/// including bare-metal one with constrained environment.
///
/// Refer to <a href="version_8h.html">comms/version.h</a> file for the version
/// Refer to @ref version.h "comms/version.h" file for the version
/// information of the @b COMMS library and this documentation.
///
2 changes: 2 additions & 0 deletions include/comms/CompileControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
#define COMMS_IS_GCC_10 (COMMS_IS_GCC && (__GNUC__ == 10))
#define COMMS_IS_GCC_10_OR_ABOVE (COMMS_IS_GCC && (__GNUC__ >= 10))
#define COMMS_IS_GCC_10_OR_BELOW (COMMS_IS_GCC && (__GNUC__ <= 10))
#define COMMS_IS_GCC_11 (COMMS_IS_GCC && (__GNUC__ == 11))
#define COMMS_IS_GCC_11_OR_ABOVE (COMMS_IS_GCC && (__GNUC__ >= 11))
#define COMMS_IS_GCC_12 (COMMS_IS_GCC && (__GNUC__ == 12))
#define COMMS_IS_CLANG_7_OR_ABOVE (COMMS_IS_CLANG && (__clang_major__ >= 7))
#define COMMS_IS_CLANG_8 (COMMS_IS_CLANG && (__clang_major__ == 8))
Expand Down
39 changes: 30 additions & 9 deletions include/comms/field/basic/ArrayList.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "comms/ErrorStatus.h"
#include "comms/util/access.h"
#include "comms/util/assign.h"
#include "comms/util/MaxSizeOf.h"
#include "comms/util/StaticVector.h"
#include "comms/util/StaticString.h"
#include "comms/util/detect.h"
Expand Down Expand Up @@ -161,6 +162,7 @@ class ArrayList :

ElementType& createBack()
{
COMMS_ASSERT(value_.size() < value_.max_size());
value_.emplace_back();
updateElemVersion(value_.back(), VersionTag<>());
return value_.back();
Expand Down Expand Up @@ -654,10 +656,8 @@ class ArrayList :
value_.clear();
auto remLen = len;
while (0 < remLen) {
ElementType& elem = createBack();
auto es = readElement(elem, iter, remLen);
auto es = createAndReadNextElementInternal(iter, remLen);
if (es != ErrorStatus::Success) {
value_.pop_back();
return es;
}
}
Expand All @@ -668,7 +668,7 @@ class ArrayList :
template <typename TIter, typename... TParams>
ErrorStatus readInternal(TIter& iter, std::size_t len, RawDataTag<TParams...>)
{
comms::util::assign(value(), iter, iter + len);
comms::util::assign(value(), iter, iter + std::min(len, comms::util::maxSizeOf(value())));
std::advance(iter, len);
return ErrorStatus::Success;
}
Expand All @@ -678,10 +678,8 @@ class ArrayList :
{
clear();
while (0 < count) {
auto& elem = createBack();
auto es = readElement(elem, iter, len);
auto es = createAndReadNextElementInternal(iter, len);
if (es != ErrorStatus::Success) {
value_.pop_back();
return es;
}

Expand All @@ -706,8 +704,14 @@ class ArrayList :
{
clear();
while (0 < count) {
auto& elem = createBack();
readElementNoStatus(elem, iter);
if (value_.size() < value_.max_size()) {
auto& elem = createBack();
readElementNoStatus(elem, iter);
}
else {
ElementType elem;
readElementNoStatus(elem, iter);
}
--count;
}
}
Expand Down Expand Up @@ -773,6 +777,23 @@ class ArrayList :
return true;
}

template <typename TIter>
comms::ErrorStatus createAndReadNextElementInternal(TIter& iter, std::size_t& len)
{
if (value_.size() < value_.max_size()) {
auto& elem = createBack();
auto es = readElement(elem, iter, len);
if (es != ErrorStatus::Success) {
value_.pop_back();
}

return es;
}

ElementType elem;
return readElement(elem, iter, len);
}

ValueType value_;
};

Expand Down
6 changes: 4 additions & 2 deletions include/comms/field/basic/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "comms/ErrorStatus.h"
#include "comms/util/access.h"
#include "comms/util/assign.h"
#include "comms/util/MaxSizeOf.h"
#include "comms/util/StaticVector.h"
#include "comms/util/StaticString.h"
#include "comms/util/detect.h"
Expand Down Expand Up @@ -186,9 +187,10 @@ class String : public TFieldBase

using ConstPointer = typename ValueType::const_pointer;
auto* str = reinterpret_cast<ConstPointer>(&(*iter));
std::advance(iter, len);
auto* endStr = reinterpret_cast<ConstPointer>(&(*iter));
auto endStr = str;
std::advance(endStr, std::min(len, comms::util::maxSizeOf(value_)));
comms::util::assign(value_, str, endStr);
std::advance(iter, len);
return ErrorStatus::Success;
}

Expand Down
81 changes: 81 additions & 0 deletions include/comms/util/MaxSizeOf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// Copyright 2015 - 2023 (C). Alex Robenko. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#pragma once

#include <cstddef>
#include <limits>
#include <type_traits>

#include "comms/details/tag.h"
#include "comms/util/type_traits.h"
#include "comms/util/detect.h"

namespace comms
{

namespace util
{

namespace details
{

class MaxSizeOfHelper
{
public:
template <typename T>
static std::size_t maxSizeOf(const T& val)
{
using DecayedType = typename std::decay<decltype(val)>::type;
using Tag =
typename comms::util::LazyShallowConditional<
comms::util::detect::hasMaxSizeFunc<DecayedType>()
>::template Type<
HasMaxSizeTag,
NoMaxSizeTag
>;

return maxSizeOfInternal(val, Tag());
}

private:
template <typename... TParams>
using HasMaxSizeTag = comms::details::tag::Tag1<>;

template <typename... TParams>
using NoMaxSizeTag = comms::details::tag::Tag2<>;

template <typename T, typename... TParams>
static std::size_t maxSizeOfInternal(const T& val, HasMaxSizeTag<>)
{
return val.max_size();
}

template <typename T, typename... TParams>
static std::size_t maxSizeOfInternal(const T& val, NoMaxSizeTag<>)
{
static_cast<void>(val);
return std::numeric_limits<std::size_t>::max();
}
};

} // namespace details

/// @cond SKIP_DOC
template <typename T>
std::size_t maxSizeOf(const T& val)
{
return details::MaxSizeOfHelper::maxSizeOf(val);
}

/// @endcond

} // namespace util

} // namespace comms


5 changes: 3 additions & 2 deletions include/comms/util/ScopeGuard.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

/// @file
/// @brief Contains definition of the "Scope Guard" idiom, see @ref comms::util::ScopeGuard.

#pragma once

#include <memory>
Expand Down Expand Up @@ -160,8 +163,6 @@ ScopeGuard<decltype(std::bind(std::forward<TFunc>(func),
return ScopeGuard<decltype(bindObj)>(std::move(bindObj));
}

// Class implementation part

} // namespace util

} // namespace comms
4 changes: 2 additions & 2 deletions include/comms/util/StaticQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

/// @file comms/util/StaticQueue.h
/// This file contains the definition and implementation of the static queue,
/// which also can be used as circular buffer.
/// @brief This file contains the definition and implementation of the static queue,
/// which also can be used as circular buffer.

#pragma once

Expand Down
Loading

0 comments on commit d2aaffc

Please sign in to comment.