Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

latest from CODA-OSS #680

Merged
merged 61 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
fec3755
latest from CODA-OSS
Jun 19, 2023
cc60094
Merge commit '1ceb8e3ffb55a240085250cfde3f4d1ab7ef0b04' into develop/…
Jun 19, 2023
1ceb8e3
Squashed 'externals/coda-oss/' changes from e87c32b4d..54033e70e
Jun 19, 2023
ac1ccde
Squashed 'externals/nitro/' changes from c8ecbe9ae..3f01809fa
Jun 19, 2023
04090c4
sync_externals
Jun 19, 2023
e47ccf3
latest from CODA-OSS
Jun 19, 2023
2829f93
Merge branch 'main' into develop/sync_externals
Jun 19, 2023
3d4e554
Squashed 'externals/nitro/' changes from 3f01809fa..cee9feb42
Jun 19, 2023
b142ec4
sync_externals
Jun 19, 2023
c747f32
latest from CODA-OSS and NITRO
Jun 19, 2023
f25c53a
Merge branch 'main' into develop/sync_externals
Jul 5, 2023
f47cbbc
latest from CODA-OSS and NITRO
Jul 5, 2023
388bdad
Merge commit 'ea623b4ee1de1651418d5d4424201df95915dca8' into develop/…
Jul 5, 2023
ea623b4
Squashed 'externals/coda-oss/' changes from 54033e70e..c2fc5fc66
Jul 5, 2023
9a22788
Squashed 'externals/nitro/' changes from cee9feb42..49ec50325
Jul 5, 2023
11665af
sync_externals
Jul 5, 2023
36beb99
sync_externals
Jul 5, 2023
d606c61
Merge branch 'main' into develop/sync_externals
Jul 5, 2023
e275c07
Merge branch 'main' into develop/sync_externals
Jul 10, 2023
d60eddd
latest from CODA-OSS and NITRO
Jul 10, 2023
d4c971d
Merge commit '3b07146d57387ad695a7c0745c77c6c891338212' into develop/…
Jul 10, 2023
3b07146
Squashed 'externals/coda-oss/' changes from c2fc5fc66..f70b4202f
Jul 10, 2023
34b23e9
Squashed 'externals/nitro/' changes from 49ec50325..b4ae2d429
Jul 10, 2023
6c6fd14
sync_externals
Jul 10, 2023
ca98de0
latest from CODA-OSS and NITRO
Jul 10, 2023
6109529
somewhere a compiler warning got unsuppressed
Jul 10, 2023
15d0336
=default doesn't implement the destructor
Jul 10, 2023
fe6ba2a
Merge branch 'main' into develop/sync_externals
JDanielSmith Jul 14, 2023
c9cb326
latest from CODA-OSS and NITRO
JDanielSmith Jul 14, 2023
b43b3d0
latest from CODA-OSS and NITRO
Jul 18, 2023
be953dd
Merge commit '069ec60d6082a207f41aaf7873ea273a31ea8d68' into develop/…
Jul 18, 2023
069ec60
Squashed 'externals/coda-oss/' changes from f70b4202f..e2472acfc
Jul 18, 2023
bd99b0b
Squashed 'externals/nitro/' changes from b4ae2d429..225273436
Jul 18, 2023
13a9343
sync_externals
Jul 18, 2023
c8e0083
latest from CODA-OSS and NITRO
Jul 18, 2023
3649c1c
Merge branch 'main' into develop/sync_externals
Jul 18, 2023
b15154c
latest from CODA-OSS and NITRO
Jul 18, 2023
8aaead7
Merge commit 'e5f8b960096a91fe031e147aeea41a34e3b6b060' into develop/…
Jul 18, 2023
e5f8b96
Squashed 'externals/coda-oss/' changes from e2472acfc..4092fd8e7
Jul 18, 2023
3da54d8
Squashed 'externals/nitro/' changes from 225273436..de91d4977
Jul 18, 2023
10ed743
sync_externals
Jul 18, 2023
5e79844
latest from CODA-OSS and NITRO
Jul 18, 2023
471ada0
Merge branch 'main' into develop/sync_externals
Jul 24, 2023
6d99d91
latest from CODA-OSS and NITRO
Jul 24, 2023
63122e8
Merge commit 'e6081570e8e535d4c185b5d501407a5e6743d8ca' into develop/…
Jul 24, 2023
e608157
Squashed 'externals/coda-oss/' changes from 4092fd8e7..42d449c33
Jul 24, 2023
6923f89
Squashed 'externals/nitro/' changes from de91d4977..fb794f0fe
Jul 24, 2023
314d15f
sync_externals
Jul 24, 2023
e0eede7
latest from CODA-OSS and NITRO
Jul 24, 2023
481f447
'out' directory for CMake
Jul 24, 2023
6e8777d
latest from CODA-OSS
Jul 24, 2023
e7afece
Merge commit '85210dd69a0cc9482b980382f60a153d3a525394' into develop/…
Jul 24, 2023
85210dd
Squashed 'externals/coda-oss/' changes from 42d449c33..034d52c86
Jul 24, 2023
ffdcbe8
Squashed 'externals/nitro/' changes from fb794f0fe..5724d8c18
Jul 24, 2023
33ea0d2
sync_externals
Jul 24, 2023
bd78310
latest from CODA-OSS and NITRO
Jul 24, 2023
9890edd
Merge branch 'main' into develop/sync_externals
Jul 27, 2023
632a217
latest from coda-oss
Jul 27, 2023
53f0165
latest from CODA-OSS
Aug 1, 2023
835354e
Squashed 'externals/coda-oss/' changes from 034d52c86..065e86ddc
Aug 1, 2023
9a0bca5
Merge commit '835354e520d81d26cb33ae0403a3585572d5bc45' into develop/…
Aug 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 84 additions & 78 deletions externals/coda-oss/modules/c++/coda_oss/include/coda_oss/optional_.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,32 @@
* License along with this program; If not, http://www.gnu.org/licenses/.
*
*/

