Skip to content

Commit

Permalink
latest from CODA-OSS and NITRO
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith authored and Dan Smith committed Jun 8, 2023
1 parent 452563c commit 646b70e
Show file tree
Hide file tree
Showing 16 changed files with 196 additions and 19 deletions.
4 changes: 4 additions & 0 deletions externals/coda-oss/UnitTest/UnitTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\modules\c++\types\unittests\test_complex_short.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\modules\c++\types\unittests\test_page_row_col.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
Expand Down
3 changes: 3 additions & 0 deletions externals/coda-oss/UnitTest/UnitTest.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@
<ClCompile Include="..\modules\c++\mt\unittests\test_mt_byte_swap.cpp">
<Filter>mt</Filter>
</ClCompile>
<ClCompile Include="..\modules\c++\types\unittests\test_complex_short.cpp">
<Filter>types</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
Expand Down
1 change: 1 addition & 0 deletions externals/coda-oss/UnitTest/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <types/PageRowCol.h>
#include <types/RangeList.h>
#include <types/Range.h>
#include <types/complex_short.h>
#include <sys/Conf.h>
#include <sys/Path.h>
#include <except/Exception.h>
Expand Down
4 changes: 4 additions & 0 deletions externals/coda-oss/UnitTest/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ TEST_CLASS(test_range_list){ public:
#include "types/unittests/test_range_list.cpp"
};

TEST_CLASS(test_complex_short){ public:
#include "types/unittests/test_complex_short.cpp"
};

}
1 change: 1 addition & 0 deletions externals/coda-oss/modules/c++/coda-oss-lite.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
<ClInclude Include="tiff\include\tiff\KnownTags.h" />
<ClInclude Include="tiff\include\tiff\TypeFactory.h" />
<ClInclude Include="tiff\include\tiff\Utils.h" />
<ClInclude Include="types\include\types\complex_short.h" />
<ClInclude Include="types\include\types\PageRowCol.h" />
<ClInclude Include="types\include\types\Range.h" />
<ClInclude Include="types\include\types\RangeList.h" />
Expand Down
3 changes: 3 additions & 0 deletions externals/coda-oss/modules/c++/coda-oss-lite.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,9 @@
<ClInclude Include="sys\include\sys\SysInt.h">
<Filter>sys</Filter>
</ClInclude>
<ClInclude Include="types\include\types\complex_short.h">
<Filter>types</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp" />
Expand Down
20 changes: 12 additions & 8 deletions externals/coda-oss/modules/c++/mem/include/mem/ScopedPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
*
*/

#pragma once
#ifndef CODA_OSS_mem_ScopedPtr_h_INCLUDED_
#define CODA_OSS_mem_ScopedPtr_h_INCLUDED_
#pragma once

#include <assert.h>

#include <cstddef>
#include <std/memory>
Expand Down Expand Up @@ -110,15 +112,13 @@ class ScopedPtr
auto rhs_ptr = rhs.get();
if (ptr == nullptr && rhs_ptr == nullptr)
{
return true;
return true; // both NULL: equal
}

if (ptr == nullptr || rhs_ptr == nullptr)
{
return false;
return false; // either NULL, but not both (above): not equal
}

return *ptr == *rhs_ptr;
return *ptr == *rhs_ptr; // compare the (non-NULL) objects
}

bool operator!=(const ScopedPtr& rhs) const noexcept
Expand All @@ -138,12 +138,16 @@ class ScopedPtr

T& operator*() const
{
return *get();
auto ptr = get();
assert(ptr != nullptr);
return *ptr;
}

T* operator->() const noexcept
{
return get();
auto ptr = get();
assert(ptr != nullptr);
return ptr;
}

void reset(T* ptr = nullptr)
Expand Down
3 changes: 1 addition & 2 deletions externals/coda-oss/modules/c++/std/include/import/cpp14.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
*
*/


#pragma once
#ifndef CODA_OSS_import_cpp14_h_INCLUDED_
#define CODA_OSS_import_cpp14_h_INCLUDED_
#pragma once

// Common C++14 headers
#include <limits>
Expand Down
3 changes: 0 additions & 3 deletions externals/coda-oss/modules/c++/str/include/str/Manip.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,6 @@ inline std::string join(const std::vector<T>& toks, const std::string& with)
// CASE INSENSTIVE string comparision routines.
// Short names w/o a "case insenstive" indicator would seem OK as
// normal (i.e., case sensitive) comparisons will use `==` and `!=` operators.
//
// Note that calling ne() directly can be faster than !eq() because the
// comparison can stop as soon as a mis-match is found.
CODA_OSS_API bool eq(const std::string& lhs, const std::string& rhs) noexcept;
CODA_OSS_API bool ne(const std::string& lhs, const std::string& rhs) noexcept;

