diff --git a/.github/matrix.json b/.github/matrix.json index 5c816d1f..d8d10c63 100644 --- a/.github/matrix.json +++ b/.github/matrix.json @@ -5,40 +5,52 @@ "compiler": "gcc", "version": "11", "os": "ubuntu-22.04", - "cxxstd" : "17" + "cxxstd": "17" }, { "name": "Linux GCC 11 C++20", "compiler": "gcc", "version": "11", "os": "ubuntu-22.04", - "cxxstd" : "20" + "cxxstd": "20" }, { "name": "Linux Clang 14 C++17", "compiler": "clang", "version": "14", "os": "ubuntu-22.04", - "cxxstd" : "17" + "cxxstd": "17" }, { "name": "Linux Clang 14 C++20", "compiler": "clang", "version": "14", "os": "ubuntu-22.04", - "cxxstd" : "20" + "cxxstd": "20" }, { - "name": "macOS apple-clang 14.3.1", + "name": "macOS apple-clang 14.3.1 C++17", "compiler": "apple-clang", "version": "14.3.1", "os": "macos-13", - "cxxstd" : "17" + "cxxstd": "17" }, { - "name": "Windows VS2022", + "name": "macOS apple-clang 14.3.1 C++20", + "compiler": "apple-clang", + "version": "14.3.1", + "os": "macos-13", + "cxxstd": "20" + }, + { + "name": "Windows VS2022 C++17", + "os": "windows-2022", + "cxxstd": "17" + }, + { + "name": "Windows VS2022 C++20", "os": "windows-2022", - "cxxstd" : "17" + "cxxstd": "20" } ] } diff --git a/.github/workflows/adobe_source_libraries.yml b/.github/workflows/adobe_source_libraries.yml index ae3390d8..ebb99466 100644 --- a/.github/workflows/adobe_source_libraries.yml +++ b/.github/workflows/adobe_source_libraries.yml @@ -15,7 +15,7 @@ jobs: outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Generate job matrix id: set-matrix @@ -32,7 +32,7 @@ jobs: name: ${{ matrix.config.name }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install dependencies (macos) if: ${{ startsWith(matrix.config.os, 'macos') }} @@ -109,7 +109,7 @@ jobs: shell: bash run: | mkdir ../build - cmake -S. -B../build -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 + cmake -S. -B../build -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=${{matrix.config.cxxstd}} - name: Configure (Windows) if: ${{ startsWith(matrix.config.os, 'windows') }} @@ -117,7 +117,7 @@ jobs: run: | call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64 mkdir ..\build - cmake -S. -B../build -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DBOOST_TEST_DYN_LINK=TRUE + cmake -S. -B../build -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=${{matrix.config.cxxstd}} -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DBOOST_TEST_DYN_LINK=TRUE - name: Build (Unix) if: ${{ startsWith(matrix.config.os, 'ubuntu') || startsWith(matrix.config.os, 'macos') }} diff --git a/.gitignore b/.gitignore index aa473714..ae52965e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ gh-pages/ documentation/doxyfile.bak build_asl/ +.vs/ +.vscode/ diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json deleted file mode 100644 index f0ac00d4..00000000 --- a/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "configurations": [ - { - "name": "Mac", - "includePath": [ - "${workspaceFolder}/**" - ], - "defines": [], - "macFrameworkPath": [ - "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks" - ], - "compilerPath": "/usr/bin/clang++", - "cStandard": "c17", - "cppStandard": "c++17", - "intelliSenseMode": "macos-clang-arm64", - "compileCommands": "${workspaceFolder}/build/compile_commands.json" - } - ], - "version": 4 -} diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index f58b1676..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,136 +0,0 @@ -{ - "files.associations": { - "*.cpp": "cpp", - "__bit_reference": "cpp", - "__bits": "cpp", - "__config": "cpp", - "__debug": "cpp", - "__errc": "cpp", - "__hash_table": "cpp", - "__locale": "cpp", - "__mutex_base": "cpp", - "__node_handle": "cpp", - "__split_buffer": "cpp", - "__threading_support": "cpp", - "__tree": "cpp", - "__tuple": "cpp", - "__verbose_abort": "cpp", - "array": "cpp", - "atomic": "cpp", - "bit": "cpp", - "bitset": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "complex": "cpp", - "condition_variable": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "exception": "cpp", - "fstream": "cpp", - "future": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "ios": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "list": "cpp", - "locale": "cpp", - "map": "cpp", - "memory": "cpp", - "mutex": "cpp", - "new": "cpp", - "optional": "cpp", - "ostream": "cpp", - "queue": "cpp", - "ratio": "cpp", - "set": "cpp", - "sstream": "cpp", - "stack": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "string": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "thread": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "typeinfo": "cpp", - "unordered_map": "cpp", - "variant": "cpp", - "vector": "cpp", - "__nullptr": "cpp", - "__string": "cpp", - "chrono": "cpp", - "compare": "cpp", - "concepts": "cpp", - "numeric": "cpp", - "random": "cpp", - "algorithm": "cpp", - "filesystem": "cpp", - "cfenv": "cpp", - "csignal": "cpp", - "strstream": "cpp", - "typeindex": "cpp", - "hash_map": "cpp", - "any": "cpp", - "barrier": "cpp", - "charconv": "cpp", - "cinttypes": "cpp", - "codecvt": "cpp", - "coroutine": "cpp", - "csetjmp": "cpp", - "execution": "cpp", - "format": "cpp", - "forward_list": "cpp", - "functional": "cpp", - "iterator": "cpp", - "latch": "cpp", - "memory_resource": "cpp", - "numbers": "cpp", - "ranges": "cpp", - "regex": "cpp", - "scoped_allocator": "cpp", - "semaphore": "cpp", - "shared_mutex": "cpp", - "source_location": "cpp", - "span": "cpp", - "stop_token": "cpp", - "syncstream": "cpp", - "unordered_set": "cpp", - "utility": "cpp", - "valarray": "cpp", - "xfacet": "cpp", - "xhash": "cpp", - "xiosbase": "cpp", - "xlocale": "cpp", - "xlocbuf": "cpp", - "xlocinfo": "cpp", - "xlocmes": "cpp", - "xlocmon": "cpp", - "xlocnum": "cpp", - "xloctime": "cpp", - "xmemory": "cpp", - "xstddef": "cpp", - "xstring": "cpp", - "xtr1common": "cpp", - "xtree": "cpp", - "xutility": "cpp", - "*.ipp": "cpp", - "*.tcc": "cpp", - "rope": "cpp", - "slist": "cpp", - "print": "cpp" - }, - "C_Cpp.default.compilerPath": "/usr/bin/clang++" -} diff --git a/CMakeLists.txt b/CMakeLists.txt index f8c6d5a0..2f1cf0fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.29) include(FindGit) include(CMakeParseArguments) enable_testing() @@ -7,8 +7,7 @@ project(adobe_source_libraries CXX) set(CMAKE_CXX_EXTENSIONS OFF) if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 17) - set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++17") + set(CMAKE_CXX_STANDARD 20) endif(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") diff --git a/CMakePresets.json b/CMakePresets.json index fc2d88bb..e3f2e4f4 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -3,12 +3,38 @@ "configurePresets": [ { "name": "debug", - "displayName": "Custom configure preset", + "displayName": "debug-windows", "description": "Sets Ninja generator, build and install directory", "generator": "Ninja", "binaryDir": "${sourceDir}/build/${presetName}", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_CXX_STANDARD": "20", + "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", + "VCPKG_TARGET_TRIPLET": "x64-windows" + }, + "architecture": { + "value": "x64", + "strategy": "external" + }, + "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "vendor": { + "microsoft.com/VisualStudioSettings/CMake/1.0": { + "hostOS": [ + "Windows" + ] + } + } + }, + { + "name": "debug-windows-cpp17", + "displayName": "debug-windows-cpp17", + "description": "Sets Ninja generator, build and install directory", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_CXX_STANDARD": "17", "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", "VCPKG_TARGET_TRIPLET": "x64-windows" }, @@ -16,10 +42,12 @@ "value": "x64", "strategy": "external" }, - "toolchainFile": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake", + "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", "vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { - "hostOS": [ "Windows" ] + "hostOS": [ + "Windows" + ] } } }, @@ -36,7 +64,9 @@ }, "vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { - "hostOS": [ "macOS" ] + "hostOS": [ + "macOS" + ] } } }, @@ -53,14 +83,16 @@ }, "vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { - "hostOS": [ "macOS" ] + "hostOS": [ + "macOS" + ] } } } ], "buildPresets": [ { - "name": "debug", + "name": "debug-windows", "description": "", "displayName": "", "configurePreset": "debug" diff --git a/adobe/algorithm/append.hpp b/adobe/algorithm/append.hpp new file mode 100644 index 00000000..9f95849d --- /dev/null +++ b/adobe/algorithm/append.hpp @@ -0,0 +1,32 @@ +/* + Copyright 2024 Adobe + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +*/ +/**************************************************************************************************/ + +#ifndef ADOBE_ALGORITHM_APPEND_HPP +#define ADOBE_ALGORITHM_APPEND_HPP + +#include + +/**************************************************************************************************/ + +namespace adobe { + +/**************************************************************************************************/ + +/// Insert the elements of _input_range_ `r` at the end of the _sequence container_ `c`, +/// returning the position corresponding to the incoming `end` of `c`. +template +inline auto append(T& c, const R& r) { + return c.insert(std::end(c), std::begin(r), std::end(r)); +} + +/**************************************************************************************************/ + +} // namespace adobe + +/**************************************************************************************************/ + +#endif diff --git a/adobe/algorithm/generate.hpp b/adobe/algorithm/generate.hpp index 60a4f3b3..b5290c5a 100644 --- a/adobe/algorithm/generate.hpp +++ b/adobe/algorithm/generate.hpp @@ -10,10 +10,8 @@ #include -#include -#include - #include +#include /**************************************************************************************************/ @@ -35,7 +33,7 @@ namespace adobe { */ template inline void generate(ForwardRange& range, Generator gen) { - std::generate(boost::begin(range), boost::end(range), gen); + std::generate(std::begin(range), std::end(range), gen); } /**************************************************************************************************/ diff --git a/adobe/algorithm/unique.hpp b/adobe/algorithm/unique.hpp index 3f12c03d..e44be0b6 100644 --- a/adobe/algorithm/unique.hpp +++ b/adobe/algorithm/unique.hpp @@ -10,11 +10,11 @@ #include -#include -#include - #include #include +#include + +#include /**************************************************************************************************/ @@ -36,8 +36,8 @@ namespace adobe { \brief unique implementation */ template -inline typename boost::range_iterator::type unique(ForwardRange& range) { - return std::unique(boost::begin(range), boost::end(range)); +inline auto unique(ForwardRange& range) { + return std::unique(std::begin(range), std::end(range)); } /*! @@ -56,9 +56,9 @@ inline ForwardIterator unique(ForwardIterator first, ForwardIterator last, Binar \brief unique implementation */ template -inline typename boost::range_iterator::type unique(ForwardRange& range, +inline auto unique(ForwardRange& range, BinaryPredicate pred) { - return adobe::unique(boost::begin(range), boost::end(range), pred); + return adobe::unique(std::begin(range), std::end(range), pred); } /*! @@ -68,7 +68,7 @@ inline typename boost::range_iterator::type unique(ForwardRange& r */ template inline OutputIterator unique_copy(InputRange& range, OutputIterator result) { - return std::unique_copy(boost::begin(range), boost::end(range), result); + return std::unique_copy(std::begin(range), std::end(range), result); } /*! @@ -78,7 +78,7 @@ inline OutputIterator unique_copy(InputRange& range, OutputIterator result) { */ template inline OutputIterator unique_copy(const InputRange& range, OutputIterator result) { - return std::unique_copy(boost::begin(range), boost::end(range), result); + return std::unique_copy(std::begin(range), std::end(range), result); } /*! @@ -100,7 +100,7 @@ inline OutputIterator unique_copy(InputIterator first, InputIterator last, Outpu */ template inline OutputIterator unique_copy(InputRange& range, OutputIterator result, BinaryPredicate pred) { - return adobe::unique_copy(boost::begin(range), boost::end(range), result, pred); + return adobe::unique_copy(std::begin(range), std::end(range), result, pred); } /*! @@ -111,7 +111,14 @@ inline OutputIterator unique_copy(InputRange& range, OutputIterator result, Bina template inline OutputIterator unique_copy(const InputRange& range, OutputIterator result, BinaryPredicate pred) { - return adobe::unique_copy(boost::begin(range), boost::end(range), result, pred); + return adobe::unique_copy(std::begin(range), std::end(range), result, pred); +} + +/// Sorts the _sequence container_ `c` and erases all but one matching element. +template +inline void sort_unique(T& c) { + sort(c); + c.erase(unique(c), std::end(c)); } /**************************************************************************************************/ diff --git a/adobe/array.hpp b/adobe/array.hpp index bb3e91bb..2a3b87ab 100644 --- a/adobe/array.hpp +++ b/adobe/array.hpp @@ -35,6 +35,9 @@ inline void push_back(array_t& v, any_regular_t x) { v.push_back(std::move(x)); #ifdef ADOBE_STD_SERIALIZATION +// To be findable by ADL, the operator must be in the same namespace as `any_regular_t.` +namespace version_1 { + inline std::ostream& operator<<(std::ostream& out, const array_t& x) { out << begin_sequence; @@ -46,6 +49,8 @@ inline std::ostream& operator<<(std::ostream& out, const array_t& x) { return out; } +} // namespace version_1 + #endif /**************************************************************************************************/ diff --git a/adobe/exception.hpp b/adobe/exception.hpp new file mode 100644 index 00000000..9f10dd9c --- /dev/null +++ b/adobe/exception.hpp @@ -0,0 +1,33 @@ +/* + Copyright 2013 Adobe + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +*/ +/**************************************************************************************************/ + +#ifndef ADOBE_EXCEPTION_HPP +#define ADOBE_EXCEPTION_HPP + +#include + +/**************************************************************************************************/ + +namespace adobe { + +/**************************************************************************************************/ + +/// invoke `std::terminate` with the given message in `what()` for the current exception. The +/// message can be retrieved in a terminate handler and is reported by the default terminate +/// handler. +[[noreturn]] void terminate(const char*); +[[noreturn]] void terminate(const std::string&); + +/**************************************************************************************************/ + +} // namespace adobe + +/**************************************************************************************************/ + +#endif + +/**************************************************************************************************/ diff --git a/adobe/implementation/toroid.hpp b/adobe/implementation/toroid.hpp index 69c93501..537214bd 100644 --- a/adobe/implementation/toroid.hpp +++ b/adobe/implementation/toroid.hpp @@ -227,7 +227,7 @@ class byte_toroid_t : boost::noncopyable { void purify(toroid_node_t* p) { toroid_header_t* c(column_of(p)); - int x(p->color_m); + auto x(p->color_m); c->color_m = x; @@ -248,7 +248,7 @@ class byte_toroid_t : boost::noncopyable { void unpurify(toroid_node_t* p) { toroid_header_t* c(column_of(p)); - int x(p->color_m); + auto x(p->color_m); for (toroid_node_t* rr = up_of(c); rr != c; rr = up_of(rr)) { if (rr->color_m < 0) { diff --git a/adobe/iomanip.hpp b/adobe/iomanip.hpp index 4cd4f1c2..d4ce64ee 100644 --- a/adobe/iomanip.hpp +++ b/adobe/iomanip.hpp @@ -16,6 +16,8 @@ #include +#include + #include #include #include @@ -24,12 +26,13 @@ #include #include -#include +#include + #include #include #include -#include + /**************************************************************************************************/ diff --git a/adobe/json.hpp b/adobe/json.hpp index ff8adb4a..1dda1424 100644 --- a/adobe/json.hpp +++ b/adobe/json.hpp @@ -200,11 +200,10 @@ class json_parser { frac(); exp(); - const auto p_len = p_ - p; char* p_end = nullptr; double value = std::strtod(p, &p_end); require(std::isfinite(value), "finite number"); - ADOBE_ASSERT(p_len == (p_end - p) && "std::strtod() failure"); + ADOBE_ASSERT((p_ - p) == (p_end - p) && "std::strtod() failure"); t = value_type(value); diff --git a/adobe/json_helper.hpp b/adobe/json_helper.hpp index 2ff734ba..79a9530f 100644 --- a/adobe/json_helper.hpp +++ b/adobe/json_helper.hpp @@ -11,7 +11,9 @@ #include #include #include +#include #include +#include /**************************************************************************************************/ @@ -56,7 +58,7 @@ struct asl_json_helper_t { else if (type == typeid(adobe::empty_t)) return json_type::null; - ADOBE_ASSERT(false && "invalid type for serialization"); + terminate(ADOBE_MESSAGE("invalid type for serialization")); } template diff --git a/adobe/macro_utilities.hpp b/adobe/macro_utilities.hpp new file mode 100644 index 00000000..4bbd01db --- /dev/null +++ b/adobe/macro_utilities.hpp @@ -0,0 +1,31 @@ +/* + Copyright 2012 Adobe Systems Incorporated + Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt + or a copy at http://stlab.adobe.com/licenses.html) +*/ + +/**************************************************************************************************/ + +#ifndef ADOBE_MACRO_UTILITIES_HPP + +/// turns `x` into a string literal. +#define ADOBE_STRINGIZE(x) \ + ADOBE_DETAIL_STRINGIZE2(x) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define ADOBE_DETAIL_STRINGIZE2(x) #x // NOLINT(cppcoreguidelines-macro-usage) + + +/// a string literal for __LINE__. +#define ADOBE_LINE_STRING() ADOBE_STRINGIZE(__LINE__) // NOLINT(cppcoreguidelines-macro-usage) + +/// Expands to a [GNU error formatted](https://www.gnu.org/prep/standards/standards.html#Errors) +/// string literal reporting `message` at the line where it is invoked. +/// +/// - Requires: `message` is a string literal. +#define ADOBE_MESSAGE(message) \ + __FILE__ ":" ADOBE_LINE_STRING() ": " message // NOLINT(cppcoreguidelines-macro-usage) + +/**************************************************************************************************/ + +#endif + +/**************************************************************************************************/ diff --git a/adobe/manip.hpp b/adobe/manip.hpp index 8b32451c..acb77cea 100644 --- a/adobe/manip.hpp +++ b/adobe/manip.hpp @@ -22,7 +22,6 @@ namespace adobe { - /**************************************************************************************************/ /*! diff --git a/adobe/serializable.hpp b/adobe/serializable.hpp index 21e4ddd1..1781bfc6 100644 --- a/adobe/serializable.hpp +++ b/adobe/serializable.hpp @@ -14,13 +14,16 @@ #include #include -#include #include +#include + /**************************************************************************************************/ namespace adobe { + #if __cplusplus < 202002L + /**************************************************************************************************/ namespace implementation { @@ -63,10 +66,10 @@ template inline typename std::enable_if::value>::type ostream_insertion(std::ostream&, const T&) {} -#else // __cplusplus < 202002L +#else // __cplusplus < 202002L template -void ostream_insertion(std::ostream& s, const T& x) { +inline void ostream_insertion(std::ostream& s, const T& x) { if constexpr (requires { s << x; }) { s << x; } @@ -110,7 +113,7 @@ class serializable_t { serializable_t(serializable_t&& x) : instance_m(x.instance_m.release()) {} - void operator()(std::ostream& s) const { object()(s); } + void operator()(std::ostream& s) const { object()._out(s); } const std::type_info& type_info() const { return object().type_info(); } @@ -121,7 +124,7 @@ class serializable_t { if (type != typeid(T)) throw bad_cast(type, typeid(T)); - return static_cast(reinterpret_cast&>(object()).object_m); + return static_cast&>(object()).object_m; } template @@ -135,19 +138,21 @@ class serializable_t { virtual instance_t* _copy() const = 0; - virtual void operator()(std::ostream& s) const = 0; + virtual void _out(std::ostream& s) const = 0; virtual const std::type_info& type_info() const = 0; }; template - struct instance : instance_t { + struct instance final : instance_t { explicit instance(T x) : object_m(std::move(x)) {} - instance_t* _copy() const { return new instance(object_m); } + instance_t* _copy() const override { return new instance(object_m); } - void operator()(std::ostream& s) const { serialize()(s, object_m); } + void _out(std::ostream& s) const override { + ostream_insertion(s, object_m); + } - const std::type_info& type_info() const { return typeid(T); } + const std::type_info& type_info() const override { return typeid(T); } T object_m; }; diff --git a/adobe/sha.hpp b/adobe/sha.hpp index 08801a63..ebf1194a 100644 --- a/adobe/sha.hpp +++ b/adobe/sha.hpp @@ -17,6 +17,8 @@ #include #include +#include + /**************************************************************************************************/ namespace adobe { @@ -239,8 +241,9 @@ std::uint64_t stuff_into_state(typename HashTraits::message_block_type& state, v <<= message_end - 8; *dst |= v; - stuff_bit_offset += num_bits; - n_stuffed_bits += num_bits; + ADOBE_ASSERT(num_bits < 8); + stuff_bit_offset += static_cast(num_bits); + n_stuffed_bits += static_cast(num_bits); } return n_stuffed_bits; } @@ -309,8 +312,8 @@ void block_and_digest(typename HashTraits::message_block_type& state, std::uint1 template struct shift_down { - void operator()(message_block_type& state, std::uint64_t message_size, - typename message_block_type::value_type value_type_mask) const {} + void operator()(message_block_type&, std::uint64_t, + typename message_block_type::value_type) const {} }; template diff --git a/adobe/task.hpp b/adobe/task.hpp index f44116da..cc9d5605 100644 --- a/adobe/task.hpp +++ b/adobe/task.hpp @@ -11,21 +11,19 @@ /**************************************************************************************************/ -#include -#include - #if defined(_MSC_VER) #include #else +#include #include -#include #include #include #include -#include +#include +#include #endif diff --git a/adobe/type_traits.hpp b/adobe/type_traits.hpp index 0327ac27..a9026bb5 100644 --- a/adobe/type_traits.hpp +++ b/adobe/type_traits.hpp @@ -10,6 +10,9 @@ #ifndef ADOBE_TYPE_TRAITS_HPP #define ADOBE_TYPE_TRAITS_HPP +#include + +/**************************************************************************************************/ namespace adobe { @@ -27,4 +30,6 @@ using invoke_result_t = std::invoke_result_t; } // namespace adobe +/**************************************************************************************************/ + #endif // include guard diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 94ab77e1..29381cd5 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -22,6 +22,14 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR target_compile_options(asl PUBLIC -ftemplate-depth=1024) endif() + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + target_compile_options (asl PUBLIC "/DNOMINMAX") + target_compile_options (asl PUBLIC "/permissive-") + target_compile_options (asl PUBLIC "/Zc:__cplusplus") + target_compile_options (asl PRIVATE "/W4") + target_compile_options (asl PRIVATE "/WX") +endif() + target_link_boost(asl) # thread linking diff --git a/source/adam.cpp b/source/adam.cpp index 1add418a..335888d3 100644 --- a/source/adam.cpp +++ b/source/adam.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -345,6 +346,28 @@ class sheet_t::implementation_t : boost::noncopyable { priority_t name_to_priority(name_t name) const; void flow(cell_bits_t& priority_accessed); + /// Returns the output cell with the given name. + /// + /// \pre A cell with that name exists. + cell_t& output_cell(const name_t& name) { + auto p = output_index_m.find(name); + assert(p != output_index_m.end() && "output cell not found"); + return *p; + } + const cell_t& output_cell(const name_t& name) const { + auto p = output_index_m.find(name); + assert(p != output_index_m.end() && "output cell not found"); + return *p; + } + + /// Returns whether any output cells in the relation are resolved. + bool resolved(const relation_t& relation) const { + return find_if(relation.name_set_m, [&](const auto& name) { + return output_cell(name).resolved_m; + }) != relation.name_set_m.end(); + } + + /* NOTE (sparent) : cell_t contains boost::signals2::signal<> which is not copyable. The cells support @@ -717,10 +740,10 @@ void sheet_t::implementation_t::add_input(name_t name, const line_position_t& po void sheet_t::implementation_t::add_output(name_t name, const line_position_t& position, const array_t& expression) { // REVISIT (sparent) : Non-transactional on failure. - cell_set_m.push_back(cell_t(access_output, name, - std::bind(&implementation_t::calculate_expression, - std::ref(*this), position, expression), - cell_set_m.size(), nullptr)); + cell_set_m.push_back(cell_t( + access_output, name, + std::bind(&implementation_t::calculate_expression, std::ref(*this), position, expression), + cell_set_m.size(), nullptr)); output_index_m.insert(cell_set_m.back()); @@ -744,11 +767,10 @@ void sheet_t::implementation_t::add_interface(name_t name, bool linked, scope_value_t scope(initialize_mode_m, true); if (initializer_expression.size()) { - cell_set_m.push_back( - cell_t(name, linked, - std::bind(&implementation_t::calculate_expression, std::ref(*this), - position1, initializer_expression), - cell_set_m.size())); + cell_set_m.push_back(cell_t(name, linked, + std::bind(&implementation_t::calculate_expression, + std::ref(*this), position1, initializer_expression), + cell_set_m.size())); } else { cell_set_m.push_back(cell_t(name, linked, cell_t::calculator_t(), cell_set_m.size())); } @@ -763,7 +785,7 @@ void sheet_t::implementation_t::add_interface(name_t name, bool linked, // REVISIT (sparent) : Non-transactional on failure. cell_set_m.push_back(cell_t(access_interface_output, name, std::bind(&implementation_t::calculate_expression, - std::ref(*this), position2, expression), + std::ref(*this), position2, expression), cell_set_m.size(), &cell_set_m.back())); } else { cell_set_m.push_back(cell_t(access_interface_output, name, @@ -831,10 +853,10 @@ void sheet_t::implementation_t::add_constant(name_t name, any_regular_t value) { void sheet_t::implementation_t::add_logic(name_t logic, const line_position_t& position, const array_t& expression) { - cell_set_m.push_back(cell_t(access_logic, logic, - std::bind(&implementation_t::calculate_expression, - std::ref(*this), position, expression), - cell_set_m.size(), nullptr)); + cell_set_m.push_back(cell_t( + access_logic, logic, + std::bind(&implementation_t::calculate_expression, std::ref(*this), position, expression), + cell_set_m.size(), nullptr)); if (!name_index_m.insert(cell_set_m.back()).second) { throw stream_error_t(make_string("cell named '", logic.c_str(), "'already exists."), @@ -847,10 +869,10 @@ void sheet_t::implementation_t::add_logic(name_t logic, const line_position_t& p void sheet_t::implementation_t::add_invariant(name_t name, const line_position_t& position, const array_t& expression) { // REVISIT (sparent) : Non-transactional on failure. - cell_set_m.push_back(cell_t(access_invariant, name, - std::bind(&implementation_t::calculate_expression, - std::ref(*this), position, expression), - cell_set_m.size(), nullptr)); + cell_set_m.push_back(cell_t( + access_invariant, name, + std::bind(&implementation_t::calculate_expression, std::ref(*this), position, expression), + cell_set_m.size(), nullptr)); output_index_m.insert(cell_set_m.back()); @@ -878,8 +900,7 @@ void sheet_t::implementation_t::add_relation(const line_position_t& position, cell_set.insert(cell_set.end(), first->name_set_m.begin(), first->name_set_m.end()); } - sort(cell_set); - cell_set.erase(unique(cell_set), cell_set.end()); + sort_unique(cell_set); for (vector::iterator f = cell_set.begin(), l = cell_set.end(); f != l; ++f) { index_t::iterator p = output_index_m.find(*f); @@ -936,7 +957,7 @@ sheet_t::connection_t sheet_t::implementation_t::monitor_enabled(name_t n, const (touch_set & priority_accessed_m).any())); return monitor_enabled_m.connect(std::bind(&sheet_t::implementation_t::enabled_filter, this, - touch_set, iter->cell_set_pos_m, monitor, _1, _2)); + touch_set, iter->cell_set_pos_m, monitor, _1, _2)); } /**************************************************************************************************/ @@ -988,8 +1009,8 @@ sheet_t::implementation_t::monitor_contributing(name_t n, const dictionary_t& ma monitor(contributing_set(mark, iter->contributing_m)); return iter->monitor_contributing_m.connect( - std::bind(monitor, std::bind(&sheet_t::implementation_t::contributing_set, - std::ref(*this), mark, _1))); + std::bind(monitor, std::bind(&sheet_t::implementation_t::contributing_set, std::ref(*this), + mark, _1))); } /**************************************************************************************************/ @@ -1018,13 +1039,11 @@ priority_t sheet_t::implementation_t::name_to_priority(name_t name) const { void sheet_t::implementation_t::flow(cell_bits_t& priority_accessed) { // Generate the set of cells connected to unresolved relations vector cells; - for (relation_cell_set_t::iterator f(relation_cell_set_m.begin()), l(relation_cell_set_m.end()); - f != l; ++f) { - if (!f->resolved_m) - cells.insert(cells.end(), f->edges_m.begin(), f->edges_m.end()); + for (const auto& relation : relation_cell_set_m) { + if (!relation.resolved_m) + append(cells, relation.edges_m); } - sort(cells); - cells.erase(unique(cells), cells.end()); + sort_unique(cells); // sort the cells by priority sort(cells, less(), &cell_t::priority); @@ -1033,8 +1052,8 @@ void sheet_t::implementation_t::flow(cell_bits_t& priority_accessed) { // REVISIT : This is an approximation for enablement that could do // better with connected components - for (vector::iterator f = cells.begin(), l = cells.end(); f != l; ++f) { - priority_accessed.set((*f)->interface_input_m->cell_set_pos_m); + for (const auto& cell : cells) { + priority_accessed.set(cell->interface_input_m->cell_set_pos_m); } /* @@ -1057,93 +1076,60 @@ void sheet_t::implementation_t::flow(cell_bits_t& priority_accessed) { cell.resolved_m = true; - for (relation_index_t::iterator f = cell.relation_index_m.begin(), - l = cell.relation_index_m.end(); - f != l; ++f) { - - if ((*f)->resolved_m) + for (const auto& relation : cell.relation_index_m) { + if (relation->resolved_m) continue; --cell.relation_count_m; - const relation_t* term = 0; - bool at_least_one = false; - - for (relation_set_t::iterator tf((*f)->terms_m.begin()), tl((*f)->terms_m.end()); - tf != tl; ++tf) { - // each term has a set of cells. If any cell is resolved then the term is resolved. - - bool resolved = false; - for (vector::iterator fc = tf->name_set_m.begin(), - lc = tf->name_set_m.end(); - fc != lc; ++fc) { - - index_t::iterator iter = output_index_m.find(*fc); - assert(iter != output_index_m.end()); - - if (iter->resolved_m) { - resolved = true; - break; - } - } - if (resolved) - continue; - - if (!term) { - term = &(*tf); - at_least_one = true; - } else { - term = NULL; - break; - } - } + auto term = + find_if(relation->terms_m, [&](const auto& term) { return !resolved(term); }); // REVISIT (sparent) : Better error reporting here. - if (!at_least_one) { + if (term == relation->terms_m.end()) throw std::logic_error("all terms of relation resolve but relation not applied."); - } - if (!term) + // If there is more than one unresolved term, continue. + if (std::find_if(next(term), relation->terms_m.end(), [&](const auto& term) { + return !resolved(term); + }) != relation->terms_m.end()) continue; // Flow out to lhs cells - (*f)->resolved_m = true; + relation->resolved_m = true; for (std::size_t n = 0, count = term->name_set_m.size(); n != count; ++n) { - index_t::iterator iter = output_index_m.find(term->name_set_m[n]); - assert(iter != output_index_m.end()); - - cell_t& cell = *iter; + auto& out_cell = output_cell(term->name_set_m[n]); // REVISIT (sparent) : Better error reporting here. - if (cell.term_m) + if (out_cell.term_m) throw logic_error("over constrained."); if (count == 1) { - cell.term_m = + out_cell.term_m = std::bind(&implementation_t::calculate_expression, std::ref(*this), - term->position_m, term->expression_m); + term->position_m, term->expression_m); } else { - cell.term_m = + out_cell.term_m = std::bind(&implementation_t::calculate_indexed, std::ref(*this), - term->position_m, term->expression_m, n); + term->position_m, term->expression_m, n); } - --cell.relation_count_m; + --out_cell.relation_count_m; // This will be a derived cell and will have a priority lower than any cell // contributing to it - assert(cell.interface_input_m && "Missing input half of interface cell."); - if (cell.interface_input_m->linked_m) { - cell.interface_input_m->priority_m = --priority_low_m; + assert(out_cell.interface_input_m && "Missing input half of interface cell."); + if (out_cell.interface_input_m->linked_m) { + out_cell.interface_input_m->priority_m = --priority_low_m; } - if (cell.relation_count_m) - cells.push_back(&cell); + if (out_cell.relation_count_m) + cells.push_back(&out_cell); else - cell.resolved_m = true; + out_cell.resolved_m = true; } // Remove the relation from any cells to which it is still attached. That is, @@ -1151,28 +1137,21 @@ void sheet_t::implementation_t::flow(cell_bits_t& priority_accessed) { vector remaining_cells; - for (relation_set_t::iterator tf((*f)->terms_m.begin()), tl((*f)->terms_m.end()); - tf != tl; ++tf) { - - if (&(*tf) == term) + for (const auto& in_term : relation->terms_m) { + if (&in_term == &(*term)) continue; - - remaining_cells.insert(remaining_cells.end(), tf->name_set_m.begin(), - tf->name_set_m.end()); + append(remaining_cells, in_term.name_set_m); } - sort(remaining_cells); - remaining_cells.erase(unique(remaining_cells), remaining_cells.end()); - - for (vector::iterator fc = remaining_cells.begin(), lc = remaining_cells.end(); - fc != lc; ++fc) { - - index_t::iterator iter = output_index_m.find(*fc); - assert(iter != output_index_m.end()); + sort_unique(remaining_cells); - if (iter->resolved_m) + /// REVISIT (sean-parent) : Rather than for_each we should have a set of in place + /// transform algorithms. This is transform_if taking a projection and a predicate. + for (const auto& name : remaining_cells) { + auto& out_cell = output_cell(name); + if (out_cell.resolved_m) continue; - --iter->relation_count_m; + --out_cell.relation_count_m; } } assert(cell.relation_count_m == 0 && diff --git a/source/adam_evaluate.cpp b/source/adam_evaluate.cpp index 95f3e8b9..831a023a 100644 --- a/source/adam_evaluate.cpp +++ b/source/adam_evaluate.cpp @@ -92,10 +92,11 @@ adam_callback_suite_t bind_to_sheet(sheet_t& sheet) { suite.add_cell_proc_m = std::bind(&add_cell, std::ref(sheet), _1, _2, _3, _4); suite.add_relation_proc_m = std::bind(&add_relation, std::ref(sheet), _1, _2, _3, _4); - suite.add_interface_proc_m = [&sheet](name_t name, bool linked, const line_position_t& position1, - const array_t& initializer, const line_position_t& position2, - const array_t& expression, const std::string& brief, - const std::string& detailed) -> void { + suite.add_interface_proc_m = + [&sheet](name_t name, bool linked, const line_position_t& position1, + const array_t& initializer, const line_position_t& position2, + const array_t& expression, const std::string& /* brief */, + const std::string& /* detailed */) -> void { sheet.add_interface(name, linked, position1, initializer, position2, expression); }; return suite; diff --git a/source/eve.cpp b/source/eve.cpp index 199e2895..c82c161b 100644 --- a/source/eve.cpp +++ b/source/eve.cpp @@ -94,9 +94,9 @@ struct view_proxy_t : adobe::extents_slices_t { layout_attributes_t geometry_m; // REVISIT (sparent) : make const place_data_t place_m; - int space_before_m; // populated from spacing_m of parent - std::array container_length_m; // calculated length of container - std::array measured_length_m; // length of container children only + int space_before_m; // populated from spacing_m of parent + std::array container_length_m; // calculated length of container + std::array measured_length_m; // length of container children only std::array container_guide_set_m; // forward/reverse guide set for // container @@ -299,8 +299,9 @@ eve_t::iterator eve_t::add_placeable(iterator parent, const layout_attributes_t& void eve_t::set_visible(iterator c, bool visible) { return object_m->set_visible(c, visible); } -void eve_t::set_layout_attributes(iterator c, const layout_attributes_t& geometry) -{ return object_m->set_layout_attributes(c, geometry); } +void eve_t::set_layout_attributes(iterator c, const layout_attributes_t& geometry) { + return object_m->set_layout_attributes(c, geometry); +} /**************************************************************************************************/ @@ -331,7 +332,7 @@ eve_t::iterator eve_t::implementation_t::add_placeable(iterator parent, if (parent == iterator()) parent = proxies_m.end(); - parent = proxies_m.insert(reverse ? boost::next(adobe::leading_of(parent)) + parent = proxies_m.insert(reverse ? std::next(adobe::leading_of(parent)) : adobe::trailing_of(parent), implementation::view_proxy_t(initial, placeable)); @@ -345,7 +346,10 @@ eve_t::iterator eve_t::implementation_t::add_placeable(iterator parent, void eve_t::implementation_t::set_visible(iterator c, bool visible) { c->visible_m = visible; } -void eve_t::implementation_t::set_layout_attributes(iterator c, const layout_attributes_t& geometry) { c->geometry_m = geometry; } +void eve_t::implementation_t::set_layout_attributes(iterator c, + const layout_attributes_t& geometry) { + c->geometry_m = geometry; +} /**************************************************************************************************/ @@ -374,8 +378,8 @@ void eve_t::implementation_t::solve(slice_select_t select) { --limiter; progress = false; - for (preorder_iterator first(boost::begin(preorder_range())), - last(boost::end(preorder_range())); + for (preorder_iterator first(std::begin(preorder_range())), + last(std::end(preorder_range())); first != last; ++first) { progress |= first->solve_down(::child_begin(first.base()), ::child_end(first.base()), select); @@ -602,10 +606,10 @@ void view_proxy_t::adjust(::child_iterator first, ::child_iterator last, slice_s guide_set = iter->geometry_m.extents_m.slice_m[select].guide_set_m; - adobe::transform(guide_set, boost::begin(guide_set), + adobe::transform(guide_set, std::begin(guide_set), std::bind(std::minus(), - iter->geometry_m.extents_m.slice_m[select].length_m, - _1)); + iter->geometry_m.extents_m.slice_m[select].length_m, + _1)); adobe::reverse(guide_set); } break; default: @@ -698,7 +702,7 @@ void view_proxy_t::flatten(::child_iterator first, ::child_iterator last, slice_ case layout_attributes_t::align_reverse: case layout_attributes_t::align_reverse_fill: { guide_set = container_guide_set_m[select][layout_attributes_t::align_reverse]; - adobe::transform(guide_set, boost::begin(guide_set), + adobe::transform(guide_set, std::begin(guide_set), std::bind(std::minus(), place_m.slice_m[select].length_m, _1)); adobe::reverse(guide_set); } break; @@ -1122,7 +1126,7 @@ void view_proxy_t::adjust_with(::child_iterator first, ::child_iterator last, std::fill( adobe::copy_bound(geometry.spacing_m, child_spacing_range).second, - boost::end(child_spacing_range), geometry_m.spacing_m.back()); + std::end(child_spacing_range), geometry_m.spacing_m.back()); */ typedef layout_attributes_t::spacing_t::difference_type difference_type; @@ -1337,22 +1341,13 @@ void view_proxy_t::solve_up_with(::child_iterator first, ::child_iterator last, // balance the guides if (gslice.balance_m && forward_guide_set.size() > 2) { - guide_set_t::iterator iter(adobe::max_adjacent_difference(forward_guide_set)); - guide_set_t::value_type difference(*boost::next(iter) - *iter); + guide_set_t::iterator iter{adobe::max_adjacent_difference(forward_guide_set)}; guide_set_t::value_type accumulate(forward_guide_set.front()); - /* - REVISIT (sparent) : This should be a call to generate - but I need a simple to create - accumulate function object. - */ - - for (guide_set_t::iterator first(boost::next(forward_guide_set.begin())), - last(forward_guide_set.end()); - first != last; ++first) { - accumulate += difference; - *first = accumulate; - } + std::generate( + std::next(forward_guide_set.begin()), forward_guide_set.end(), + [&, _difference = *std::next(iter) - *iter] { return accumulate += _difference; }); } length += additional_rlength; @@ -1409,14 +1404,16 @@ bool view_proxy_t::solve_down_with(::child_iterator first, ::child_iterator last if ((rfirst->geometry_m.placement_m == eve_t::place_leaf) && guide != guide_last) { // Snap the current postion to the guide. - ADOBE_ASSERT(reverse_guide_iter != - container_guide_set_m[select][layout_attributes_t::align_reverse].end()); + ADOBE_ASSERT( + reverse_guide_iter != + container_guide_set_m[select][layout_attributes_t::align_reverse].end()); rlength = *reverse_guide_iter++ - *guide++; } for (; guide != guide_last; ++guide, ++reverse_guide_iter) { - ADOBE_ASSERT(reverse_guide_iter != - container_guide_set_m[select][layout_attributes_t::align_reverse].end()); + ADOBE_ASSERT( + reverse_guide_iter != + container_guide_set_m[select][layout_attributes_t::align_reverse].end()); int new_guide(*reverse_guide_iter - rlength); if (new_guide != *guide) { @@ -1453,14 +1450,16 @@ bool view_proxy_t::solve_down_with(::child_iterator first, ::child_iterator last if ((iter->geometry_m.placement_m == adobe::eve_t::place_leaf) && guide != guide_last) { // Snap the current postion to the guide. - ADOBE_ASSERT(guide_iter != - container_guide_set_m[select][layout_attributes_t::align_forward].end()); + ADOBE_ASSERT( + guide_iter != + container_guide_set_m[select][layout_attributes_t::align_forward].end()); length = *guide_iter++ - *guide++; } for (; guide != guide_last; ++guide, ++guide_iter) { - ADOBE_ASSERT(guide_iter != - container_guide_set_m[select][layout_attributes_t::align_forward].end()); + ADOBE_ASSERT( + guide_iter != + container_guide_set_m[select][layout_attributes_t::align_forward].end()); int new_guide(*guide_iter - length); if (new_guide != *guide) { diff --git a/source/eve_evaluate.cpp b/source/eve_evaluate.cpp index d734743a..93912ed5 100644 --- a/source/eve_evaluate.cpp +++ b/source/eve_evaluate.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -198,14 +199,15 @@ eve_callback_suite_t bind_layout(const bind_layout_proc_t& proc, sheet_t& sheet, eve_callback_suite_t suite; - suite.add_view_proc_m = std::bind( - proc, _1, _3, std::bind(&evaluate_named_arguments, std::ref(evaluator), _4)); + suite.add_view_proc_m = + std::bind(proc, _1, _3, std::bind(&evaluate_named_arguments, std::ref(evaluator), _4)); suite.add_cell_proc_m = std::bind(&add_cell, std::ref(sheet), _1, _2, _3, _4); suite.add_relation_proc_m = std::bind(&add_relation, std::ref(sheet), _1, _2, _3, _4); - suite.add_interface_proc_m = [&sheet](name_t name, bool linked, const line_position_t& position1, - const array_t& initializer, const line_position_t& position2, - const array_t& expression, const std::string& brief, - const std::string& detailed) -> void { + suite.add_interface_proc_m = + [&sheet](name_t name, bool linked, const line_position_t& position1, + const array_t& initializer, const line_position_t& position2, + const array_t& expression, const std::string& /* brief */, + const std::string& /* detailed */) -> void { sheet.add_interface(name, linked, position1, initializer, position2, expression); }; suite.finalize_sheet_proc_m = std::bind(&sheet_t::update, std::ref(sheet)); @@ -320,16 +322,16 @@ void apply_layout_parameters(layout_attributes_t& data, const dictionary_t& para dictionary_t::const_iterator iter(parameters.find(key_spacing)); if (iter != parameters.end()) { if (iter->second.type_info() == typeid(array_t)) { + // REVISIT (sean-parent) : This could use a back inserter but this is overwriting + // starting at the second element (contains a default value). Maybe a simpler + // expression? const array_t& spacing_array = iter->second.cast(); data.spacing_m.resize(spacing_array.size() + 1); layout_attributes_t::spacing_t::iterator dest_iter(data.spacing_m.begin() + 1); - for (array_t::const_iterator iter(spacing_array.begin()); - iter != spacing_array.end(); ++iter) { - *dest_iter = iter->cast(); - ++dest_iter; - } + transform(spacing_array, dest_iter, + [](const any_regular_t& x) { return x.cast(); }); } else { double tmp(data.spacing_m[1]); iter->second.cast(tmp); // Try getting as number diff --git a/source/exception.cpp b/source/exception.cpp new file mode 100644 index 00000000..56887e5f --- /dev/null +++ b/source/exception.cpp @@ -0,0 +1,40 @@ +/* + Copyright 2013 Adobe + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +*/ +/**************************************************************************************************/ + +#include + +#include +#include +#include + +/**************************************************************************************************/ + +namespace adobe { + +/**************************************************************************************************/ + +[[noreturn]] void terminate(const char* message) { + try { + throw std::logic_error(message); + } catch (...) { + std::terminate(); + } +} + +[[noreturn]] void terminate(const std::string& message) { + try { + throw std::logic_error(message); + } catch (...) { + std::terminate(); + } +} + +/**************************************************************************************************/ + +} // namespace adobe + +/**************************************************************************************************/ diff --git a/source/xml_lex.cpp b/source/xml_lex.cpp index 1aa71a48..c6a6fedb 100644 --- a/source/xml_lex.cpp +++ b/source/xml_lex.cpp @@ -304,8 +304,8 @@ bool xml_lex_t::is_name_start_char() { return false; return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == ':' || c == '_' || - (c >= char(0xC0) && c <= char(0xD6)) || (c >= char(0xD8) && c <= char(0xF6)) || - (c >= char(0xF8) && c <= char(0xFF)); + (c >= '\xC0' && c <= '\xD6') || (c >= '\xD8' && c <= '\xF6') || + (c >= '\xF8' && c <= '\xFF'); } /**************************************************************************************************/ @@ -323,7 +323,7 @@ bool xml_lex_t::is_name_char() { if (!peek_char(c)) return false; - return c == '-' || c == '.' || (c >= '0' && c <= '9') || c == char(0xB7); + return c == '-' || c == '.' || (c >= '0' && c <= '9') || c == '\xB7'; } /**************************************************************************************************/ diff --git a/source/xstring.cpp b/source/xstring.cpp index 3e9c023b..989f1284 100644 --- a/source/xstring.cpp +++ b/source/xstring.cpp @@ -323,7 +323,8 @@ count_max_element_tuple(Range& x, UnaryFunction f) { /**************************************************************************************************/ context_frame_t::store_iterator -context_frame_t::closest_match(store_range_pair_t range, const adobe::attribute_set_t& searching) { +context_frame_t::closest_match(store_range_pair_t /* range */, + const adobe::attribute_set_t& /* searching */) { // REVISIT: (fbrereto) This function fails to compile because `store_range_pair_t range`'s // iterators fail to evaluate as modeling the ForwardIterator concept, so the // count_max_element_tuple call below emits an error. I am disabling this routine instead diff --git a/source/zuid.cpp b/source/zuid.cpp index f6660646..01632512 100644 --- a/source/zuid.cpp +++ b/source/zuid.cpp @@ -166,9 +166,16 @@ zuid_t::zuid_t(const char* zuid_t) : uuid_m(empty_uuid()) { unsigned long temp_data1; int temp_data[8]; +// Secure versions of sscanf is used on MSVC to avoid warnings. +#ifdef _MSC_VER + ::sscanf_s(zuid_t, "%8lx-%4hx-%4hx-%2x%2x-%2x%2x%2x%2x%2x%2x", &temp_data1, &uuid_m.data2_m, + &uuid_m.data3_m, &temp_data[0], &temp_data[1], &temp_data[2], &temp_data[3], + &temp_data[4], &temp_data[5], &temp_data[6], &temp_data[7]); +#else std::sscanf(zuid_t, "%8lx-%4hx-%4hx-%2x%2x-%2x%2x%2x%2x%2x%2x", &temp_data1, &uuid_m.data2_m, &uuid_m.data3_m, &temp_data[0], &temp_data[1], &temp_data[2], &temp_data[3], &temp_data[4], &temp_data[5], &temp_data[6], &temp_data[7]); +#endif uuid_m.data1_m = static_cast(temp_data1); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3c490db9..5102f450 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -7,7 +7,8 @@ function(asl_test) add_executable (${asl_test_NAME} ${asl_test_SOURCES}) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - target_compile_options (${asl_test_NAME} PRIVATE "/DNOMINMAX") + target_compile_options (${asl_test_NAME} PRIVATE "/W4") + target_compile_options (${asl_test_NAME} PRIVATE "/WX") else() target_compile_options (${asl_test_NAME} PRIVATE "-Wno-unused-variable") target_compile_options (${asl_test_NAME} PRIVATE "-Wno-unknown-pragmas") diff --git a/test/adam_smoke/CMakeLists.txt b/test/adam_smoke/CMakeLists.txt index 5768c482..92809e9e 100644 --- a/test/adam_smoke/CMakeLists.txt +++ b/test/adam_smoke/CMakeLists.txt @@ -1,5 +1,10 @@ add_executable (adam_smoke_test adam_smoke_test.cpp) target_link_libraries(adam_smoke_test PRIVATE asl) +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + target_compile_options (adam_smoke_test PRIVATE "/W4") + target_compile_options (adam_smoke_test PRIVATE "/WX") +endif() + add_test (NAME adam_smoke_test_rtd COMMAND adam_smoke_test ut_mode ${CMAKE_CURRENT_SOURCE_DIR}/rtd.adm) add_test (NAME adam_smoke_test_io COMMAND adam_smoke_test ut_mode ${CMAKE_CURRENT_SOURCE_DIR}/io.adm) diff --git a/test/property_model_eval/iomanip_flat.cpp b/test/property_model_eval/iomanip_flat.cpp index 2d57650b..7c65d28b 100644 --- a/test/property_model_eval/iomanip_flat.cpp +++ b/test/property_model_eval/iomanip_flat.cpp @@ -4,7 +4,7 @@ or a copy at http://stlab.adobe.com/licenses.html) */ -// REVISIT (mmarcus) : repalce this file with merge into iomanip_asl_cel +// REVISIT (mmarcus) : replace this file with merge into iomanip_asl_cel /**************************************************************************************************/ @@ -151,7 +151,7 @@ void flat_format::handle_atom(stream_type& os, bool is_push) { } else if (value.type_info() == typeid(dictionary_t)) { os << value.cast(); } else if (value.type_info() == typeid(array_t)) { - os << value.cast(); + os << value.cast();; } else { os << "'cel_unknown: " << value.type_info().name() << "'"; } diff --git a/test/to_string/main.cpp b/test/to_string/main.cpp index 137bd333..f9c9b5a5 100644 --- a/test/to_string/main.cpp +++ b/test/to_string/main.cpp @@ -17,10 +17,14 @@ #define BOOST_TEST_MAIN // boost +#ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunneeded-internal-declaration" +#endif #include +#ifdef __clang__ #pragma clang diagnostic pop +#endif // asl #include diff --git a/test/unit_tests/any_regular/any_regular_serialization_test.cpp b/test/unit_tests/any_regular/any_regular_serialization_test.cpp index 653820cf..8e4ae168 100644 --- a/test/unit_tests/any_regular/any_regular_serialization_test.cpp +++ b/test/unit_tests/any_regular/any_regular_serialization_test.cpp @@ -30,7 +30,7 @@ void operator<<(std::ostream& s, const foo_t& x) { s << x.x; } // bar_t has no operator<< defined. As such it will not be serialized when bar_t // is wrapped in an any_regular_t. struct bar_t {}; -bool operator==(const bar_t& x, const bar_t& y) { return true; }; +bool operator==(const bar_t&, const bar_t&) { return true; }; bool operator!=(const bar_t& x, const bar_t& y) { return !(x == y); } BOOST_AUTO_TEST_CASE(any_regular_serialization_test) { diff --git a/test/unit_tests/copy_on_write/cow_test.cpp b/test/unit_tests/copy_on_write/cow_test.cpp index 1465391a..c709702e 100644 --- a/test/unit_tests/copy_on_write/cow_test.cpp +++ b/test/unit_tests/copy_on_write/cow_test.cpp @@ -142,7 +142,7 @@ void test_copy_on_write() { typename CowType::value_type (*mv)(const long&) = &make_value; - if (is_noisy) { + if constexpr (is_noisy) { // reset counters noisy_check_allocation(); noisy_check_deallocation(); @@ -153,7 +153,7 @@ void test_copy_on_write() { // Test default constructor { CowType value_0; } // Check - if (is_noisy) { + if constexpr (is_noisy) { BOOST_CHECK_MESSAGE(noisy_check_allocation() == 1, "allocation count mismatch"); BOOST_CHECK_MESSAGE(noisy_check_deallocation() == 0, "deallocation count mismatch"); } @@ -186,7 +186,7 @@ void test_copy_on_write() { BOOST_CHECK(value_test.identity(value_2)); } // Check - if (is_noisy) { + if constexpr (is_noisy) { BOOST_CHECK_MESSAGE(noisy_check_allocation() == 4, "allocation count mismatch"); BOOST_CHECK_MESSAGE(noisy_check_deallocation() == 4, "deallocation count mismatch"); } @@ -211,7 +211,7 @@ void test_copy_on_write() { #endif } // Check - if (is_noisy) { + if constexpr (is_noisy) { BOOST_CHECK_MESSAGE(noisy_check_allocation() == 2, "allocation count mismatch"); BOOST_CHECK_MESSAGE(noisy_check_deallocation() == 2, "deallocation count mismatch"); } @@ -224,7 +224,7 @@ void test_copy_on_write() { value_4.write() = mv(4); } // Check - if (is_noisy) { + if constexpr (is_noisy) { BOOST_CHECK_MESSAGE(noisy_check_allocation() == 1, "allocation count mismatch"); BOOST_CHECK_MESSAGE(noisy_check_deallocation() == 1, "deallocation count mismatch"); } @@ -237,7 +237,7 @@ void test_copy_on_write() { foo = mv(2); // allocation } // Check - if (is_noisy) { + if constexpr (is_noisy) { BOOST_CHECK_MESSAGE(noisy_check_allocation() == 2, "allocation count mismatch"); BOOST_CHECK_MESSAGE(noisy_check_deallocation() == 2, "deallocation count mismatch"); } @@ -254,7 +254,7 @@ void test_copy_on_write() { BOOST_CHECK(bar.unique_instance() && foo.unique_instance()); } // Check - if (is_noisy) { + if constexpr (is_noisy) { BOOST_CHECK_MESSAGE(noisy_check_allocation() == 2, "allocation count mismatch"); BOOST_CHECK_MESSAGE(noisy_check_deallocation() == 2, "deallocation count mismatch"); } @@ -268,7 +268,7 @@ void test_copy_on_write() { foo = std::move(value); // allocation } // Check - if (is_noisy) { + if constexpr (is_noisy) { BOOST_CHECK_MESSAGE(noisy_check_allocation() == 2, "allocation count mismatch"); BOOST_CHECK_MESSAGE(noisy_check_deallocation() == 2, "deallocation count mismatch"); } @@ -281,7 +281,7 @@ void test_copy_on_write() { foo = std::move(value); } // Check - if (is_noisy) { + if constexpr (is_noisy) { BOOST_CHECK_MESSAGE(noisy_check_allocation() == 1, "allocation count mismatch"); BOOST_CHECK_MESSAGE(noisy_check_deallocation() == 1, "deallocation count mismatch"); } @@ -295,7 +295,7 @@ void test_copy_on_write() { foo = std::move(value); // allocation } // Check - if (is_noisy) { + if constexpr (is_noisy) { BOOST_CHECK_MESSAGE(noisy_check_allocation() == 2, "allocation count mismatch"); BOOST_CHECK_MESSAGE(noisy_check_deallocation() == 2, "deallocation count mismatch"); } @@ -307,7 +307,7 @@ void test_copy_on_write() { foo.write() = typename CowType::value_type(mv(2)); } // Check - if (is_noisy) { + if constexpr (is_noisy) { BOOST_CHECK_MESSAGE(noisy_check_allocation() == 1, "allocation count mismatch"); BOOST_CHECK_MESSAGE(noisy_check_deallocation() == 1, "deallocation count mismatch"); } @@ -320,7 +320,7 @@ void test_copy_on_write() { foo.write() = typename CowType::value_type(mv(2)); // allocation } // Check - if (is_noisy) { + if constexpr (is_noisy) { BOOST_CHECK_MESSAGE(noisy_check_allocation() == 2, "allocation count mismatch"); BOOST_CHECK_MESSAGE(noisy_check_deallocation() == 2, "deallocation count mismatch"); } @@ -338,7 +338,7 @@ void test_copy_on_write() { "read error"); } // Check - if (is_noisy) { + if constexpr (is_noisy) { BOOST_CHECK_MESSAGE(noisy_check_allocation() == 1, "allocation count mismatch"); BOOST_CHECK_MESSAGE(noisy_check_deallocation() == 1, "deallocation count mismatch"); } @@ -354,7 +354,7 @@ void test_copy_on_write() { BOOST_CHECK_MESSAGE(bar.read() == typename CowType::value_type(mv(1)), "swap error"); } // Check - if (is_noisy) { + if constexpr (is_noisy) { BOOST_CHECK_MESSAGE(noisy_check_allocation() == 2, "allocation count mismatch"); BOOST_CHECK_MESSAGE(noisy_check_deallocation() == 2, "deallocation count mismatch"); }