#pragma once
#ifndef CODA_OSS_coda_oss_optional__h_INCLUDED_
#define CODA_OSS_coda_oss_optional__h_INCLUDED_
#pragma once

#include <assert.h>

#include <utility>
#include <stdexcept>

// Simple version of std::optional since that doesn't exist until C++17.
//
// This doesn't even TRY to match the actual C++17 specification,
// it only tries to minimize code changes.
//
// http://en.cppreference.com/w/cpp/utility/Optional

#include "coda_oss/namespace_.h"
namespace coda_oss
{
namespace details
{
inline void throw_bad_optional_access()
{
throw std::logic_error(
"No value for optional<>."); // TODO: std::bad_optional_access
throw std::logic_error("No value for optional<>."); // TODO: std::bad_optional_access
}

template <typename T>
class optional final
{
T value_;
T value_{};
bool has_value_ = false;

void check_has_value() const
Expand All @@ -62,61 +57,81 @@ class optional final
public:
using value_type = T;

#if defined(_MSC_VER) && _PREFAST_ // Visual Studio /analyze
__pragma(warning(push)) __pragma(warning(disable : 26495)) // Variable '...' is uninitialized. Always initialize a member variable(type.6).
#endif
optional() noexcept
{
}
#if defined(_MSC_VER) && _PREFAST_
__pragma(warning(pop))
#endif
optional(const value_type& v) : value_(v), has_value_(true)
{
}
#if defined(_MSC_VER) && _PREFAST_ // Visual Studio /analyze
__pragma(warning(push)) __pragma(warning(disable : 26495)) // Variable '...' is uninitialized. Always initialize a member variable(type.6).
#endif
optional(const optional& other) : has_value_(other.has_value_)
optional(value_type&& v) : value_(std::move(v)), has_value_(true)
{
if (has_value())
{
value_ = other.value_;
}
}
#if defined(_MSC_VER) && _PREFAST_
__pragma(warning(pop))
#endif
optional& operator=(const optional& other)
{
if (has_value() && !other.has_value())
{
reset();
}
else if (other.has_value())
{
value_ = other.value_;
has_value_ = true;
}

return *this;
optional(const optional& other)
{
*this = other;
}

template <typename... Args> // https://en.cppreference.com/w/cpp/utility/Optional/emplace
T& emplace(Args&&... args)
optional(optional&& other) noexcept
{
value_ = value_type(std::forward<Args>(args)...);
has_value_ = true;
return value_;
*this = std::move(other);
}
template <typename U>
explicit optional(const optional<U>& other)
{
*this = other;
}
template <typename U>
explicit optional(optional<U>&& other)
{
*this = std::forward<optional<U>>(other);
}
template <typename U = T>
explicit optional(U&& value)
{
*this = std::forward<U>(value);
}

template <typename U = T> // https://en.cppreference.com/w/cpp/utility/optional/operator%3D
// https://en.cppreference.com/w/cpp/utility/optional/operator%3D
optional& operator=(const optional& other)
{
value_ = other.value_;
has_value_ = other.has_value_;
return *this;
}
optional& operator=(optional&& other) noexcept
{
value_ = std::move(other.value_);
has_value_ = std::move(other.has_value_);
return *this;
}
template <typename U = T>
optional& operator=(U&& value) noexcept
{
value_ = std::forward<U>(value);
has_value_ = true;
return *this;
}
template <typename U>
optional& operator=(const optional<U>& other)
{
value_ = other.value_;
has_value_ = other.has_value_;
return *this;
}
template <typename U>
optional& operator=(optional<U>&& other)
{
value_ = std::forward<optional<U>>(other.value_);
has_value_ = other.has_value_;
return *this;
}

template <typename... Args> // https://en.cppreference.com/w/cpp/utility/Optional/emplace
T& emplace(Args&&... args)
{
value_ = value_type(std::forward<Args>(args)...);
has_value_ = true;
return value_;
}

bool has_value() const noexcept
{
Expand Down Expand Up @@ -159,16 +174,13 @@ class optional final
const T* operator->() const
{
assert(has_value());
return &value_; // "This operator does not check whether the optional
// contains a value!"
return &value_; // "This operator does not check whether the optional contains a value!"
}
T* operator->() noexcept
{
assert(has_value());
return &value_; // "This operator does not check whether the optional
// contains a value!"
return &value_; // "This operator does not check whether the optional contains a value!"
}

const T& operator*() const& noexcept
{
assert(has_value());
Expand All @@ -177,20 +189,17 @@ class optional final
T& operator*() &
{
assert(has_value());
return value_; // "This operator does not check whether the optional
// contains a value!"
return value_; // "This operator does not check whether the optional contains a value!"
}
const T&& operator*() const&&
{
assert(has_value());
return value_; // "This operator does not check whether the optional
// contains a value!"
return value_; // "This operator does not check whether the optional contains a value!"
}
T&& operator*() &&
{
assert(has_value());
return value_; // "This operator does not check whether the optional
// contains a value!"
return value_; // "This operator does not check whether the optional contains a value!"
}

// https://en.cppreference.com/w/cpp/utility/optional/value_or
Expand Down Expand Up @@ -223,26 +232,23 @@ inline optional<T> make_optional(TArgs&&... args)
// Compares two optional objects, lhs and rhs. The contained values are compared
// (using the corresponding operator of T) only if both lhs and rhs contain
// values. Otherwise,
// * lhs is considered equal to rhs if, and only if, both lhs and rhs do not
// contain a value.
// * lhs is considered less than rhs if, and only if, rhs contains a value and
// lhs does not.
// * lhs is considered equal to rhs if, and only if, both lhs and rhs do not contain a value.
// * lhs is considered less than rhs if, and only if, rhs contains a value and lhs does not.
template <typename T, typename U>
inline bool operator==(const optional<T>& lhs, const optional<U>& rhs)
{
// If bool(lhs) != bool(rhs), returns false
if (bool(lhs) != bool(rhs))
// "If bool(lhs) != bool(rhs), returns false."
if (lhs.has_value() != rhs.has_value())
{
return false;
}
// Otherwise, if bool(lhs) == false (and so bool(rhs) == false as well),
// returns true
// "Otherwise, if bool(lhs) == false (and so bool(rhs) == false as well), returns true."
if (!lhs.has_value())
{
assert(!rhs.has_value());
return true;
}
// Otherwise, returns *lhs == *rhs.
// "Otherwise, returns *lhs == *rhs."
return *lhs == *rhs;
}
template <typename T, typename U>
Expand Down Expand Up @@ -275,17 +281,17 @@ inline bool operator!=(const optional<T>& opt, const U& value)
template <typename T, typename U>
inline bool operator<(const optional<T>& lhs, const optional<U>& rhs)
{
// If bool(rhs) == false returns false
// "If bool(rhs) == false returns false."
if (!rhs.has_value())
{
return false;
}
// Otherwise, if bool(lhs) == false, returns true
// "Otherwise, if bool(lhs) == false, returns true."
if (!lhs.has_value())
{
return true;
}
// Otherwise returns *lhs < *rhs
// "Otherwise returns *lhs < *rhs."
return *lhs < *rhs;
}
template <typename T, typename U>
Expand All @@ -302,17 +308,17 @@ inline bool operator<(const optional<T>& opt, const U& value)
template <typename T, typename U>
inline bool operator<=(const optional<T>& lhs, const optional<U>& rhs)
{
// If bool(lhs) == false returns true
// "If bool(lhs) == false returns true."
if (!lhs.has_value())
{
return true;
}
// Otherwise, if bool(rhs) == false, returns false
// "Otherwise, if bool(rhs) == false, returns false."
if (!rhs.has_value())
{
return false;
}
// Otherwise returns *lhs <= *rhs
// "Otherwise returns *lhs <= *rhs."
return *lhs <= *rhs;
}
template <typename T, typename U>
Expand All @@ -329,17 +335,17 @@ inline bool operator<=(const optional<T>& opt, const U& value)
template <typename T, typename U>
inline bool operator>(const optional<T>& lhs, const optional<U>& rhs)
{
// If bool(lhs) == false returns false
// "If bool(lhs) == false returns false."
if (!lhs.has_value())
{
return false;
}
// Otherwise, if bool(rhs) == false, returns true
// "Otherwise, if bool(rhs) == false, returns true."
if (!rhs.has_value())
{
return true;
}
// Otherwise returns *lhs > *rhs
// "Otherwise returns *lhs > *rhs."
return *lhs > *rhs;
}
template <typename T, typename U>
Expand All @@ -356,17 +362,17 @@ inline bool operator>(const optional<T>& opt, const U& value)
template <typename T, typename U>
inline bool operator>=(const optional<T>& lhs, const optional<U>& rhs)
{
// If bool(rhs) == false returns true
// "If bool(rhs) == false returns true."
if (!rhs.has_value())
{
return true;
}
// Otherwise, if bool(lhs) == false, returns false
// "Otherwise, if bool(lhs) == false, returns false."
if (!lhs.has_value())
{
return false;
}
// Otherwise returns *lhs >= *rhs
// "Otherwise returns *lhs >= *rhs."
return *lhs >= *rhs;
}
template <typename T, typename U>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ net::NetConnection* net::NetConnectionClientFactory::newConnection(
{
return new net::NetConnection(std::move(toServer));
}
#if CODA_OSS_autoptr_is_std // std::unique_ptr removed in C++17
net::NetConnection* net::NetConnectionClientFactory::newConnection(
std::unique_ptr<net::Socket> toServer)
{
return new net::NetConnection(toServer);
}
#endif

net::NetConnection * net::NetConnectionClientFactory::create(
const net::SocketAddress& address)
Expand Down
4 changes: 2 additions & 2 deletions externals/coda-oss/modules/c++/str/unittests/test_str.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ TEST_CASE(test_toStringComplexShort)
actual = str::toString(types_cx_short);
TEST_ASSERT_EQ(actual, expected);

const types::zint16_t zint16(1, -2);
const types::Complex<int16_t> zint16(1, -2);
actual = str::toString(zint16);
TEST_ASSERT_EQ(actual, expected);
}
Expand All @@ -303,7 +303,7 @@ TEST_CASE(test_toTypeComplexShort)
strActual = str::toString(zactual);
TEST_ASSERT_EQ(strActual, strValue);

zactual = str::toType<types::zint16_t>(strValue);
zactual = str::toType<types::Complex<int16_t>>(strValue);
strActual = str::toString(zactual);
TEST_ASSERT_EQ(strActual, strValue);
}
Expand Down
10 changes: 5 additions & 5 deletions externals/coda-oss/modules/c++/sys/include/sys/ByteSwap.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ inline void check_elemSize(size_t elemSize)
template <typename T>
inline auto make_span(coda_oss::span<const std::complex<T>> s)
{
static_assert(std::is_floating_point<T>::value, "std::complex<T> should use floating-point");
//static_assert(std::is_floating_point<T>::value, "std::complex<T> should use floating-point");

const void* const p_ = s.data();
auto const p = static_cast<const T*>(p_);
Expand All @@ -101,7 +101,7 @@ inline auto make_span(coda_oss::span<const std::complex<T>> s)
template<typename T>
inline auto make_span(coda_oss::span<std::complex<T>> s)
{
static_assert(std::is_floating_point<T>::value, "std::complex<T> should use floating-point");
//static_assert(std::is_floating_point<T>::value, "std::complex<T> should use floating-point");

void* const p_ = s.data();
auto const p = static_cast<T*>(p_);
Expand All @@ -122,7 +122,7 @@ inline void byteSwap(T* buffer, size_t elemSize, size_t numElems)
template <typename T>
inline void byteSwap(std::complex<T>* buffer, size_t elemSize, size_t numElems) // dont't want `T` as `std::complex<...>`
{
static_assert(std::is_floating_point<T>::value, "std::complex<T> should use floating-point");
//static_assert(std::is_floating_point<T>::value, "std::complex<T> should use floating-point");

details::check_elemSize<T>(elemSize);
void* const buffer_ = buffer;
Expand Down Expand Up @@ -194,7 +194,7 @@ inline void byteSwap(const T* buffer, size_t elemSize, size_t numElems, U* outpu
template <typename T, typename U>
inline void byteSwap(const std::complex<T>* buffer, size_t elemSize, size_t numElems, U* outputBuffer) // dont't want `T` as `std::complex<...>`
{
static_assert(std::is_floating_point<T>::value, "std::complex<T> should use floating-point");
//static_assert(std::is_floating_point<T>::value, "std::complex<T> should use floating-point");

details::check_elemSize<T>(elemSize);
const void* const buffer_ = buffer;
Expand Down Expand Up @@ -234,7 +234,7 @@ inline auto byteSwap(coda_oss::span<const std::complex<T>> buffer)
template <typename T>
inline auto byteSwapValue(std::complex<T> z)
{
static_assert(std::is_floating_point<T>::value, "std::complex<T> should use floating-point");
//static_assert(std::is_floating_point<T>::value, "std::complex<T> should use floating-point");

// C++ mandates that `std::complex<T>` be the same as `T cx[2]`; that is
// the structure is contiguous. https://en.cppreference.com/w/cpp/numeric/complex
Expand Down
Loading