From df247a7a9c1033496c064c6b21492f95acc282ad Mon Sep 17 00:00:00 2001 From: "J. Daniel Smith" Date: Mon, 24 Jul 2023 09:44:12 -0400 Subject: [PATCH] Squashed 'externals/coda-oss/' changes from 710754a00..a357c55b9 a357c55b9 Merge branch 'cpp17' into cpp20 17696426f Merge branch 'cpp17' into cpp20 5f3f99143 build with C++20 10756ea88 Merge branch 'cpp17' into cpp20 b028a625f Merge branch 'cpp17' into cpp20 78e40ace3 Merge branch 'cpp17' into cpp20 0fafe39ea suppress C++20-only warning d89913d55 -std=c++20 only for modules/c++ b3a55d3ed restore C++20 c17aab612 restore C++20 894afe57b Merge branch 'cpp17' into cpp20 9840e6906 Merge branch 'cpp17' into cpp20 9babe53d4 restore C++20 15337cebc Merge branch 'cpp17' into cpp20 11e472854 Merge branch 'cpp17' into cpp20 e71539d27 C++20 has 8d99186db Merge branch 'cpp17' into cpp20 61ba2a2a8 Merge branch 'cpp17' into cpp20 b0be9762c Merge branch 'cpp17' into cpp20 679725800 Merge branch 'cpp17' into cpp20 b672c0ab8 Merge branch 'cpp17' into cpp20 18d4c9c5c start over again from 'cpp17' git-subtree-dir: externals/coda-oss git-subtree-split: a357c55b98ca718cc541473f5b6b6a329044e031 --- CMakeLists.txt | 14 +- UnitTest/UnitTest.vcxproj | 8 +- build/build.py | 52 +-- build/config.guess | 2 +- modules/c++/CMakeLists.txt | 4 +- modules/c++/coda-oss.vcxproj | 9 +- modules/c++/coda-oss.vcxproj.filters | 3 - .../c++/coda_oss/include/coda_oss/CPlusPlus.h | 4 +- modules/c++/coda_oss/include/coda_oss/bit.h | 16 +- .../c++/coda_oss/include/coda_oss/cstddef.h | 2 +- .../coda_oss/include/coda_oss/namespace_.h | 2 +- .../c++/coda_oss/include/coda_oss/numbers.h | 50 +-- modules/c++/coda_oss/include/coda_oss/span.h | 51 +-- modules/c++/coda_oss/include/coda_oss/span_.h | 101 ------ .../c++/coda_oss/include/coda_oss/string.h | 15 +- .../coda_oss/include/coda_oss/type_traits.h | 2 +- modules/c++/pch.h | 1 + modules/c++/std/include/std/bit | 26 +- modules/c++/std/include/std/cstddef | 4 +- modules/c++/std/include/std/filesystem | 24 +- modules/c++/std/include/std/numbers | 24 +- modules/c++/std/include/std/optional | 8 +- modules/c++/std/include/std/span | 25 +- modules/c++/std/include/std/string | 28 +- modules/c++/sys/include/sys/filesystem.h | 47 +-- modules/c++/sys/include/sys/sys_filesystem.h | 135 +------- modules/c++/sys/source/sys_filesystem.cpp | 306 ------------------ modules/drivers/hdf5/CMakeLists.txt | 7 +- test_package/CMakeLists.txt | 2 +- 29 files changed, 110 insertions(+), 862 deletions(-) delete mode 100644 modules/c++/coda_oss/include/coda_oss/span_.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ef7c1b35..4acc001e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,9 @@ cmake_minimum_required(VERSION 3.14) project(coda-oss) -set(CMAKE_CXX_STANDARD 17) +project(coda-oss) + +set(CMAKE_CXX_STANDARD 20) set(CXX_STANDARD_REQUIRED true) if (EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") @@ -22,13 +24,9 @@ if (${CMAKE_PROJECT_NAME} STREQUAL coda-oss) # Always turn on "warnings as errors" to avoid lots of (meaningless?) build output; # we'll dial-back warnings as necessary. if (MSVC) - add_compile_options(/WX) # warnings as errors - add_compile_options(/MP) # multi-processor compile - - if (ENABLE_ASAN) - # https://docs.microsoft.com/en-us/cpp/sanitizers/asan?view=msvc-160 - add_compile_options(/fsanitize=address) - endif() + # set warning level to /W3 + string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REGEX REPLACE "/W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") elseif (UNIX) add_compile_options(-Werror) # warnings as errors diff --git a/UnitTest/UnitTest.vcxproj b/UnitTest/UnitTest.vcxproj index 28f616995..464070d17 100644 --- a/UnitTest/UnitTest.vcxproj +++ b/UnitTest/UnitTest.vcxproj @@ -71,8 +71,8 @@ true /Zc:__cplusplus %(AdditionalOptions) AdvancedVectorExtensions2 - stdcpp17 - stdc11 + stdcpp20 + stdc17 MultiThreadedDebugDLL @@ -99,8 +99,8 @@ true /Zc:__cplusplus %(AdditionalOptions) AdvancedVectorExtensions2 - stdcpp17 - stdc11 + stdcpp20 + stdc17 Windows diff --git a/build/build.py b/build/build.py index a5766d145..b04994adc 100644 --- a/build/build.py +++ b/build/build.py @@ -812,7 +812,7 @@ def options(opt): 'results. NOOP if junit_xml cannot be imported') -def ensureCpp17Support(self): +def ensureCpp20Support(self): # DEPRECATED. # Keeping for now in case downstream code is still looking for it self.env['cpp11support'] = True @@ -830,6 +830,14 @@ def configureCompilerOptions(self): if ccCompiler == 'msvc': cxxCompiler = ccCompiler + else: + if ccCompiler == 'gcc': + ccCompiler = 'gcc-10' + self.env['COMPILER_CC'] =ccCompiler + + if cxxCompiler == 'g++': + cxxCompiler = 'g++-10' + self.env['COMPILER_CXX'] = cxxCompiler if not cxxCompiler or not ccCompiler: self.fatal('Unable to find C/C++ compiler') @@ -873,7 +881,7 @@ def configureCompilerOptions(self): self.env.append_value('CFLAGS', '-fPIC -dynamiclib'.split()) # GCC / ICC (for Linux or Solaris) - elif ccCompiler == 'gcc' or ccCompiler == 'icc': + elif ccCompiler == 'gcc' or ccCompiler == 'gcc-10' or ccCompiler == 'icc': if not re.match(winRegex, sys_platform): self.env.append_value('LIB_DL', 'dl') if not re.match(osxRegex, sys_platform): @@ -883,7 +891,7 @@ def configureCompilerOptions(self): self.check_cc(lib='pthread', mandatory=True) warningFlags = '-Wall' - if ccCompiler == 'gcc': + if ccCompiler == 'gcc' or ccCompiler == 'gcc-10': #warningFlags += ' -Wno-deprecated-declarations -Wold-style-cast' warningFlags += ' -Wno-deprecated-declarations' else: @@ -897,7 +905,13 @@ 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 == 'g++' or cxxCompiler == 'icpc': + if cxxCompiler == 'gcc' or cxxCompiler == 'gcc-10': + 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 == 'g++-10' or cxxCompiler == 'icpc': config['cxx']['warn'] = warningFlags.split() config['cxx']['verbose'] = '-v' config['cxx']['64'] = '-m64' @@ -913,8 +927,7 @@ def configureCompilerOptions(self): # The "fastest-possible" option is new; see comments above. config['cxx']['optz_fastest-possible'] = [ config['cxx']['optz_faster'], '-march=native' ] # -march=native instead of haswell - self.env.append_value('CXXFLAGS', '-fPIC'.split()) - gxxCompileFlags='-std=c++17' + gxxCompileFlags='-fPIC -std=c++2a' self.env.append_value('CXXFLAGS', gxxCompileFlags.split()) # DEFINES and LINKFLAGS will apply to both gcc and g++ @@ -929,22 +942,13 @@ def configureCompilerOptions(self): self.env.append_value('LINKFLAGS', linkFlags.split()) - 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': + if ccCompiler == 'gcc' or ccCompiler == 'gcc-10': + 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 == 'gcc-10' or ccCompiler == 'icc': config['cc']['warn'] = warningFlags.split() config['cc']['verbose'] = '-v' config['cc']['64'] = '-m64' @@ -1024,7 +1028,7 @@ def configureCompilerOptions(self): '_LARGEFILE_SOURCE WIN32 _USE_MATH_DEFINES NOMINMAX WIN32_LEAN_AND_MEAN'.split() flags = '/UUNICODE /U_UNICODE /EHs /GR'.split() - flags.append('/std:c++17') + flags.append('/std:c++20') self.env.append_value('DEFINES', defines) self.env.append_value('CXXFLAGS', flags) @@ -1245,7 +1249,7 @@ def configure(self): if Options.options._defs: env.append_unique('DEFINES', Options.options._defs.split(',')) configureCompilerOptions(self) - ensureCpp17Support(self) + ensureCpp20Support(self) env['PLATFORM'] = sys_platform diff --git a/build/config.guess b/build/config.guess index c93201a4d..30646a1ad 100755 --- a/build/config.guess +++ b/build/config.guess @@ -115,7 +115,7 @@ dummy=$tmp/dummy ; tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; case $CC_FOR_BUILD,$HOST_CC,$CC in ,,) echo "int x;" > $dummy.c ; - for c in cc gcc c89 c99 ; do + for c in gcc-10 gcc c99 c89 cc; do if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then CC_FOR_BUILD="$c"; break ; fi ; diff --git a/modules/c++/CMakeLists.txt b/modules/c++/CMakeLists.txt index 2e4e7e3a1..4abfd4322 100644 --- a/modules/c++/CMakeLists.txt +++ b/modules/c++/CMakeLists.txt @@ -1,7 +1,7 @@ set(TARGET_LANGUAGE c++) if (MSVC) - add_compile_options(/std:c++17) + add_compile_options(/std:c++20) # turn on maximum warnings # By default, there is a /W3 on the command-line from somewhere (?); adding @@ -10,7 +10,7 @@ if (MSVC) string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # /Wall elseif (UNIX) - add_compile_options(-std=c++17) + add_compile_options(-std=c++20) # https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html add_compile_options(-Werror) # Make all warnings into errors diff --git a/modules/c++/coda-oss.vcxproj b/modules/c++/coda-oss.vcxproj index b662e35ba..4884f4971 100644 --- a/modules/c++/coda-oss.vcxproj +++ b/modules/c++/coda-oss.vcxproj @@ -23,7 +23,6 @@ - @@ -593,8 +592,8 @@ AdvancedVectorExtensions2 MultiThreadedDebugDLL true - stdcpp17 - stdc11 + stdcpp20 + stdc17 true @@ -623,8 +622,8 @@ true /Zc:__cplusplus %(AdditionalOptions) AdvancedVectorExtensions2 - stdcpp17 - stdc11 + stdcpp20 + stdc17 true diff --git a/modules/c++/coda-oss.vcxproj.filters b/modules/c++/coda-oss.vcxproj.filters index 3172cb27f..b09a789eb 100644 --- a/modules/c++/coda-oss.vcxproj.filters +++ b/modules/c++/coda-oss.vcxproj.filters @@ -39,9 +39,6 @@ coda_oss - - coda_oss - coda_oss diff --git a/modules/c++/coda_oss/include/coda_oss/CPlusPlus.h b/modules/c++/coda_oss/include/coda_oss/CPlusPlus.h index 8d5d6a0d3..6b6a8a78c 100644 --- a/modules/c++/coda_oss/include/coda_oss/CPlusPlus.h +++ b/modules/c++/coda_oss/include/coda_oss/CPlusPlus.h @@ -70,8 +70,8 @@ #define CODA_OSS_cpp20 (CODA_OSS_cplusplus >= 202002L) #define CODA_OSS_cpp23 (CODA_OSS_cplusplus >= 202302L) -#if !CODA_OSS_cpp17 -#error "Must compile with C++17 or greater." +#if !CODA_OSS_cpp20 +#error "Must compile with C++20 or greater." #endif #endif // CODA_OSS_coda_oss_CPlusPlus_h_INCLUDED_ diff --git a/modules/c++/coda_oss/include/coda_oss/bit.h b/modules/c++/coda_oss/include/coda_oss/bit.h index 271935ab0..a289e264f 100644 --- a/modules/c++/coda_oss/include/coda_oss/bit.h +++ b/modules/c++/coda_oss/include/coda_oss/bit.h @@ -28,24 +28,14 @@ #include // "These functions are GNU extensions." #endif +#include #include #include "coda_oss/namespace_.h" namespace coda_oss { - // https://en.cppreference.com/w/cpp/types/endian - enum class endian - { - #ifdef _WIN32 - little = 0, - big = 1, - native = little - #else - little = __ORDER_LITTLE_ENDIAN__, - big = __ORDER_BIG_ENDIAN__, - native = __BYTE_ORDER__ - #endif - }; + using std::endian; + // https://en.cppreference.com/w/cpp/numeric/byteswap namespace details diff --git a/modules/c++/coda_oss/include/coda_oss/cstddef.h b/modules/c++/coda_oss/include/coda_oss/cstddef.h index 68a7ad5dc..02b5d720b 100644 --- a/modules/c++/coda_oss/include/coda_oss/cstddef.h +++ b/modules/c++/coda_oss/include/coda_oss/cstddef.h @@ -26,7 +26,7 @@ namespace coda_oss { - using byte = std::byte; + using std::byte; } #endif // CODA_OSS_coda_oss_cstddef_h_INCLUDED_ diff --git a/modules/c++/coda_oss/include/coda_oss/namespace_.h b/modules/c++/coda_oss/include/coda_oss/namespace_.h index a00c3c2c7..5e054a3f4 100644 --- a/modules/c++/coda_oss/include/coda_oss/namespace_.h +++ b/modules/c++/coda_oss/include/coda_oss/namespace_.h @@ -18,9 +18,9 @@ * License along with this program; If not, http://www.gnu.org/licenses/. * */ +#pragma once #ifndef CODA_OSS_coda_oss_namespace__h_INCLUDED_ #define CODA_OSS_coda_oss_namespace__h_INCLUDED_ -#pragma once namespace coda_oss { diff --git a/modules/c++/coda_oss/include/coda_oss/numbers.h b/modules/c++/coda_oss/include/coda_oss/numbers.h index 698bb042d..e4388303f 100644 --- a/modules/c++/coda_oss/include/coda_oss/numbers.h +++ b/modules/c++/coda_oss/include/coda_oss/numbers.h @@ -22,62 +22,16 @@ #ifndef CODA_OSS_coda_oss_numbers_h_INCLUDED_ #define CODA_OSS_coda_oss_numbers_h_INCLUDED_ -#ifndef _USE_MATH_DEFINES -#define _USE_MATH_DEFINES // get M_PI, etc. -#endif -#include -/* -#define M_E 2.71828182845904523536 // e -#define M_LOG2E 1.44269504088896340736 // log2(e) -#define M_LOG10E 0.434294481903251827651 // log10(e) -#define M_LN2 0.693147180559945309417 // ln(2) -#define M_LN10 2.30258509299404568402 // ln(10) -#define M_PI 3.14159265358979323846 // pi -#define M_PI_2 1.57079632679489661923 // pi/2 -#define M_PI_4 0.785398163397448309616 // pi/4 -#define M_1_PI 0.318309886183790671538 // 1/pi -#define M_2_PI 0.636619772367581343076 // 2/pi -#define M_2_SQRTPI 1.12837916709551257390 // 2/sqrt(pi) -#define M_SQRT2 1.41421356237309504880 // sqrt(2) -#define M_SQRT1_2 0.707106781186547524401 // 1/sqrt(2) -*/ +#include namespace coda_oss { - namespace numbers { -// https://en.cppreference.com/w/cpp/header/numbers -template constexpr T e_v = static_cast(M_E); -template constexpr T log2e_v = static_cast(M_LOG2E); -template constexpr T log10e_v = static_cast(M_LOG10E); -template constexpr T pi_v = static_cast(M_PI); -template constexpr T inv_pi_v = static_cast(M_1_PI); -//template constexpr T inv_sqrtpi_v = static_cast(); -template constexpr T ln2_v = static_cast(M_LN2); -template constexpr T ln10_v = static_cast(M_LN10); -template constexpr T sqrt2_v = static_cast(M_SQRT2); -//template constexpr T sqrt3_v = static_cast(); -//template constexpr T inv_sqrt3_v = static_cast(); -//template constexpr T egamma_v = static_cast(); -//template constexpr T phi_v = static_cast(); +using namespace std::numbers; -constexpr double e = e_v; -constexpr double log2e = log2e_v; -constexpr double log10e = log10e_v; -constexpr double pi = pi_v; -constexpr double inv_pi = inv_pi_v; -//constexpr double inv_sqrtpi = inv_sqrtpi_v; -constexpr double ln2 = ln2_v; -constexpr double ln10 = ln10_v; -constexpr double sqrt2 = sqrt2_v; -//constexpr double sqrt3 = sqrt3_v; -//constexpr double inv_sqrt3 = inv_sqrt3_v; -//constexpr double egamma = egamma_v; -//constexpr double phi = phi_v; } - } #endif // CODA_OSS_coda_oss_numbers_h_INCLUDED_ diff --git a/modules/c++/coda_oss/include/coda_oss/span.h b/modules/c++/coda_oss/include/coda_oss/span.h index 6aff3b5d5..9ed4c007b 100644 --- a/modules/c++/coda_oss/include/coda_oss/span.h +++ b/modules/c++/coda_oss/include/coda_oss/span.h @@ -23,56 +23,15 @@ #ifndef CODA_OSS_coda_oss_span_h_INCLUDED_ #define CODA_OSS_coda_oss_span_h_INCLUDED_ -#include - -#include - -#include "coda_oss/namespace_.h" -#include "coda_oss/span_.h" -#include "coda_oss/cstddef.h" // byte - -// Need a fairly decent C++ compiler to use the real GSL. This brings in more than -// we really need for span (e.g., gsl::narrow()), but it keeps things simple. -#include "gsl/gsl.h" // not gsl/span; need #pragma here to turn off warnings +#include namespace coda_oss { -#if defined(GSL_SPAN_H) // the above #include'd gsl/span - using gsl::span; -#else // no gsl::span, use our own - using details::span; -#endif // GSL_SPAN_H - -// https://en.cppreference.com/w/cpp/container/span/as_bytes -template -inline auto as_bytes(span s) noexcept -{ - // https://en.cppreference.com/w/cpp/types/is_trivially_copyable "... serialized to/from binary files ..." - static_assert(std::is_trivially_copyable::value, "must be 'trivially' copyable."); - - const void* const p_ = s.data(); - auto const p = static_cast(p_); - return span(p, s.size_bytes()); -} -template -inline auto as_bytes(span s) noexcept -{ - const span s_(s.data(), s.size()); - return as_bytes(s_); -} -template -inline span as_writable_bytes(span s) noexcept -{ - // https://en.cppreference.com/w/cpp/types/is_trivially_copyable "... serialized to/from binary files ..." - static_assert(std::is_trivially_copyable::value, "must be 'trivially' copyable."); - - static_assert(!std::is_const::value, "T cannot be 'const'"); - - void* const p_ = s.data(); - auto const p = static_cast(p_); - return span(p, s.size_bytes()); -} + using std::span; + // https://en.cppreference.com/w/cpp/container/span/as_bytes + using std::as_bytes; + using std::as_writable_bytes; } #endif // CODA_OSS_coda_oss_span_h_INCLUDED_ diff --git a/modules/c++/coda_oss/include/coda_oss/span_.h b/modules/c++/coda_oss/include/coda_oss/span_.h deleted file mode 100644 index fa32901d2..000000000 --- a/modules/c++/coda_oss/include/coda_oss/span_.h +++ /dev/null @@ -1,101 +0,0 @@ -/* ========================================================================= - * This file is part of coda_oss-c++ - * ========================================================================= - * - * (C) Copyright 2004 - 2014, MDA Information Systems LLC - * - * coda_oss-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 . - * - */ -#ifndef CODA_OSS_coda_oss_span__h_INCLUDED_ -#define CODA_OSS_coda_oss_span__h_INCLUDED_ -#pragma once - -#include -#include - -namespace coda_oss -{ -namespace details -{ -// super-simple version of std::span -// https://en.cppreference.com/w/cpp/container/span -template -struct span final -{ - using size_type = size_t; - using element_type = T; - using pointer = T*; - using reference = T&; - - span() noexcept = default; - span(pointer p, size_type sz) noexcept : p_(p), sz_(sz) - { - assert(p != nullptr); - } - span(const span&) noexcept = default; - - // https://en.cppreference.com/w/cpp/container/span/data - constexpr pointer data() const noexcept - { - return p_; - } - - // https://en.cppreference.com/w/cpp/container/span/operator_at - /*constexpr*/ reference operator[](size_type idx) const noexcept - { - assert(idx < size()); // prevents "constexpr" in C++11 - return data()[idx]; - } - - // https://en.cppreference.com/w/cpp/container/span/size - constexpr size_type size() const noexcept - { - return sz_; - } - - // https://en.cppreference.com/w/cpp/container/span/size_bytes - constexpr size_type size_bytes() const noexcept - { - return sz_ * sizeof(element_type); - } - - // https://en.cppreference.com/w/cpp/container/span/empty - constexpr bool empty() const noexcept - { - return size() == 0; - } - - using iterator = pointer; - // https://en.cppreference.com/w/cpp/container/span/begin - constexpr iterator begin() const noexcept - { - return data(); - } - - // https://en.cppreference.com/w/cpp/container/span/end - constexpr iterator end() const noexcept - { - return begin() + size(); - } - -private: - pointer p_ = nullptr; - size_type sz_ = 0; -}; -} -} - -#endif // CODA_OSS_coda_oss_span__h_INCLUDED_ diff --git a/modules/c++/coda_oss/include/coda_oss/string.h b/modules/c++/coda_oss/include/coda_oss/string.h index 0eeb73ef0..cb0cd4c13 100644 --- a/modules/c++/coda_oss/include/coda_oss/string.h +++ b/modules/c++/coda_oss/include/coda_oss/string.h @@ -20,27 +20,16 @@ * */ +#pragma once #ifndef CODA_OSS_coda_oss_string_h_INCLUDED_ #define CODA_OSS_coda_oss_string_h_INCLUDED_ -#pragma once #include -#include "config/compiler_extensions.h" - #include "coda_oss/namespace_.h" namespace coda_oss { - // char8_t for UTF-8 characters - CODA_OSS_disable_warning_push - #if _MSC_VER - #pragma warning(disable: 5052) // Keyword '...' was introduced in C++20 and requires use of the '...' command-line option - #endif - #if !defined(__cpp_char8_t) // https://en.cppreference.com/w/cpp/feature_test - enum class char8_t : unsigned char { }; // https://en.cppreference.com/w/cpp/language/types - #endif - using u8string = std::basic_string; // https://en.cppreference.com/w/cpp/string - CODA_OSS_disable_warning_pop + using std::u8string; } #endif // CODA_OSS_coda_oss_string_h_INCLUDED_ diff --git a/modules/c++/coda_oss/include/coda_oss/type_traits.h b/modules/c++/coda_oss/include/coda_oss/type_traits.h index a5a3df63a..f95ff49fa 100644 --- a/modules/c++/coda_oss/include/coda_oss/type_traits.h +++ b/modules/c++/coda_oss/include/coda_oss/type_traits.h @@ -18,9 +18,9 @@ * License along with this program; If not, http://www.gnu.org/licenses/. * */ +#pragma once #ifndef CODA_OSS_coda_oss_type_traits_h_INCLUDED_ #define CODA_OSS_coda_oss_type_traits_h_INCLUDED_ -#pragma once #include diff --git a/modules/c++/pch.h b/modules/c++/pch.h index 26ba3ed05..965213612 100644 --- a/modules/c++/pch.h +++ b/modules/c++/pch.h @@ -98,6 +98,7 @@ CODA_OSS_disable_warning_pop #pragma warning(disable: 26458) // Prefer to use gsl::at() instead of unchecked subscript operator (bounds.4). #pragma warning(disable: 26482) // Only index into arrays using constant expressions (bounds.2). #pragma warning(disable: 26481) // Don't use pointer arithmetic. Use span instead (bounds.1). +#pragma warning(disable: 26821) // For '...', consider using gsl::span instead of std::span to guarantee runtime bounds safety (gsl.view). // Yes, these are our files ... but they don't change very often, and if they do // change we want to rebuild everything anyway. diff --git a/modules/c++/std/include/std/bit b/modules/c++/std/include/std/bit index dbcc0b6c5..a26eecef3 100644 --- a/modules/c++/std/include/std/bit +++ b/modules/c++/std/include/std/bit @@ -18,35 +18,15 @@ * License along with this program; If not, http://www.gnu.org/licenses/. * */ +#pragma once #ifndef CODA_OSS_std_bit_INCLUDED_ #define CODA_OSS_std_bit_INCLUDED_ -#pragma once + +#include #include "coda_oss/bit.h" #include "coda_oss/CPlusPlus.h" -// Make it (too?) easy for clients to get our various std:: implementations -#ifndef CODA_OSS_NO_std_endian - #if CODA_OSS_cpp20 - // Some implementations claim to be C++20 w/o - #if __has_include() // __has_include is C++17 - #include - #define CODA_OSS_NO_std_endian 1 // provided by implementation, probably C++20 - #endif - #endif - // At this point, CODA_OSS_NO_std_endian will be set only if we were able to successfully use (above) - #ifndef CODA_OSS_NO_std_endian - #define CODA_OSS_NO_std_endian 0 // <= C++17, use our own - #endif -#endif - -#if !CODA_OSS_NO_std_endian -namespace std // This is slightly uncouth: we're not supposed to augment "std". -{ - using coda_oss::endian; -} -#endif // CODA_OSS_NO_std_endian - // Make it (too?) easy for clients to get our various std:: implementations #ifndef CODA_OSS_NO_std_byteswap #if CODA_OSS_cpp23 diff --git a/modules/c++/std/include/std/cstddef b/modules/c++/std/include/std/cstddef index 794d21efb..01bfcdd31 100644 --- a/modules/c++/std/include/std/cstddef +++ b/modules/c++/std/include/std/cstddef @@ -18,10 +18,10 @@ * License along with this program; If not, http://www.gnu.org/licenses/. * */ -#pragma once +#pragma once #ifndef CODA_OSS_std_cstddef_INCLUDED_ #define CODA_OSS_std_cstddef_INCLUDED_ #include -#endif // CODA_OSS_std_cstddef_INCLUDED_ \ No newline at end of file +#endif // CODA_OSS_std_cstddef_INCLUDED_ diff --git a/modules/c++/std/include/std/filesystem b/modules/c++/std/include/std/filesystem index 4804550ae..4003fa017 100644 --- a/modules/c++/std/include/std/filesystem +++ b/modules/c++/std/include/std/filesystem @@ -18,31 +18,11 @@ * License along with this program; If not, http://www.gnu.org/licenses/. * */ +#pragma once #ifndef CODA_OSS_std_filesystem_INCLUDED_ #define CODA_OSS_std_filesystem_INCLUDED_ -#pragma once +#include #include "sys/filesystem.h" -#include "coda_oss/CPlusPlus.h" - -// Make it (too?) easy for clients to get our various std:: implementations -#ifndef CODA_OSS_NO_std_filesystem - #if CODA_OSS_cpp17 - // Some versions of G++ say they're C++17 but don't have - #if __has_include() // __has_include is C++17 - #include - #define CODA_OSS_NO_std_filesystem 1 // part of C++17 - #endif - #else - #define CODA_OSS_NO_std_filesystem 0 // use our own - #endif -#endif - -#if !CODA_OSS_NO_std_filesystem -namespace std // This is slightly uncouth: we're not supposed to augment "std". -{ - namespace filesystem = coda_oss::filesystem; -} -#endif // !CODA_OSS_NO_std_filesystem #endif // CODA_OSS_std_filesystem_INCLUDED_ \ No newline at end of file diff --git a/modules/c++/std/include/std/numbers b/modules/c++/std/include/std/numbers index e089df22b..26a14d891 100644 --- a/modules/c++/std/include/std/numbers +++ b/modules/c++/std/include/std/numbers @@ -22,28 +22,6 @@ #ifndef CODA_OSS_std_numbers_INCLUDED_ #define CODA_OSS_std_numbers_INCLUDED_ -#include "coda_oss/numbers.h" -#include "coda_oss/CPlusPlus.h" - - // Make it (too?) easy for clients to get our various std:: implementations -#ifndef CODA_OSS_NO_std_numbers - #if CODA_OSS_cpp20 - #include - #define CODA_OSS_NO_std_numbers 1 // provided by implementation, probably C++20 - #endif - #ifndef CODA_OSS_NO_std_numbers - #define CODA_OSS_NO_std_numbers 0 // <= C++20, use our own - #endif -#endif - -#if !CODA_OSS_NO_std_numbers -namespace std // This is slightly uncouth: we're not supposed to augment "std". -{ -namespace numbers -{ - using namespace coda_oss::numbers; -} -} -#endif // CODA_OSS_NO_std_numbers +#include #endif // CODA_OSS_std_numbers_INCLUDED_ diff --git a/modules/c++/std/include/std/optional b/modules/c++/std/include/std/optional index 54345783f..60dacfead 100644 --- a/modules/c++/std/include/std/optional +++ b/modules/c++/std/include/std/optional @@ -1,10 +1,10 @@ /* ========================================================================= - * This file is part of std-c++ + * This file is part of sys-c++ * ========================================================================= * * (C) Copyright 2021, Maxar Technologies, Inc. * - * std-c++ is free software; you can redistribute it and/or modify + * sys-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. @@ -18,10 +18,10 @@ * License along with this program; If not, http://www.gnu.org/licenses/. * */ -#pragma once +#pragma once #ifndef CODA_OSS_std_optional_INCLUDED_ #define CODA_OSS_std_optional_INCLUDED_ #include -#endif // CODA_OSS_std_optional_INCLUDED_ \ No newline at end of file +#endif // CODA_OSS_std_optional_INCLUDED_ diff --git a/modules/c++/std/include/std/span b/modules/c++/std/include/std/span index 819befe15..6b78ea9bb 100644 --- a/modules/c++/std/include/std/span +++ b/modules/c++/std/include/std/span @@ -18,31 +18,10 @@ * License along with this program; If not, http://www.gnu.org/licenses/. * */ +#pragma once #ifndef CODA_OSS_std_span_INCLUDED_ #define CODA_OSS_std_span_INCLUDED_ -#pragma once -#include "coda_oss/span.h" -#include "coda_oss/CPlusPlus.h" - -// Make it (too?) easy for clients to get our various std:: implementations -#ifndef CODA_OSS_NO_std_span - #if CODA_OSS_cpp20 - #include - #define CODA_OSS_NO_std_span 1 // part of C++20 - #else - #define CODA_OSS_NO_std_span 0 // use our own - #endif -#endif - -#if !CODA_OSS_NO_std_span -namespace std // This is slightly uncouth: we're not supposed to augment "std". -{ - using coda_oss::span; - - using coda_oss::as_bytes; - using coda_oss::as_writable_bytes; -} -#endif // CODA_OSS_DEFINE_std_span_ +#include #endif // CODA_OSS_std_span_INCLUDED_ \ No newline at end of file diff --git a/modules/c++/std/include/std/string b/modules/c++/std/include/std/string index e740a42f2..f8360a0e1 100644 --- a/modules/c++/std/include/std/string +++ b/modules/c++/std/include/std/string @@ -18,36 +18,10 @@ * License along with this program; If not, http://www.gnu.org/licenses/. * */ +#pragma once #ifndef CODA_OSS_std_string_INCLUDED_ #define CODA_OSS_std_string_INCLUDED_ -#pragma once #include -#include "coda_oss/string.h" -#include "coda_oss/CPlusPlus.h" - -// Make it (too?) easy for clients to get our various std:: implementations -#ifndef CODA_OSS_NO_std_u8string - #if CODA_OSS_cpp20 - #define CODA_OSS_NO_std_u8string 1 // part of C++20 - #else - #define CODA_OSS_NO_std_u8string 0 // use our own - #endif -#endif - -#if !CODA_OSS_NO_std_u8string -#include "config/compiler_extensions.h" -namespace std // This is slightly uncouth: we're not supposed to augment "std". -{ - CODA_OSS_disable_warning_push - #if defined(_MSC_VER) && (_MSC_VER >= 1927) - #pragma warning(disable: 5052) // Keyword '...' was introduced in C++ 20 and requires use of the '...' command-line option - #endif - using char8_t = coda_oss::char8_t; - CODA_OSS_disable_warning_pop - - using coda_oss::u8string; -} -#endif // !CODA_OSS_NO_std_u8string #endif // CODA_OSS_std_string_INCLUDED_ \ No newline at end of file diff --git a/modules/c++/sys/include/sys/filesystem.h b/modules/c++/sys/include/sys/filesystem.h index a42a40e1e..479532f23 100644 --- a/modules/c++/sys/include/sys/filesystem.h +++ b/modules/c++/sys/include/sys/filesystem.h @@ -18,47 +18,30 @@ * License along with this program; If not, http://www.gnu.org/licenses/. * */ +#pragma once #ifndef CODA_OSS_sys_filesystem_h_INCLUDED_ #define CODA_OSS_sys_filesystem_h_INCLUDED_ -#pragma once + +#include // always implement sys::filesystem::path #include "sys/sys_filesystem.h" -#include "sys/CPlusPlus.h" -#if CODA_OSS_cpp17 - // Some versions of G++ say they're C++17 but don't have - #if __has_include() // __has_include is C++17 - #include - #define CODA_OSS_has_std_filesystem_ 1 - #endif -#else - #define CODA_OSS_has_std_filesystem_ 0 -#endif - +#include "coda_oss/namespace_.h" namespace coda_oss { - // Allow coda_oss::filesystem to compile; used in .h files - namespace filesystem - { - #if CODA_OSS_has_std_filesystem_ - #define CODA_OSS_coda_oss_filesystem_impl_ std - #else - #define CODA_OSS_coda_oss_filesystem_impl_ sys - #endif - using CODA_OSS_coda_oss_filesystem_impl_::filesystem::file_type; - using CODA_OSS_coda_oss_filesystem_impl_::filesystem::path; +namespace filesystem +{ + +using std::filesystem::path; +using std::filesystem::file_type; - using CODA_OSS_coda_oss_filesystem_impl_::filesystem::absolute; - using CODA_OSS_coda_oss_filesystem_impl_::filesystem::create_directory; - using CODA_OSS_coda_oss_filesystem_impl_::filesystem::current_path; - using CODA_OSS_coda_oss_filesystem_impl_::filesystem::remove; - using CODA_OSS_coda_oss_filesystem_impl_::filesystem::temp_directory_path; - using CODA_OSS_coda_oss_filesystem_impl_::filesystem::is_regular_file; - using CODA_OSS_coda_oss_filesystem_impl_::filesystem::is_directory; - using CODA_OSS_coda_oss_filesystem_impl_::filesystem::exists; - using CODA_OSS_coda_oss_filesystem_impl_::filesystem::file_size; - } +using std::filesystem::current_path; +using std::filesystem::exists; +using std::filesystem::is_directory; +using std::filesystem::is_regular_file; + +} } #endif // CODA_OSS_sys_filesystem_h_INCLUDED_ diff --git a/modules/c++/sys/include/sys/sys_filesystem.h b/modules/c++/sys/include/sys/sys_filesystem.h index 59df476a5..37bd740a2 100644 --- a/modules/c++/sys/include/sys/sys_filesystem.h +++ b/modules/c++/sys/include/sys/sys_filesystem.h @@ -22,129 +22,24 @@ #define CODA_OSS_sys_sys_filesystem_h_INCLUDED_ #pragma once -// -// For now, these are just some wrappers around the CODA-OSS routines ... -// eventually, this should be replaced with C++17's . -// -// This does not even TRY to be a complete implementation of std::filesystem. -// +#include -#include -#include -#include - -#include "sys/CPlusPlus.h" -#include "coda_oss/namespace_.h" // get something in the "coda_oss" namespace -#include "config/Exports.h" - -namespace sys // should be in coda_oss/, but implementation needs sys::Path -{ -// http://en.cppreference.com/w/cpp/filesystem -namespace filesystem // not "Filesystem", make it easy to use code in other namespaces +namespace sys { - struct path; // forward - namespace details - { - CODA_OSS_API bool Equals(const path& lhs, const path& rhs) noexcept; - CODA_OSS_API std::ostream& Ostream(std::ostream& os, const path& p); - } - - // https://en.cppreference.com/w/cpp/filesystem/file_type - enum class file_type // match C++17 spelling for easier transition from our C++11 work-around - { - none = 0, - not_found = 1, - regular, - directory, - unknown - }; - -// http://en.cppreference.com/w/cpp/filesystem/path -struct CODA_OSS_API path final // N.B. this is an INCOMPLETE and NON-STANDARD implementation! +namespace filesystem { - // character type used by the native encoding of the filesystem: char on POSIX, wchar_t on Windows - #ifdef _WIN32 - using value_type = wchar_t; - #else - using value_type = char; - #endif - using string_type = std::basic_string; - - // http://en.cppreference.com/w/cpp/filesystem/path/path - path() noexcept; - path(const path&); - path(const string_type&); - template - path(const TSource& source) - { - *this = source; - } - - path& operator=(const path&) = default; - path& operator=(path&&) = default; - template - path& operator=(const TSource& source) - { - p_ = to_native(source); - return *this; - } - - path& operator/=(const path&); // http://en.cppreference.com/w/cpp/filesystem/path/append - template - path& operator/=(const TSource& source) // http://en.cppreference.com/w/cpp/filesystem/path/append - { - return (*this) /= path(to_native(source)); - } - void clear() noexcept; // http://en.cppreference.com/w/cpp/filesystem/path/clear - - // http://en.cppreference.com/w/cpp/filesystem/path/native - const value_type* c_str() const noexcept; - const string_type& native() const noexcept; - operator string_type() const; - - std::string string() const; // http://en.cppreference.com/w/cpp/filesystem/path/string - - path root_path() const; // https://en.cppreference.com/w/cpp/filesystem/path/root_path - path parent_path() const; // http://en.cppreference.com/w/cpp/filesystem/path/parent_path - path filename() const; // http://en.cppreference.com/w/cpp/filesystem/path/filename - path stem() const; // http://en.cppreference.com/w/cpp/filesystem/path/stem - path extension() const; // https://en.cppreference.com/w/cpp/filesystem/path/extension - - bool empty() const noexcept; // http://en.cppreference.com/w/cpp/filesystem/path/empty - bool is_absolute() const; // http://en.cppreference.com/w/cpp/filesystem/path/is_absrel - bool is_relative() const; // http://en.cppreference.com/w/cpp/filesystem/path/is_absrel - - CODA_OSS_API friend bool operator==(const path& lhs, const path& rhs) noexcept // https://en.cppreference.com/w/cpp/filesystem/path/operator_cmp - { - return details::Equals(lhs, rhs); - } - CODA_OSS_API friend bool operator!=(const path& lhs, const path& rhs) noexcept // https://en.cppreference.com/w/cpp/filesystem/path/operator_cmp - { - return !(lhs == rhs); - } - CODA_OSS_API friend std::ostream& operator<<(std::ostream& os, const path& p) // https://en.cppreference.com/w/cpp/filesystem/path/operator_ltltgtgt - { - return details::Ostream(os, p); - } - -private: - string_type p_; - static string_type to_native(const std::string& s); -}; - -CODA_OSS_API path operator/(const path& lhs, const path& rhs); // http://en.cppreference.com/w/cpp/filesystem/path/operator_slash - -CODA_OSS_API path absolute(const path&); // http://en.cppreference.com/w/cpp/filesystem/absolute -CODA_OSS_API bool create_directory(const path&); // https://en.cppreference.com/w/cpp/filesystem/create_directory -CODA_OSS_API path current_path(); // https://en.cppreference.com/w/cpp/filesystem/current_path -CODA_OSS_API bool remove(const path& p); // https://en.cppreference.com/w/cpp/filesystem/remove -CODA_OSS_API path temp_directory_path(); // https://en.cppreference.com/w/cpp/filesystem/temp_directory_path - -CODA_OSS_API bool is_regular_file(const path& p); // https://en.cppreference.com/w/cpp/filesystem/is_regular_file -CODA_OSS_API bool is_directory(const path& p); // https://en.cppreference.com/w/cpp/filesystem/is_directory -CODA_OSS_API bool exists(const path& p); // https://en.cppreference.com/w/cpp/filesystem/exists -CODA_OSS_API std::uintmax_t file_size(const path& p); // https://en.cppreference.com/w/cpp/filesystem/file_size - + using std::filesystem::file_type; + using std::filesystem::path; + + using std::filesystem::absolute; + using std::filesystem::create_directory; + using std::filesystem::current_path; + using std::filesystem::exists; + using std::filesystem::is_directory; + using std::filesystem::is_regular_file; + using std::filesystem::remove; + using std::filesystem::temp_directory_path; + using std::filesystem::file_size; } } diff --git a/modules/c++/sys/source/sys_filesystem.cpp b/modules/c++/sys/source/sys_filesystem.cpp index 95f968896..8d91933a7 100644 --- a/modules/c++/sys/source/sys_filesystem.cpp +++ b/modules/c++/sys/source/sys_filesystem.cpp @@ -1,307 +1 @@ #include "sys/sys_filesystem.h" - -#include -#ifdef _WIN32 -#include -#else -#include -#endif - -#include -#include -#include -#include -#include -#include - -#include "sys/Path.h" -#include "gsl/gsl.h" -#include "str/EncodedString.h" - -namespace fs = sys::filesystem; - -static inline std::string strerror_(int errnum) -{ -#ifdef _MSC_VER - std::array errmsg; - strerror_s(errmsg.data(), errmsg.size(), errnum); - return errmsg.data(); -#else - return ::strerror(errnum); -#endif -} - -static inline std::string make_what(const char* curfile, const int lineNum, const std::string& msg) -{ - std::ostringstream what; - what << "ERROR: " << curfile << ", Line " << lineNum << ": " << msg; - return what.str(); -} -static inline std::string make_what(const char* curfile, const int lineNum, const std::ostringstream& msg) -{ - return make_what(curfile, lineNum, msg.str()); -} -// A macro for conveniently throwing errors. -// Need "throw" to be visible, not hidden inside of a function, so that code-analysis tools can see it. -#define CODA_OSS_sys_filesystem_THROW_ERR(MSG) throw std::runtime_error(make_what(__FILE__, __LINE__, MSG)) // TODO: std::filesystem_error - -fs::path::string_type fs::path::to_native(const std::string& s_) -{ - -#ifdef _WIN32 - return str::EncodedStringView(s_).wstring(); -#else - return s_; -#endif -} - -fs::path::path() noexcept -{ -} -fs::path::path(const path& p) : p_(p.native()) -{ -} -fs::path::path(const string_type& p) : p_(p) -{ -} - -fs::path& fs::path::operator/=(const path& p) -{ - // https://en.cppreference.com/w/cpp/filesystem/path/append - - if (p.is_absolute()) // || (p.has_root_name() && p.root_name() != root_name()) - { - p_ = p.native(); // "If p.is_absolute() ... replaces the current path with p ..." - } - else - { - // TODO: there is more to do here ... see http://en.cppreference.com/w/cpp/filesystem/path/append - p_ = to_native(sys::Path::joinPaths(string(), p.string())); - } - - return *this; -} - -void fs::path::clear() noexcept -{ - p_.clear(); -} - -const fs::path::value_type* fs::path::c_str() const noexcept -{ - return native().c_str(); -} - -const fs::path::string_type& fs::path::native() const noexcept -{ - return p_; -} - -fs::path::operator string_type() const -{ - return native(); -} - -std::string fs::path::string() const -{ - return str::EncodedString(p_).native(); -} - -fs::path fs::path::root_path() const -{ - return parent_path() / stem(); -} - -fs::path fs::path::parent_path() const -{ - return sys::Path::splitPath(string()).first; -} - -fs::path fs::path::filename() const -{ - return sys::Path::basename(string(), false /*rmvExt*/); -} - -fs::path fs::path::stem() const -{ - return sys::Path::basename(string(), true /*rmvExt*/); -} - -fs::path fs::path::extension() const -{ - // https://en.cppreference.com/w/cpp/filesystem/path/extension - - // "If the pathname is either . or .., ... then empty path is returned." - const auto pathname = string(); - if ((pathname == ".") || (pathname == "..")) - { - return fs::path(); - } - - auto fn = filename().string(); - const auto dot = fn.find("."); - - // "If ... filename() does not contain the . character, then empty path is returned." - if (dot == std::string::npos) - { - return fs::path(); - } - - // "If the first character in the filename is a period, that period is ignored - // (a filename like '.profile' is not treated as an extension)" - if (dot == 0) - { - fn = fn.substr(1); - } - - return sys::Path::splitExt(fn).second; -} - -bool fs::path::empty() const noexcept -{ - return native().empty(); -} - -bool fs::path::is_absolute() const -{ - return sys::Path::isAbsolutePath(string()); -} -bool fs::path::is_relative() const -{ - return !is_absolute(); // "... the other way round." http://en.cppreference.com/w/cpp/filesystem/path/is_absrel -} - -fs::path fs::operator/(const fs::path& lhs, const fs::path& rhs) -{ - return fs::path(lhs) /= rhs; // "... returns path(lhs) /= rhs." http://en.cppreference.com/w/cpp/filesystem/path/operator_slash -} - -fs::path fs::absolute(const path& p) -{ - return sys::Path::absolutePath(p.string()); -} - -fs::path fs::temp_directory_path() -{ - // https://en.cppreference.com/w/cpp/filesystem/temp_directory_path - // - // On POSIX systems, the path may be the one specified in the environment variables TMPDIR, TMP, TEMP, TEMPDIR, and, if none of them are - // specified, the path "/tmp" is returned. - // - // On Windows systems, the path is typically the one returned by GetTempPath -#if defined(_WIN32) - - // https://msdn.microsoft.com/en-us/library/b0084kay.aspx - // "_WIN32 Defined as 1 when the compilation target is 32 - bit ARM, 64 - bit ARM, x86, or x64.Otherwise, undefined." - - // https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-gettemppatha - std::array buf; // "The maximum possible return value is MAX_PATH+1 (261)." - const auto result = GetTempPathA(static_cast(buf.size()), buf.data()); - if (result == 0) // "If the function fails, the return value is zero" - { - CODA_OSS_sys_filesystem_THROW_ERR("GetTempPathA() failed."); - } - - return buf.data(); - -#else // assume Linux - - // https://stackoverflow.com/questions/31068/how-do-i-find-the-temp-directory-in-linux - const std::vector tmpdirs{"TMPDIR", "TMP", "TEMP", "TEMPDIR"}; - for (const auto& dir : tmpdirs) - { - if (auto result = getenv(dir)) - { - return result; - } - } - - return "/tmp"; -#endif -} - -bool fs::create_directory(const path& p_) -{ - const sys::OS os; - const auto p = p_.string(); - const bool created = os.makeDirectory(p); - if (created) - { - // If it exists, see if it's a file - if (os.isFile(p)) - { - const std::string stat_failed("stat failed: " + p); - const std::string error("Error:\n" + strerror_(errno)); - CODA_OSS_sys_filesystem_THROW_ERR(stat_failed + "\n" + error); - } - else if (!os.isDirectory(p)) - { - std::stringstream ss; - ss << "Path '" << p << "' exists and is not a directory."; - CODA_OSS_sys_filesystem_THROW_ERR(ss.str()); - } - - // If we got here, the path exists and is a directory, which is what we want - } - return created; -} - -bool fs::is_regular_file(const path& p) -{ - const sys::OS os; - return os.isFile(p.string()); -} - -bool fs::is_directory(const path& p) -{ - const sys::OS os; - return os.isDirectory(p.string()); -} - -bool fs::exists(const path& p) -{ - const sys::OS os; - return os.exists(p.string()); -} - -bool fs::remove(const path& p_) -{ - // https://en.cppreference.com/w/cpp/io/c/remove - const auto p = p_.string(); - return ::remove(p.c_str()) == 0; // "0 upon success or non-zero value on error." -} - -fs::path fs::current_path() -{ - // https://en.cppreference.com/w/cpp/filesystem/current_path - - // https://stackoverflow.com/questions/2203159/is-there-a-c-equivalent-to-getcwd - char temp[1024]; - return -#ifdef _WIN32 - _getcwd -#else - getcwd -#endif - (temp, sizeof(temp)) - ? std::string(temp) - : std::string(); -} - -std::uintmax_t fs::file_size(const fs::path& p) -{ - const sys::Path path(p.string()); - return gsl::narrow (path.length()); -} - -bool fs::details::Equals(const path& lhs, const path& rhs) noexcept -{ - return sys::Path::normalizePath(lhs.string()) == sys::Path::normalizePath(rhs.string()); -} - -std::ostream& fs::details::Ostream(std::ostream& os, const path& p) -{ - // https://en.cppreference.com/w/cpp/filesystem/path/operator_ltltgtgt - os << "\"" << p.string() << "\""; - return os; -} diff --git a/modules/drivers/hdf5/CMakeLists.txt b/modules/drivers/hdf5/CMakeLists.txt index dd8c01d3f..406eb8411 100644 --- a/modules/drivers/hdf5/CMakeLists.txt +++ b/modules/drivers/hdf5/CMakeLists.txt @@ -2,12 +2,7 @@ set(MODULE_NAME hdf5) set(TARGET_LANGUAGE c++) if(CODA_ENABLE_HDF5) - # set up warnings - if (MSVC) - # DO NOT use standard (not legacy) C pre-processor - add_compile_options(/Zc:preprocessor-) - endif() - + set(TARGET_LANGUAGE c++) coda_add_module(${MODULE_NAME} VERSION 1.13.2) else() message("${MODULE_NAME} will not be built since HDF5 is not enabled") diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt index be886e92a..f3c77f2c9 100644 --- a/test_package/CMakeLists.txt +++ b/test_package/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.14) project(coda-oss-test_package) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 20) set(CXX_STANDARD_REQUIRED true) include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")