Skip to content

Commit

Permalink
Squashed 'externals/nitro/' changes from c899f14ad..b5612a7df
Browse files Browse the repository at this point in the history
b5612a7df enable "WarningsAsErrors" for DEBUG builds
2f47cc122 Merge commit 'f067a751ac940fc485c06f003e2e2c23071a8766' into cpp17
f067a751a Squashed 'externals/coda-oss/' changes from 5015192abb..1ec9a072c4
50a3500ec Merge branch 'main' into cpp17
de4686af0 improve TRE unitesting (#599)
a4d0a5130 remove /Wall from MSVC (#598)
b97c4a867 disable pre-loaded TREs (#597)
1075b4ecd be sure the string is properly padded for the field type

git-subtree-dir: externals/nitro
git-subtree-split: b5612a7dffc1a7340da81f6390fda40e8a59e679
  • Loading branch information
Dan Smith committed Nov 15, 2023
1 parent b60fb0a commit 9188104
Show file tree
Hide file tree
Showing 45 changed files with 483 additions and 1,393 deletions.
4 changes: 3 additions & 1 deletion UnitTest/UnitTest.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include "pch.h"
#include "CppUnitTest.h"

#include <nitf/PluginRegistry.h>
#include <nitf/UnitTests.hpp>

// https://learn.microsoft.com/en-us/visualstudio/test/microsoft-visualstudio-testtools-cppunittestframework-api-reference?view=vs-2022
TEST_MODULE_INITIALIZE(methodName)
{
// module initialization code
nitf::Test::setNitfPluginPath();
nitf_PluginRegistry_PreloadedTREHandlersEnable(NRT_TRUE);
nitf::Test::j2kSetNitfPluginPath();
}
6 changes: 2 additions & 4 deletions UnitTest/UnitTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<WarningLevel>Level4</WarningLevel>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(ProjectDir);$(SolutionDir)modules\c\nrt\include;$(SolutionDir)modules\c\nitf\include;$(SolutionDir)modules\c++\nitf\include;$(SolutionDir)modules\c\j2k\include;$(SolutionDir)modules\c;$(SolutionDir)modules\c++;$(SolutionDir)externals\coda-oss\modules\c++;$(SolutionDir)externals\coda-oss\out\install\$(Platform)-$(Configuration)\include;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand All @@ -70,6 +70,7 @@
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
<UseStandardPreprocessor>true</UseStandardPreprocessor>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down Expand Up @@ -262,9 +263,6 @@
<ProjectReference Include="..\modules\c\nitf-c.vcxproj">
<Project>{f06550ad-cfc7-40b8-8727-6c82c69a8982}</Project>
</ProjectReference>
<ProjectReference Include="..\modules\c\nitf\ENGRDA.vcxproj">
<Project>{53f9f908-c678-4dee-9309-e71c1e03a45f}</Project>
</ProjectReference>
<ProjectReference Include="..\modules\c\nitf\XML_DATA_CONTENT.vcxproj">
<Project>{78849481-d356-4cc7-b182-31c21f857ed1}</Project>
</ProjectReference>
Expand Down
2 changes: 1 addition & 1 deletion UnitTest/nitf-c++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <import/nitf.hpp>
#include <nitf/UnitTests.hpp>
#include <nitf/TREField.hpp>
#include <nitf/TREsTyped.hpp>
#include <nitf/TestingTest.hpp>
#include <nitf/J2KReader.hpp>
#include <nitf/J2KWriter.hpp>
Expand Down
7 changes: 5 additions & 2 deletions externals/coda-oss/modules/c++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ set(TARGET_LANGUAGE c++)
if (MSVC)
# By default, there is a /W3 on the command-line from somewhere (?); adding
# /Wn results in a compiler warning.
#add_compile_options(/W4) # /Wall
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # /Wall
#
# https://github.com/microsoft/STL/wiki/Changelog#vs-2022-179-preview-1
# > *Note*: `/Wall` is not intended for regular production use, as it contains a large number of
# > extremely noisy and low-value warnings. In general, the STL does not attempt to be `/Wall` clean.
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # add_compile_options(/W4)

elseif (UNIX)
# https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
Expand Down
4 changes: 2 additions & 2 deletions externals/coda-oss/modules/c++/coda-oss.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>EnableAllWarnings</WarningLevel>
<WarningLevel>Level4</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions);CODA_OSS_EXPORTS;CODA_OSS_DLL;MT_DEFAULT_PINNING=0;RE_ENABLE_STD_REGEX=1</PreprocessorDefinitions>
<ForcedIncludeFiles>pch.h</ForcedIncludeFiles>
Expand Down Expand Up @@ -598,7 +598,6 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
Expand All @@ -617,6 +616,7 @@
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
<UseStandardPreprocessor>true</UseStandardPreprocessor>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
<SubSystem>
Expand Down
3 changes: 2 additions & 1 deletion externals/coda-oss/modules/c++/str/include/str/Convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ std::string toString_(const T& value)
return buf.str();
}
template <typename T>
inline auto toString(const T& value)
inline std::string toString(const T& value)
{
return toString_(value);
}
Expand Down Expand Up @@ -105,6 +105,7 @@ inline auto toString(long double value)
{
return toString_(value);
}

inline std::string toString(uint8_t value)
{
return toString(gsl::narrow<unsigned int>(value));
Expand Down
21 changes: 7 additions & 14 deletions externals/coda-oss/modules/c++/str/source/Convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,25 @@ template<> std::string str::toType<std::string>(const std::string& s)

template<> bool str::toType<bool>(const std::string& s)
{
std::string ss = s;
str::lower(ss);

if (ss == "true")
if (eq(s, "true")) // case-insensitive compare
{
return true;
}
else if (ss == "false")
if (eq(s, "false")) // case-insensitive compare
{
return false;
}
else if (str::isNumeric(ss))

// no need for lower(), digits don't have case
if (str::isNumeric(s))
{
int value(0);
std::stringstream buf(ss);
std::stringstream buf(s);
buf >> value;
return (value != 0);
}
else
{
throw except::BadCastException(except::Context(__FILE__, __LINE__,
std::string(""), std::string(""),
std::string("Invalid bool: '") + s + std::string("'")));
}

return false;
throw except::BadCastException(except::Context(__FILE__, __LINE__, "", "", "Invalid bool: '" + s + "'"));
}

long long str::strtoll(const char *str, char **endptr, int base)
Expand Down
9 changes: 6 additions & 3 deletions modules/c++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ set(TARGET_LANGUAGE c++)
# turn on warnings as errors
if (MSVC)
# By default, there is a /W3 on the command-line from somewhere (?); adding
# /W4 results in a compiler warning.
#add_compile_options(/W4) # /Wall
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # /Wall
# /Wn results in a compiler warning.
#
# https://github.com/microsoft/STL/wiki/Changelog#vs-2022-179-preview-1
# > *Note*: `/Wall` is not intended for regular production use, as it contains a large number of
# > extremely noisy and low-value warnings. In general, the STL does not attempt to be `/Wall` clean.
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # add_compile_options(/W4)

elseif (UNIX)
#add_compile_options(-Wall -pedantic -Wextra)
Expand Down
4 changes: 3 additions & 1 deletion modules/c++/nitf-c++.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
<ClInclude Include="nitf\include\nitf\TextSubheader.hpp" />
<ClInclude Include="nitf\include\nitf\TRE.hpp" />
<ClInclude Include="nitf\include\nitf\TREField.hpp" />
<ClInclude Include="nitf\include\nitf\TREsTyped.hpp" />
<ClInclude Include="nitf\include\nitf\UnitTests.hpp" />
<ClInclude Include="nitf\include\nitf\Utils.hpp" />
<ClInclude Include="nitf\include\nitf\Version.hpp" />
Expand Down Expand Up @@ -213,7 +214,7 @@
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>EnableAllWarnings</WarningLevel>
<WarningLevel>Level4</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
Expand All @@ -235,6 +236,7 @@
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
<UseStandardPreprocessor>true</UseStandardPreprocessor>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>
Expand Down
3 changes: 3 additions & 0 deletions modules/c++/nitf-c++.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -463,5 +463,8 @@
<ClInclude Include="nitf\include\nitf\UnitTests.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="nitf\include\nitf\TREsTyped.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion modules/c++/nitf/apps/show_nitf++/show_nitf++.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>EnableAllWarnings</WarningLevel>
<WarningLevel>Level4</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
Expand All @@ -68,6 +68,7 @@
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
<UseStandardPreprocessor>true</UseStandardPreprocessor>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
3 changes: 0 additions & 3 deletions modules/c++/nitf/include/nitf/TRE.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,6 @@ DECLARE_CLASS(TRE)
*/
std::string getID() const;

private:
std::string truncate(const std::string& value, size_t maxDigits) const;

mutable nitf_Error error{};
};
}
Expand Down
120 changes: 120 additions & 0 deletions modules/c++/nitf/include/nitf/TREsTyped.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/* =========================================================================
* This file is part of NITRO
* =========================================================================
*
* (C) Copyright 2004 - 2014, MDA Information Systems LLC
* © Copyright 2023, Maxar Technologies, Inc.
*
* NITRO 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, If not,
* see <http://www.gnu.org/licenses/>.
*
*/

