Skip to content

Commit

Permalink
Squashed 'externals/coda-oss/' changes from 3bcb3d874..22a7eab30
Browse files Browse the repository at this point in the history
22a7eab30 need C++17 in this branch
99daeec9a latest from 'main'
b9ea37bbf xml::lite::Validator can be moved (#648)
9cfe9a4a8 Merge branch 'master'
e989b0910 createElement() needs to be virtual (#646)
4bdaf10d9 Change xml lite function to virtual (#645)
d17b57a54 Merge branch 'master'
fa00a5430 move debug -g flags to be turned on only if debugging (#644)
6be8f0a2e move debug -g flags to be turned on only if debugging (#644)
44ab72854 routines for simple writing to HDF5 files (#643)
aabc5818e remove more C++11 work-arounds (#642)

git-subtree-dir: externals/coda-oss
git-subtree-split: 22a7eab3010a0074ec244142bba80fc8656ebec3
  • Loading branch information
Dan Smith authored and Dan Smith committed Feb 6, 2023
1 parent ffe62b2 commit 4aa2813
Show file tree
Hide file tree
Showing 19 changed files with 523 additions and 63 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
*~
*.pyc
__pycache__/
# Build artifacts

# Build artifacts
install/
install-*/
target/
Expand All @@ -20,6 +20,7 @@ CMakeFiles/
Makefile
modules/**/Makefile
out/
CMakeSettings.json

# Waf
.waf-*
Expand Down Expand Up @@ -51,4 +52,5 @@ project.sln
**/x64/
*.vcxproj.user

CMakeSettings.json
# Unit-tests
TEST_*_TMP.*
27 changes: 15 additions & 12 deletions build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,12 +897,6 @@ def configureCompilerOptions(self):
# If you want the plugins to not depend on Intel libraries,
# configure with:
# --with-cflags=-static-intel --with-cxxflags=-static-intel --with-linkflags=-static-intel
if cxxCompiler == 'gcc':
config['cxx']['debug'] = '-ggdb3'
config['cxx']['optz_debug'] = '-Og'
elif cxxCompiler == 'icpc':
config['cxx']['debug'] = '-g'
config['cxx']['optz_debug'] = ''
if cxxCompiler == 'g++' or cxxCompiler == 'icpc':
config['cxx']['warn'] = warningFlags.split()
config['cxx']['verbose'] = '-v'
Expand Down Expand Up @@ -934,12 +928,21 @@ def configureCompilerOptions(self):

self.env.append_value('LINKFLAGS', linkFlags.split())

if ccCompiler == 'gcc':
config['cc']['debug'] = '-ggdb3'
config['cc']['optz_debug'] = '-Og'
elif ccCompiler == 'icc':
config['cc']['debug'] = '-g'
config['cc']['optz_debug'] = ''
if Options.options.debugging:
if cxxCompiler == 'g++':
config['cxx']['debug'] = '-ggdb3'
config['cxx']['optz_debug'] = '-Og'
elif cxxCompiler == 'icpc':
config['cxx']['debug'] = '-g'
config['cxx']['optz_debug'] = ''

if ccCompiler == 'gcc':
config['cc']['debug'] = '-ggdb3'
config['cc']['optz_debug'] = '-Og'
elif ccCompiler == 'icc':
config['cc']['debug'] = '-g'
config['cc']['optz_debug'] = ''

if ccCompiler == 'gcc' or ccCompiler == 'icc':
config['cc']['warn'] = warningFlags.split()
config['cc']['verbose'] = '-v'
Expand Down
14 changes: 2 additions & 12 deletions modules/c++/coda_oss/include/coda_oss/CPlusPlus.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@
#endif // __INTEL_COMPILER
#endif // CODA_OSS_cplusplus

#if CODA_OSS_cplusplus < 201402L
// oops ... try to fix
#if defined(__INTEL_COMPILER) && (__INTEL_COMPILER_BUILD_DATE >= 20151021)
// __cplusplus is 201300, not 201402L
// Enough C++14, at least with our std/ work-arounds
#undef CODA_OSS_cplusplus
#define CODA_OSS_cplusplus 201402L
#endif
#endif // CODA_OSS_cplusplus

#if CODA_OSS_cplusplus < 202002L
// oops ... try to fix
#if defined(__GNUC__) && (__cplusplus >= 201709L) // note > C++ 17 of 201703L
Expand All @@ -79,8 +69,8 @@
#define CODA_OSS_cpp20 (CODA_OSS_cplusplus >= 202002L)
#define CODA_OSS_cpp23 0

#if !CODA_OSS_cpp14
#error "Must compile with C++14 or greater."
#if !CODA_OSS_cpp17
#error "Must compile with C++17 or greater."
#endif

#endif // CODA_OSS_coda_oss_CPlusPlus_h_INCLUDED_
14 changes: 0 additions & 14 deletions modules/c++/coda_oss/include/coda_oss/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,7 @@
#include "coda_oss/namespace_.h"
namespace coda_oss
{
// workaround missing "is_trivially_copyable" in g++ < 5.0
// https://stackoverflow.com/a/31798726/8877
#if defined(__GNUC__) && (__GNUC__ < 5)
template <typename T>
struct is_trivially_copyable final
{
// This old Intel compiler has enough C++14 for our needs; see CPlusPlus.h
#if !(defined(__INTEL_COMPILER) && (__INTEL_COMPILER_BUILD_DATE <= 20151021))
static_assert(CODA_OSS_cplusplus < 201402L, "C++14 must have is_trivially_copyable.");
#endif
static constexpr bool value = __has_trivial_copy(T);
};
#else
using std::is_trivially_copyable;
#endif
}

#endif // CODA_OSS_coda_oss_type_traits_h_INCLUDED_
1 change: 1 addition & 0 deletions modules/c++/except/include/except/Backtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
namespace version { namespace except {
#if _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4619) // #pragma warning: there is no warning number '...'
#pragma warning(disable: 5264) // '...': '...' variable is not used
#endif // _MSC_VER

Expand Down
9 changes: 5 additions & 4 deletions modules/c++/hdf5.lite/include/hdf5/lite/Read.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* \file Read.h
* \brief HDF File-reading API
*
* These are simple routines to read HDF5 files; they're loosly modeled after the MATLab API
* These are simple routines to read HDF5 files; they're loosely modeled after the MATLab API
* https://www.mathworks.com/help/matlab/import_export/import-hdf5-files.html
*/

Expand All @@ -39,16 +39,17 @@
#include "sys/filesystem.h"
#include "types/RowCol.h"

#include "SpanRC.h"

namespace hdf5
{
namespace lite
{

CODA_OSS_API types::RowCol<size_t> readFile(const coda_oss::filesystem::path&, const std::string& loc, std::vector<double>&);
CODA_OSS_API types::RowCol<size_t> readFile(const coda_oss::filesystem::path&, const std::string& loc, std::vector<float>&);
CODA_OSS_API SpanRC<double> readFile(const coda_oss::filesystem::path&, const std::string& loc, std::vector<double>&);
CODA_OSS_API SpanRC<float> readFile(const coda_oss::filesystem::path&, const std::string& loc, std::vector<float>&);

}
}

#endif // CODA_OSS_hdf5_lite_Read_h_INCLUDED_

115 changes: 115 additions & 0 deletions modules/c++/hdf5.lite/include/hdf5/lite/SpanRC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/* =========================================================================
* This file is part of hdf5.lite-c++
* =========================================================================
*
* (C) Copyright 2022, Maxar Technologies, Inc.
*
* hdf5.lite-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/>.
*
*/

#ifndef CODA_OSS_hdf5_lite_SpanRC_h_INCLUDED_
#define CODA_OSS_hdf5_lite_SpanRC_h_INCLUDED_
#pragma once

/*!
* \file SpanRC.h
*
* This is a super-simple version of C++23's mdspan. It's here because 1) don't want widespread use, and
* 2) CODA already has a View2D.
*/

#include <assert.h>

#include "config/Exports.h"
#include "coda_oss/span.h"
#include "types/RowCol.h"

namespace hdf5
{
namespace lite
{

template<typename T>
struct SpanRC final
{
using size_type = types::RowCol<size_t>;
using element_type = T;
using pointer = T*;
using reference = T&;

SpanRC() = default;
SpanRC(pointer p, size_type rc) noexcept : s_(p, rc.area()), rc_(rc)
{
}
SpanRC(pointer p, size_t r, size_t c) noexcept : SpanRC(p, size_type(r, c))
{
}
SpanRC(const SpanRC&) noexcept = default;

constexpr pointer data() const noexcept
{
return s_.data();
}

/*constexpr*/ reference operator[](size_t idx) const noexcept
{
assert(idx < size()); // prevents "constexpr" in C++11
return data()[idx];
}
/*constexpr*/ reference operator()(size_t r, size_t c) const noexcept
{
const auto offset = (r * dims().col) + c;
return (*this)[offset];
}
/*constexpr*/ reference operator[](size_type idx) const noexcept
{
return (*this)(idx.row, idx.col);
}

constexpr size_t size() const noexcept
{
assert(s_.size() == rc_.area());
return s_.size();
}
constexpr size_t area() const noexcept
{
return size();
}

constexpr size_type size_bytes() const noexcept
{
return s_.size_bytes();
}

constexpr bool empty() const noexcept
{
return s_.empty();
}

const auto& dims() const
{
return rc_;
}

private:
types::RowCol<size_t> rc_;
coda_oss::span<T> s_;
};

}
}

#endif // CODA_OSS_hdf5_lite_SpanRC_h_INCLUDED_
80 changes: 80 additions & 0 deletions modules/c++/hdf5.lite/include/hdf5/lite/Write.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* =========================================================================
* This file is part of hdf5.lite-c++
* =========================================================================
*
* (C) Copyright 2023, Maxar Technologies, Inc.
*
* hdf5.lite-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/>.
*
*/

#ifndef CODA_OSS_hdf5_lite_Write_h_INCLUDED_
#define CODA_OSS_hdf5_lite_Write_h_INCLUDED_
#pragma once

/*!
* \file Read.h
* \brief HDF File-reading API
*
* These are simple routines to write HDF5 files; they're loosely modeled after the MATLab API
* https://www.mathworks.com/help/matlab/ref/h5create.html
* https://www.mathworks.com/help/matlab/ref/h5write.html
*/

#include <string>
#include <vector>

#include "config/Exports.h"
#include "sys/filesystem.h"
#include "types/RowCol.h"

#include "SpanRC.h"

namespace hdf5
{
namespace lite
{
template<typename TDataSet> // currently implemented for float and double
CODA_OSS_API void createFile(const coda_oss::filesystem::path&, const std::string& ds, const types::RowCol<size_t>&);
CODA_OSS_API void createFile(const coda_oss::filesystem::path&, const std::string& ds, SpanRC<const double>);
inline void createFile(const coda_oss::filesystem::path& path, const std::string& ds, SpanRC<double> data_)
{
SpanRC<const double> data(data_.data(), data_.dims());
createFile(path, ds, data);
}
CODA_OSS_API void createFile(const coda_oss::filesystem::path&, const std::string& ds, SpanRC<const float>);
inline void createFile(const coda_oss::filesystem::path& path, const std::string& ds, SpanRC<float> data_)
{
SpanRC<const float> data(data_.data(), data_.dims());
createFile(path, ds, data);
}

CODA_OSS_API void writeFile(const coda_oss::filesystem::path&, const std::string& loc, SpanRC<const double>);
inline void writeFile(const coda_oss::filesystem::path& path, const std::string& ds, SpanRC<double> data_)
{
SpanRC<const double> data(data_.data(), data_.dims());
writeFile(path, ds, data);
}
CODA_OSS_API void writeFile(const coda_oss::filesystem::path&, const std::string& loc, SpanRC<const float>);
inline void writeFile(const coda_oss::filesystem::path& path, const std::string& ds, SpanRC<float> data_)
{
SpanRC<const float> data(data_.data(), data_.dims());
writeFile(path, ds, data);
}

}
}

#endif // CODA_OSS_hdf5_lite_Write_h_INCLUDED_
Loading

0 comments on commit 4aa2813

Please sign in to comment.