Expand Down
2 changes: 2 additions & 0 deletions externals/coda-oss/modules/c++/str/source/Manip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ void escapeForXML(std::string& str)
// https://en.cppreference.com/w/cpp/string/char_traits
class ci_char_traits final : public std::char_traits<char>
{
// Use our own routine rather than strcasecmp() so that the same
// toupperCheck() is used as when calling upper().
static auto to_upper(char ch) noexcept
{
return toupperCheck(ch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ namespace sys
template <typename T>
inline auto as_bytes(const T& v) noexcept
{
static_assert(!std::is_compound<T>::value, "T cannot be a 'struct'");
return sys::as_bytes(&v, 1);
}
template <typename T>
inline auto as_writable_bytes(T& v) noexcept
{
static_assert(!std::is_compound<T>::value, "T cannot be a 'struct'");
return sys::as_writable_bytes(&v, 1);
}

Expand Down
2 changes: 1 addition & 1 deletion externals/coda-oss/modules/c++/types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ set(MODULE_NAME types)

coda_add_module(${MODULE_NAME}
VERSION 1.0
DEPS gsl-c++)
DEPS coda_oss-c++ config-c++ gsl-c++ coda_oss-c++)

coda_add_tests(
MODULE_NAME ${MODULE_NAME}
Expand Down
114 changes: 114 additions & 0 deletions externals/coda-oss/modules/c++/types/include/types/complex_short.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/* =========================================================================
* This file is part of types-c++
* =========================================================================
*
* (C) Copyright 2004 - 2014, MDA Information Systems LLC
* (C) Copyright 2023, Maxar Technologies, Inc.
*
* types-c++ is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* see <http://www.gnu.org/licenses/>.
*
*/

#pragma once
#ifndef CODA_OSS_types_complex_short_h_INCLUDED_
#define CODA_OSS_types_complex_short_h_INCLUDED_

#include <complex>

#include "config/disable_compiler_warnings.h"
#include "coda_oss/CPlusPlus.h"

namespace types
{
namespace details
{
/*!
* \class complex_short
* \brief std::complex<short>
*
* `std::complex<short>` is no longer valid C++; provide a (partial) work-around.
* See https://en.cppreference.com/w/cpp/numeric/complex for detals.
*/
struct complex_short final
{
using value_type = short;

complex_short(value_type re = 0, value_type im = 0) : z{re, im} {}
complex_short(const complex_short&) = default;
complex_short& operator=(const complex_short&) = default;
complex_short(complex_short&&) = default;
complex_short& operator=(complex_short&&) = default;
~complex_short() = default;

value_type real() const
{
return z[0];
}
void real(value_type value)
{
z[0] = value;
}

value_type imag() const
{
return z[1];
}
void imag(value_type value)
{
z[1] = value;
}

private:
value_type z[2]{0, 0};
};
static_assert(sizeof(complex_short) == sizeof(float), "sizeof(complex_short) != sizeof(float)");

CODA_OSS_disable_warning_push
#ifdef _MSC_VER
#pragma warning(disable: 4996) // '...': warning STL4037: The effect of instantiating the template std::complex for any type other than float, double, or long double is unspecified. You can define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING to suppress this warning.
#endif

inline const std::complex<short>& cast(const complex_short& z)
{
// Getting different results with GCC vs MSVC :-( So just use
// std::complex<short> Assume by the time we're actually using C++23 with a
// compiler that enforces this restriction, "something" will be different.
const void* const pZ_ = &z;
return *static_cast<const std::complex<short>*>(pZ_);
}

CODA_OSS_disable_warning_pop

// https://en.cppreference.com/w/cpp/numeric/complex/abs
inline auto abs(const complex_short& z)
{
return abs(cast(z));
}

}

#if CODA_OSS_cpp23
using details::complex_short;
#else
// No macro to turn this on/off, want to implement what we need in details::complex_short.
// But keep in `details` in case somebody wants to uncomment.
//using complex_short = std::complex<short>; // not valid in C++23
using details::complex_short;

static_assert(sizeof(std::complex<short>) == sizeof(complex_short), "sizeof(sizeof(std::complex<short>) != sizeof(complex_short)");
#endif
}

#endif // CODA_OSS_types_complex_short_h_INCLUDED_
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* =========================================================================
* This file is part of types-c++
* =========================================================================
*
* (C) Copyright 2004 - 2017, MDA Information Systems LLC
*
* types-c++ is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* see <http://www.gnu.org/licenses/>.
*
*/

#include "TestCase.h"

#include <types/complex_short.h>

TEST_CASE(TestCxShort_abs)
{
constexpr auto real = 123;
constexpr auto imag = -321;

CODA_OSS_disable_warning_push
#ifdef _MSC_VER
#pragma warning(disable: 4996) // '...': warning STL4037: The effect of instantiating the template std::complex for any type other than float, double, or long double is unspecified. You can define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING to suppress this warning.
#endif
const std::complex<short> cx_short(real, imag);
CODA_OSS_disable_warning_pop
const auto expected = abs(cx_short);

const types::complex_short types_cx_short(real, imag);
const auto actual = abs(types_cx_short);
TEST_ASSERT_EQ(actual, expected);
}

TEST_MAIN(
TEST_CHECK(TestCxShort_abs);
)
2 changes: 1 addition & 1 deletion externals/coda-oss/modules/c++/types/wscript
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
NAME = 'types'
VERSION = '1.0'
MODULE_DEPS = 'gsl'
MODULE_DEPS = 'coda_oss config gsl coda_oss'
UNITTEST_DEPS = 'sys'

options = configure = distclean = lambda p: None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ struct DecompressionInterface final
* \class Compressor
* \brief This is the c++ interface for nitf_CompressionControl
*/
struct Decompressor final
struct Decompressor
{
Decompressor() = default;
virtual ~Decompressor() {}
Expand All @@ -145,4 +145,4 @@ struct Decompressor final

}

#endif
#endif

0 comments on commit 646b70e

Please sign in to comment.