#pragma once

#include "TREField.hpp"

// A sample (and simple) "strongly-typed" TRE; see ENGRDA in the
// unittests for something a bit more elaborate (not included because it's incomplete).
namespace nitf
{
namespace TREs
{
class TEST_DES final
{
nitf::TRE tre_;
static constexpr const char* tag = "TEST_DES";

public:
// from TRE::getID()
/**
* Get the TRE identifier. This is NOT the tag, however it may be the
* same value as the tag. The ID is used to identify a specific
* version/incarnation of the TRE, if multiple are possible. For most TREs,
* this value will be the same as the tag.
*/
TEST_DES(const std::string& id = "") noexcept(false)
: tre_(tag, id.empty() ? tag : id.c_str()),
TEST_DES_COUNT(tre_, "TEST_DES_COUNT"),
TEST_DES_START(tre_, "TEST_DES_START"),
TEST_DES_INCREMENT(tre_, "TEST_DES_INCREMENT")
{
}
~TEST_DES() = default;
TEST_DES(const TEST_DES&) = delete;
TEST_DES& operator=(const TEST_DES&) = delete;
TEST_DES(TEST_DES&&) = default;
TEST_DES& operator=(TEST_DES&&) = delete;

// From TEST_DES.c
/*
static nitf_TREDescription TEST_DES_description[] = {
{NITF_BCS_N, 2, "Number of data values", "TEST_DES_COUNT" },
{NITF_BCS_N, 3, "Start value in ramp", "TEST_DES_START" },
{NITF_BCS_N, 2, "Increment between values in ramp", "TEST_DES_INCREMENT" },
{NITF_END, 0, NULL, NULL}
};
*/
nitf::TREField_BCS_N<2> TEST_DES_COUNT;
nitf::TREField_BCS_N<3> TEST_DES_START;
nitf::TREField_BCS_N<2> TEST_DES_INCREMENT;

void updateFields()
{
tre_.updateFields();
}
};

class TEST_PRELOADED_DES final
{
nitf::TRE tre_;
static constexpr const char* tag = "TEST_PRELOADED_DES";

public:
// from TRE::getID()
/**
* Get the TRE identifier. This is NOT the tag, however it may be the
* same value as the tag. The ID is used to identify a specific
* version/incarnation of the TRE, if multiple are possible. For most TREs,
* this value will be the same as the tag.
*/
TEST_PRELOADED_DES(const std::string& id = "") noexcept(false) : tre_(tag, id.empty() ? tag : id.c_str()),
COUNT(tre_, "COUNT"), START(tre_, "START"), INCREMENT(tre_, "INCREMENT") { }
~TEST_PRELOADED_DES() = default;
TEST_PRELOADED_DES(const TEST_PRELOADED_DES&) = delete;
TEST_PRELOADED_DES& operator=(const TEST_PRELOADED_DES&) = delete;
TEST_PRELOADED_DES(TEST_PRELOADED_DES&&) = default;
TEST_PRELOADED_DES& operator=(TEST_PRELOADED_DES&&) = delete;

// From TREs.c
/*
static nitf_TREDescription TEST_PRELOADED_DES_description[] = {
{NITF_BCS_N, 2, "Number of data values", "COUNT" },
{NITF_BCS_N, 3, "Start value in ramp", "START" },
{NITF_BCS_N, 2, "Increment between values in ramp", "INCREMENT" },
{NITF_END, 0, NULL, NULL}
};
*/
nitf::TREField_BCS_N<2> COUNT;
nitf::TREField_BCS_N<3> START;
nitf::TREField_BCS_N<2> INCREMENT;

void updateFields()
{
tre_.updateFields();
}
};

} // namespace TREs
} // namespace nitf
Loading

0 comments on commit 9188104

Please sign in to comment.