├── .clang-format ├── .gitignore ├── .gitmodules ├── .travis.yml ├── CHANGELOG.md ├── CMakeLists.txt ├── LICENSE ├── README.md ├── UPGRADE.md ├── cmake └── ProofSeedConfig.cmake ├── codecov.yml ├── include └── proofseed │ ├── asynqro_extra.h │ ├── planting.h │ ├── proofalgorithms.h │ ├── proofseed_global.h │ └── tasks.h ├── proofmodule.json ├── src └── proofseed │ ├── dummy.cpp │ └── tasks.cpp └── tests └── proofseed ├── CMakeLists.txt ├── algorithms_flatten_test.cpp ├── algorithms_map_test.cpp ├── algorithms_test.cpp ├── asynqro_extra_test.cpp ├── main.cpp └── tasks_test.cpp /.clang-format: -------------------------------------------------------------------------------- 1 | # Proof clang-format configuration file 2 | #Requires clang-format >= 6.0.0 3 | 4 | --- 5 | DisableFormat: false 6 | Language: Cpp 7 | Standard: Cpp11 8 | BasedOnStyle: LLVM 9 | AccessModifierOffset: -4 10 | AlignAfterOpenBracket: Align 11 | AlignConsecutiveAssignments: false 12 | AlignConsecutiveDeclarations: false 13 | AlignEscapedNewlines: Left 14 | AlignOperands: true 15 | AlignTrailingComments: false 16 | AllowAllParametersOfDeclarationOnNextLine: false 17 | AllowShortBlocksOnASingleLine: false 18 | AllowShortCaseLabelsOnASingleLine: false 19 | AllowShortFunctionsOnASingleLine: InlineOnly 20 | AllowShortIfStatementsOnASingleLine: false 21 | AllowShortLoopsOnASingleLine: false 22 | AlwaysBreakAfterReturnType: None 23 | AlwaysBreakBeforeMultilineStrings: false 24 | AlwaysBreakTemplateDeclarations: true #should be MultiLine since 7.0.0 25 | BinPackArguments: true 26 | BinPackParameters: true 27 | BraceWrapping: 28 | AfterClass: true 29 | AfterControlStatement: false 30 | AfterEnum: true 31 | AfterFunction: true 32 | AfterNamespace: false 33 | AfterStruct: true 34 | AfterUnion: true 35 | AfterExternBlock: false 36 | BeforeCatch: false 37 | BeforeElse: false 38 | IndentBraces: false 39 | SplitEmptyFunction: false 40 | SplitEmptyRecord: false 41 | BreakBeforeBinaryOperators: NonAssignment 42 | BreakBeforeBraces: Custom 43 | BreakBeforeInheritanceComma: false 44 | BreakBeforeTernaryOperators: true 45 | BreakConstructorInitializers: BeforeColon 46 | BreakStringLiterals: true 47 | ColumnLimit: 120 48 | CommentPragmas: "^ *!|^ *:|^ *TODO:|^ *NOTE:|^ *HACK:" 49 | CompactNamespaces: false 50 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 51 | ConstructorInitializerIndentWidth: 4 52 | ContinuationIndentWidth: 4 53 | Cpp11BracedListStyle: true 54 | DerivePointerAlignment: false 55 | FixNamespaceComments: true 56 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, forever, Q_FOREVER, QBENCHMARK, QBENCHMARK_ONCE ] 57 | IncludeBlocks: Regroup 58 | IncludeCategories: 59 | - Regex: '^` overload added for shorter successful and sequence methods usage 42 | * Future::reduce renamed to innerReduce 43 | * Additional morphisms added to Future with container value: innerReduceByMutation, innerMap, innerFilter 44 | * Future::zipValue method added 45 | * Failure::withMessage, withCode, withData methods added 46 | 47 | #### Bug Fixing 48 | * -- 49 | 50 | ## 0.18.7.6 51 | #### Features 52 | * flatten algorithm now reserves destination 53 | * forAll, exists and mapInPlace algorithms 54 | * toSet/toVector/toList/toKeysSet/toKeysVector/toKeysList/toValuesSet/toValuesVector/toValuesList algorithms 55 | * identity/keyIdentity/valueIdentity helper functions in algorithms 56 | * Future::andThenValue and Future::filter operations 57 | * CancelableFuture 58 | * Generic IsSpecialization trait 59 | * IsSpecialization and HasTypeParams traits moved out from detail namespace 60 | * Future::zip() can now accept any FutureSP-like (should contain Type type which contains Value type) arguments 61 | * tasks::RestrictionType::ThreadBound for tasks that should always be on exactly the same thread 62 | * Failure::Hints enum now has DataIsHttpCodeHint value to determine if data contains http status code 63 | 64 | #### Bug Fixing 65 | * proper tasks finishing waiting in sequenceRunWithFailure test 66 | 67 | ## 0.18.4.12 68 | #### Features 69 | * forEach algorithm 70 | * flatten algorithm 71 | * flatFilter algorithm 72 | * All algorithms can work with QJsonArray now (and any other container that provide either cbegin/cend, constBegin/constEnd or begin/end) 73 | * algorithms::map() overload for cases when index is also needed 74 | * tasks::run() overload for data containers with functor returning Future 75 | * tasks::run() overload for data containers with functor returning void 76 | * tasks::run() overload for data containers with index available in task lambda 77 | 78 | #### Bug Fixing 79 | * -- 80 | 81 | ## 0.18.3.14 82 | Initial release 83 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12.0) 2 | if(NOT PROOF_FULL_BUILD) 3 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/lib/cmake/modules") 4 | include(ProofInternal) 5 | endif() 6 | 7 | project(ProofSeed VERSION ${PROOF_VERSION} LANGUAGES CXX) 8 | 9 | find_package(Qt5Core CONFIG REQUIRED) 10 | if(NOT PROOF_FULL_BUILD) 11 | proof_init() 12 | find_package(proof-gtest CONFIG REQUIRED) 13 | enable_testing() 14 | endif() 15 | 16 | set(ASYNQRO_QT_SUPPORT ON CACHE BOOL "Qt support in asynqro" FORCE) 17 | set(ASYNQRO_BUILD_TESTS OFF CACHE BOOL "Asynqro tests" FORCE) 18 | set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libs (used only for asynqro, everything else is force-shared anyway)" FORCE) 19 | add_subdirectory(3rdparty/asynqro) 20 | 21 | proof_add_target_sources(Seed 22 | src/proofseed/tasks.cpp 23 | ) 24 | 25 | proof_add_target_headers(Seed 26 | include/proofseed/planting.h 27 | include/proofseed/proofalgorithms.h 28 | include/proofseed/asynqro_extra.h 29 | include/proofseed/proofseed_global.h 30 | include/proofseed/tasks.h 31 | ) 32 | 33 | if (PROOF_CLANG_TIDY) 34 | proof_add_target_sources(Seed src/proofseed/dummy.cpp) 35 | endif() 36 | 37 | proof_add_module(Seed 38 | QT_LIBS Core 39 | OTHER_LIBS asynqro::asynqro 40 | ) 41 | 42 | add_subdirectory(tests/proofseed) 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2018, OpenSoft Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted 5 | provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, this list of 10 | conditions and the following disclaimer in the documentation and/or other materials provided 11 | with the distribution. 12 | * Neither the name of OpenSoft Inc. nor the names of its contributors may be used to endorse 13 | or promote products derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 16 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 17 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 18 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 21 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 22 | OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.com/opensoft/proofseed.svg?branch=develop)](https://travis-ci.com/opensoft/proofseed) 2 | 3 | Seed of Proof 4 | ============= 5 | Low-level primitives used by Proof framework. Mostly a wrapper around [asynqro library](https://github.com/dkormalev/asynqro). 6 | -------------------------------------------------------------------------------- /UPGRADE.md: -------------------------------------------------------------------------------- 1 | Upgrades 2 | ======== 3 | Changes that one must make to applications based on Proof between versions. 4 | 5 | 6 | ## Not released 7 | #### IT issues 8 | * -- 9 | 10 | #### API modifications/removals/deprecations 11 | * -- 12 | 13 | #### Config changes 14 | * -- 15 | 16 | #### Migrations 17 | * -- 18 | 19 | ## 0.19.4.2 20 | #### IT issues 21 | * -- 22 | 23 | #### API modifications/removals/deprecations 24 | * Future, Promise and related classes replaced with 3rdparty asynqro 25 | * type traits removed (use asynqro) 26 | * SpinLock removed (use asynqro) 27 | * tasks scheduling replaced with 3rdparty asynqro 28 | 29 | #### Config changes 30 | * -- 31 | 32 | #### Migrations 33 | * -- 34 | 35 | ## 0.18.8.10 36 | #### IT issues 37 | * -- 38 | 39 | #### API modifications/removals/deprecations 40 | * Future::reduce renamed to innerReduce 41 | 42 | #### Config changes 43 | * -- 44 | 45 | #### Migrations 46 | * -- 47 | 48 | ## 0.18.3.14 49 | Initial release 50 | -------------------------------------------------------------------------------- /cmake/ProofSeedConfig.cmake: -------------------------------------------------------------------------------- 1 | include(CMakeFindDependencyMacro) 2 | 3 | list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_LIST_DIR}/3rdparty") 4 | find_dependency(Threads REQUIRED) 5 | find_dependency(Qt5Core CONFIG REQUIRED) 6 | find_dependency(Qt5Concurrent CONFIG REQUIRED) 7 | find_dependency(asynqro CONFIG REQUIRED) 8 | list(REMOVE_AT CMAKE_PREFIX_PATH -1) 9 | 10 | if(NOT TARGET Proof::Seed) 11 | include("${CMAKE_CURRENT_LIST_DIR}/ProofSeedTargets.cmake") 12 | endif() 13 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | range: 80..95 3 | round: down 4 | precision: 2 5 | 6 | codecov: 7 | branch: develop 8 | -------------------------------------------------------------------------------- /include/proofseed/asynqro_extra.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019, OpenSoft Inc. 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, are permitted 5 | * provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, this list of 8 | * conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, this list of 10 | * conditions and the following disclaimer in the documentation and/or other materials provided 11 | * with the distribution. 12 | * * Neither the name of OpenSoft Inc. nor the names of its contributors may be used to endorse 13 | * or promote products derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 17 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 21 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 22 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | * 24 | * Author: denis.kormalev@opensoftdev.com (Denis Kormalev) 25 | * 26 | */ 27 | #ifndef PROOFSEED_ASYNQRO_EXTRA_H 28 | #define PROOFSEED_ASYNQRO_EXTRA_H 29 | 30 | #include "asynqro/asynqro" 31 | 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | namespace Proof { 38 | struct Failure 39 | { 40 | enum Hints 41 | { 42 | NoHint = 0x0, 43 | UserFriendlyHint = 0x1, 44 | CriticalHint = 0x2, 45 | DataIsHttpCodeHint = 0x4, 46 | FromExceptionHint = 0x8 47 | }; 48 | Failure(const QString &message, long moduleCode, long errorCode, unsigned long hints = Failure::NoHint, 49 | const QVariant &data = QVariant()) noexcept 50 | : exists(true), moduleCode(moduleCode), errorCode(errorCode), hints(hints), message(message), data(data) 51 | {} 52 | explicit Failure(const QVariant &data) noexcept : exists(true), data(data) {} 53 | Failure() noexcept {} 54 | Failure(Failure &&) noexcept = default; 55 | Failure(const Failure &) = default; 56 | ~Failure() = default; 57 | Failure &operator=(Failure &&) noexcept = default; 58 | Failure &operator=(const Failure &) = default; 59 | operator QString() noexcept { return message; } // NOLINT(google-explicit-constructor) 60 | Failure withMessage(const QString &msg) const noexcept { return Failure(msg, moduleCode, errorCode, hints, data); } 61 | Failure withCode(long module, long error) const noexcept { return Failure(message, module, error, hints, data); } 62 | Failure withData(const QVariant &d) const noexcept { return Failure(message, moduleCode, errorCode, hints, d); } 63 | 64 | bool exists = false; 65 | long moduleCode = 0; 66 | long errorCode = 0; 67 | unsigned long hints = NoHint; 68 | QString message; 69 | QVariant data; 70 | }; 71 | 72 | template 73 | using Future = asynqro::Future; 74 | template 75 | using Promise = asynqro::Promise; 76 | template 77 | using CancelableFuture = asynqro::CancelableFuture; 78 | using WithFailure = asynqro::WithFailure; 79 | using SpinLock = asynqro::detail::SpinLock; 80 | using SpinLockHolder = asynqro::detail::SpinLockHolder; 81 | 82 | using asynqro::RepeaterResult; 83 | template 84 | using RepeaterFutureResult = asynqro::RepeaterFutureResult, Failure>; 85 | 86 | namespace repeater { 87 | using asynqro::repeater::Continue; 88 | using asynqro::repeater::Finish; 89 | using asynqro::repeater::TrampolinedContinue; 90 | } // namespace repeater 91 | 92 | namespace futures { 93 | template 94 | auto successful(T &&value) noexcept 95 | { 96 | return Proof::Future>::successful(std::forward(value)); 97 | } 98 | 99 | template 100 | auto successful(const T &value) noexcept 101 | { 102 | return Proof::Future::successful(value); 103 | } 104 | 105 | // This overload copies container to make sure that it will be reachable in future 106 | template typename F, template typename Container, typename... Fs> 107 | Proof::Future> sequence(const Container, Fs...> &container) noexcept 108 | { 109 | Container> copy = container; 110 | return Proof::Future::sequence(std::move(copy)); 111 | } 112 | 113 | template typename F, template typename Container, typename... Fs> 114 | Proof::Future> sequence(Container, Fs...> &&container) noexcept 115 | { 116 | return Proof::Future::sequence(std::move(container)); 117 | } 118 | 119 | // This overload copies container to make sure that it will be reachable in future 120 | template