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 committed Nov 15, 2023
1 parent 79b590e commit 24bc1a7
Show file tree
Hide file tree
Showing 35 changed files with 592 additions and 200 deletions.
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 @@ -564,7 +564,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 @@ -593,7 +593,6 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
Expand All @@ -609,6 +608,7 @@
<ConformanceMode>true</ConformanceMode>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
<SubSystem>
Expand Down
1 change: 1 addition & 0 deletions externals/coda-oss/modules/c++/str/include/str/Convert.h
Original file line number Diff line number Diff line change
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
4 changes: 3 additions & 1 deletion externals/nitro/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();
}
5 changes: 1 addition & 4 deletions externals/nitro/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 Down Expand Up @@ -258,9 +258,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 externals/nitro/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
9 changes: 6 additions & 3 deletions externals/nitro/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 externals/nitro/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 @@ -232,6 +233,7 @@
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>
Expand Down
3 changes: 3 additions & 0 deletions externals/nitro/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>
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 @@ -65,6 +65,7 @@
<SupportJustMyCode>true</SupportJustMyCode>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
3 changes: 0 additions & 3 deletions externals/nitro/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 externals/nitro/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
38 changes: 36 additions & 2 deletions externals/nitro/modules/c++/nitf/source/TRE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static bool endsWith(const std::string& s, const std::string& match) noexcept
return sLen >= mLen;
}

std::string TRE::truncate(const std::string& value, size_t maxDigits) const
static std::string truncate(const std::string& value, size_t maxDigits)
{
const size_t decimalIndex = value.find('.');
if (decimalIndex == std::string::npos)
Expand All @@ -184,6 +184,40 @@ std::string TRE::truncate(const std::string& value, size_t maxDigits) const
}
return value;
}
static std::string truncate(const nitf_Field& field, const std::string& value)
{
auto retval = truncate(value, field.length);

// From Field.h
if (field.type == NITF_BCS_A)
{
// is BCS-A data, it is space-filled, right-aligned.
while (retval.length() < field.length)
{
// copyAndFillSpaces() in Field.c "Spaces are added to the right"
retval += " ";
}
}
else if (field.type == NITF_BCS_N)
{
const auto decimalIndex = retval.find('.');

// If it is BCS-N, we expect zero-filled, left-aligned.
while (retval.length() < field.length)
{
if (decimalIndex == std::string::npos)
{
retval = "0" + retval;
}
else
{
retval += "0";
}
}
}

return retval;
}

void TRE::setFieldValue(const std::string& key, const void* data, size_t dataLength, bool forceUpdate)
{
Expand All @@ -207,7 +241,7 @@ void TRE::setFieldValue(const nitf_Field& field, const std::string& key, const s
else
{
// call truncate() first
const auto s = truncate(data, field.length);
const auto s = truncate(field, data);
setFieldValue(key, s.c_str(), s.size(), forceUpdate);
}
}
Expand Down
2 changes: 1 addition & 1 deletion externals/nitro/modules/c++/nitf/source/UnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ static std::string buildPluginName(const std::string& base)
void nitf::Test::setNitfPluginPath()
{
// The name of the plugin we know exists and will always be built, see test_load_plugins
static const auto p = getNitfPluginPath(buildPluginName("ENGRDA"));
static const auto p = getNitfPluginPath(buildPluginName("TEST_DES"));
sys::OS().setEnv("NITF_PLUGIN_PATH", p.string(), true /*overwrite*/);
}

Expand Down
Loading

0 comments on commit 24bc1a7

Please sign in to comment.