Skip to content

Commit

Permalink
Save state
Browse files Browse the repository at this point in the history
  • Loading branch information
bzeller committed Oct 2, 2024
1 parent 7c07a09 commit d9af39f
Show file tree
Hide file tree
Showing 47 changed files with 593 additions and 549 deletions.
18 changes: 12 additions & 6 deletions tests/parser/RepoindexFileReader_test.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include <sstream>
#include <string>
#include <zypp/Pathname.h>
#include <zypp/parser/RepoindexFileReader.h>
#include <zypp/base/NonCopyable.h>

#include <zypp/ng/parser/repoindexfilereader.h>
#include <zypp/ng/context.h>
#include <zypp/ng/repoinfo.h>

#include "TestSetup.h"

using std::stringstream;
Expand All @@ -21,13 +24,13 @@ static string service = "<repoindex arch=\"i386\" distver=\"11\">"

struct RepoCollector : private base::NonCopyable
{
bool collect( const RepoInfo &repo )
bool collect( const zyppng::RepoInfo &repo )
{
repos.push_back(repo);
return true;
}

RepoInfoList repos;
zyppng::RepoInfoList repos;
};

// Must be the first test!
Expand All @@ -36,11 +39,14 @@ BOOST_AUTO_TEST_CASE(read_index_file)
{
stringstream input(service);
RepoCollector collector;
parser::RepoindexFileReader parser( input, bind( &RepoCollector::collect, &collector, _1 ) );

auto ctx = zyppng::SyncContext::create();
ctx->initialize().unwrap();

zyppng::parser::RepoIndexFileReader parser( ctx, input, bind( &RepoCollector::collect, &collector, _1 ) );
BOOST_REQUIRE_EQUAL(3, collector.repos.size());

RepoInfo repo;
repo = collector.repos.front();
zyppng::RepoInfo repo = collector.repos.front();

BOOST_CHECK_EQUAL("Company's Foo", repo.name());
BOOST_CHECK_EQUAL("company-foo", repo.alias());
Expand Down
8 changes: 4 additions & 4 deletions tests/zyppng/Pipelines_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ BOOST_AUTO_TEST_CASE( asyncToMixedPipelineWithIndirectAsyncCB )

auto op = zyppng::AsyncOpRef<std::string>(std::make_shared<DelayedValue<std::string>>("5"))
| &toSignedInt
| []( auto &&in ){ in.value += 5; return std::make_shared<DelayedValue<Int>>(std::move(in)); }
| []( auto in ){ in.value += 5; return std::make_shared<DelayedValue<Int>>(std::move(in)); }
| &toString
| [&]( auto && res ){
| [&]( auto res ){
BOOST_CHECK_EQUAL ( std::string("10") , res );
ev->quit ();
return res;
Expand All @@ -172,13 +172,13 @@ BOOST_AUTO_TEST_CASE( asyncToMixedPipelineWithIndirectAsyncCBInStdFunction )

const auto &makePipeline = [&](){

const std::function< AsyncOpRef<Int>( Int && ) > &addFiveAsync = []( auto &&in ){ in.value += 5; return std::make_shared<DelayedValue<Int>>(std::move(in)); };
const std::function< AsyncOpRef<Int>( Int && ) > &addFiveAsync = []( auto in ){ in.value += 5; return std::make_shared<DelayedValue<Int>>(std::move(in)); };

return zyppng::AsyncOpRef<std::string>(std::make_shared<DelayedValue<std::string>>("5"))
| &toSignedInt
| addFiveAsync
| &toString
| [&]( auto && res ){
| [&]( auto res ){
BOOST_CHECK_EQUAL ( std::string("10") , res );
ev->quit ();
return res;
Expand Down
3 changes: 3 additions & 0 deletions zypp-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ SET( zyppng_pipelines_HEADERS
zyppng/pipelines/lift.h
zyppng/pipelines/MTry
zyppng/pipelines/mtry.h
zyppng/pipelines/operators.h
zyppng/pipelines/Optional
zyppng/pipelines/optional.h
zyppng/pipelines/Redo
zyppng/pipelines/redo.h
zyppng/pipelines/Transform
Expand Down
1 change: 1 addition & 0 deletions zypp-core/zyppng/pipelines/Optional
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "optional.h"
7 changes: 7 additions & 0 deletions zypp-core/zyppng/pipelines/asyncresult.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ namespace zyppng {
template <typename T>
constexpr bool is_nested_async_v = is_nested_async<T>::value;

// helper to figure out the return type for a mbind callback, if the ArgType is void the callback is considered to take no argument.
// Due to how std::conditional works, we cannot pass std::invoke_result_t but instead use the template type std::invoke_result, since
// one of the two options have no "::type" because the substitution fails, this breaks the std::conditional_t since it can only work with two well formed
// types. Instead we pass in the template types and evaluate the ::type in the end, when the correct invoke_result was chosen.
template < typename Function, typename ArgType>
using mbind_cb_result_t = typename std::conditional_t< std::is_same_v<ArgType,void>, std::invoke_result<Function>,std::invoke_result<Function, ArgType> >::type;


// case 1: connect async result to async callback
template <typename PrevRes, typename CallbackOp, typename AOpRes = typename CallbackOp::value_type >
Expand Down
95 changes: 1 addition & 94 deletions zypp-core/zyppng/pipelines/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <zypp-core/zyppng/pipelines/AsyncResult>
#include <zypp-core/zyppng/pipelines/Wait>
#include <zypp-core/zyppng/pipelines/Transform>
#include <zypp-core/zyppng/pipelines/operators.h>

namespace zyppng {

Expand Down Expand Up @@ -403,14 +404,6 @@ namespace zyppng {
}

namespace detail {

// helper to figure out the return type for a mbind callback, if the ArgType is void the callback is considered to take no argument.
// Due to how std::conditional works, we cannot pass std::invoke_result_t but instead use the template type std::invoke_result, since
// one of the two options have no "::type" because the substitution fails, this breaks the std::conditional_t since it can only work with two well formed
// types. Instead we pass in the template types and evaluate the ::type in the end, when the correct invoke_result was chosen.
template < typename Function, typename ArgType>
using mbind_cb_result_t = typename std::conditional_t< std::is_same_v<ArgType,void>, std::invoke_result<Function>,std::invoke_result<Function, ArgType> >::type;

template <typename T>
bool waitForCanContinueExpected( const expected<T> &value ) {
return value.is_valid();
Expand Down Expand Up @@ -555,57 +548,6 @@ namespace zyppng {


namespace detail {

template <typename Callback>
struct and_then_helper {
Callback function;

template< typename T, typename E >
auto operator()( const expected<T, E>& exp ) {
return and_then( exp, function );
}

template< typename T, typename E >
auto operator()( expected<T, E>&& exp ) {
return and_then( std::move(exp), function );
}
};

template <typename Callback>
struct or_else_helper {
Callback function;

template< typename T, typename E >
auto operator()( const expected<T, E>& exp ) {
return or_else( exp, function );
}

template< typename T, typename E >
auto operator()( expected<T, E>&& exp ) {
return or_else( std::move(exp), function );
}
};

template <typename Callback>
struct inspect_helper {
Callback function;

template< typename T, typename E >
auto operator()( expected<T, E>&& exp ) {
return inspect( std::move(exp), function );
}
};

template <typename Callback>
struct inspect_err_helper {
Callback function;

template< typename T, typename E >
auto operator()( expected<T, E>&& exp ) {
return inspect_err( std::move(exp), function );
}
};

struct collect_helper {
template < typename T >
inline auto operator()( T&& in ) {
Expand All @@ -615,41 +557,6 @@ namespace zyppng {
}

namespace operators {
template <typename Fun>
auto mbind ( Fun && function ) {
return detail::and_then_helper<Fun> {
std::forward<Fun>(function)
};
}

template <typename Fun>
auto and_then ( Fun && function ) {
return detail::and_then_helper<Fun> {
std::forward<Fun>(function)
};
}

template <typename Fun>
auto or_else ( Fun && function ) {
return detail::or_else_helper<Fun> {
std::forward<Fun>(function)
};
}

template <typename Fun>
auto inspect ( Fun && function ) {
return detail::inspect_helper<Fun> {
std::forward<Fun>(function)
};
}

template <typename Fun>
auto inspect_err ( Fun && function ) {
return detail::inspect_err_helper<Fun> {
std::forward<Fun>(function)
};
}

inline detail::collect_helper collect() {
return detail::collect_helper();
}
Expand Down
96 changes: 96 additions & 0 deletions zypp-core/zyppng/pipelines/operators.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*---------------------------------------------------------------------\
| ____ _ __ __ ___ |
| |__ / \ / / . \ . \ |
| / / \ V /| _/ _/ |
| / /__ | | | | | | |
| /_____||_| |_| |_| |
| |
----------------------------------------------------------------------/
*
* This file contains private API, this might break at any time between releases.
* You have been warned!
*/

#ifndef ZYPP_ZYPPNG_PIPELINES_OPERATORS_H
#define ZYPP_ZYPPNG_PIPELINES_OPERATORS_H

#include <utility>

namespace zyppng {

namespace detail {
template <typename Callback>
struct and_then_helper {
Callback function;

template< typename T >
auto operator()( T&& exp ) {
return and_then( std::forward<T>(exp), function );
}
};

template <typename Callback>
struct or_else_helper {
Callback function;

template< typename T >
auto operator()(T&& exp ) {
return or_else( std::forward<T>(exp), function );
}
};

template <typename Callback>
struct inspect_helper {
Callback function;

template< typename T>
auto operator()( T &&exp ) {
return inspect( std::forward<T>(exp), function );
}
};

template <typename Callback>
struct inspect_err_helper {
Callback function;

template< typename T>
auto operator()( T &&exp ) {
return inspect_err( std::forward<T>(exp), function );
}
};
}


namespace operators {
template <typename Fun>
auto inspect ( Fun && function ) {
return detail::inspect_helper<Fun> {
std::forward<Fun>(function)
};
}

template <typename Fun>
auto inspect_err ( Fun && function ) {
return detail::inspect_err_helper<Fun> {
std::forward<Fun>(function)
};
}

template <typename Fun>
auto and_then ( Fun && function ) {
return detail::and_then_helper<Fun> {
std::forward<Fun>(function)
};
}

template <typename Fun>
auto or_else ( Fun && function ) {
return detail::or_else_helper<Fun> {
std::forward<Fun>(function)
};
}
}

}

#endif
Loading

0 comments on commit d9af39f

Please sign in to comment.