Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] view madness in seqan2 #190

Merged
merged 4 commits into from
Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/ci_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ jobs:
fail-fast: false
matrix:
include:
- name: "gcc12"
install: "g++-12"
cxx: "g++-12"
cc: "gcc-12"
build_type: Release

- name: "gcc11"
install: "g++-11"
cxx: "g++-11"
Expand Down Expand Up @@ -88,7 +94,7 @@ jobs:
run: |
mkdir build
cd build
cmake ../lambda -DLAMBDA_COMPILE_THREADS=2 -DLAMBDA_NATIVE_BUILD=ON -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}" -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache
cmake ../lambda -DLAMBDA_COMPILE_THREADS=2 -DLAMBDA_NATIVE_BUILD=OFF -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}" -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache

- name: Build tests
if: matrix.name != 'clang_format'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
fail-fast: false
matrix:
include:
- name: "gcc11"
cxx: "g++-11"
cc: "gcc-11"
- name: "gcc12"
cxx: "g++-12"
cc: "gcc-12"
build_type: Release

- name: "gcc10"
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
run: |
mkdir build
cd build
cmake ../lambda -DLAMBDA_COMPILE_THREADS=3 -DLAMBDA_NATIVE_BUILD=ON -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}" -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache
cmake ../lambda -DLAMBDA_COMPILE_THREADS=3 -DLAMBDA_NATIVE_BUILD=OFF -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}" -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache

- name: Build tests
env:
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ if (LAMBDA_NATIVE_BUILD)
if (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xHOST -ipo -no-prec-div -fp-model fast=2")
endif (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
else (LAMBDA_NATIVE_BUILD)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmmx -msse -msse2 -msse3 -mssse3 -msse4 -mpopcnt")
endif (LAMBDA_NATIVE_BUILD)

if (LAMBDA_STATIC_BUILD)
Expand Down
224 changes: 224 additions & 0 deletions src/holder_tristate_overload.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
// ==========================================================================
// SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2018, Knut Reinert, FU Berlin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Knut Reinert or the FU Berlin nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: Andreas Gogol-Döring <[email protected]>
// ==========================================================================
// Tristate Holder Implementation.
// ==========================================================================

#pragma once

#include <seqan/basic.h>

using overload_t = std::ranges::take_view<std::ranges::drop_view<seqan3::detail::view_translate_single<std::ranges::ref_view<std::vector<seqan3::dna5>>>>>;

template <typename t>
concept overload_c = std::same_as<std::remove_cvref_t<t>, overload_t>;

namespace seqan
{

// ============================================================================
// Tags, Classes, Enums
// ============================================================================
template <overload_c TValue>
struct Holder<TValue, Tristate>
{
enum EHolderState
{
EMPTY = 0,
OWNER = 1,
DEPENDENT = 2
};

typedef std::optional<TValue> THostValue;

// ------------------------------------------------------------------------
// Members
// ------------------------------------------------------------------------

THostValue data_value;
EHolderState data_state;

// ------------------------------------------------------------------------
// Constructors; Destructor
// ------------------------------------------------------------------------

Holder() : data_value{}, data_state(EMPTY)
{
}

Holder(Holder const & source_) : data_value{}, data_state(EMPTY)
{
data_value = source_;
}

explicit
Holder(THostValue & value_) : data_value{}, data_state(EMPTY)
{
data_value = value_;
}

explicit
Holder(THostValue const & value_) : data_value{}, data_state(EMPTY)
{
data_value = value_;
}

~Holder()
{
clear(*this);
}

// ------------------------------------------------------------------------
// Assignment Operators; Must be defined in class.
// ------------------------------------------------------------------------

Holder & operator=(Holder const &) = default;

Holder & operator=(THostValue const & value_)
{
data_value = value_;
return *this;
}

// ------------------------------------------------------------------------
// Conversion Operators; Must be defined in class.
// ------------------------------------------------------------------------

inline operator THostValue()
{
return data_value;
}
};

// ============================================================================
// Functions
// ============================================================================

/// ----------------------------------------------------------------------------
// Function clear()
// ----------------------------------------------------------------------------

template <overload_c TValue>
inline void
clear(Holder<TValue, Tristate> & me)
{
me.data_value.reset();
me.data_state = Holder<TValue, Tristate>::EMPTY;
}

// ----------------------------------------------------------------------------
// Function setValue()
// ----------------------------------------------------------------------------

template <overload_c TValue>
inline void
setValue(Holder<TValue, Tristate> & me,
TValue const & value_)
{
me.data_value = value_;
me.data_state = Holder<TValue, Tristate>::OWNER;
}

template <overload_c TValue>
inline void
setValue(Holder<TValue const, Tristate> & me,
TValue const & value_)
{
me.data_value = value_;
me.data_state = Holder<TValue const, Tristate>::OWNER;
}

// ----------------------------------------------------------------------------
// Function value()
// ----------------------------------------------------------------------------

template <overload_c TValue>
auto & value(Holder<TValue, Tristate> & me)
{
SEQAN_ASSERT_NOT(empty(me)); // HERE BE DRAGONS!!!
return * me.data_value;
}

template <overload_c TValue>
auto & value(Holder<TValue, Tristate> const & me)
{
SEQAN_ASSERT_NOT(empty(me));

return * me.data_value;
}

// ----------------------------------------------------------------------------
// Function assignValue()
// ----------------------------------------------------------------------------

template <overload_c TValue, typename TSource>
inline void
assignValue(Holder<TValue, Tristate> & me,
TSource const & value_)
{
setValue(me, value_);
}

// ----------------------------------------------------------------------------
// Function moveValue()
// ----------------------------------------------------------------------------

template <overload_c TValue, typename TSource>
inline void
moveValue(Holder<TValue, Tristate> & me,
TSource const & value_)
{
setValue(me, value_);
}

// ----------------------------------------------------------------------------
// Function assign()
// ----------------------------------------------------------------------------

template <overload_c TValue>
inline void
assign(Holder<TValue, Tristate> & target_,
Holder<TValue, Tristate> const & source_)
{
target_ = source_;
}

template <overload_c TValue>
inline void
assign(Holder<TValue const, Tristate> & target_,
Holder<TValue const, Tristate> const & source_)
{
target_ = source_;
}

} // namespace seqan
20 changes: 20 additions & 0 deletions src/seqan2seqan3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ inline seqan3::gapped<alph_t> gapValueImpl(seqan3::gapped<alph_t> const *)
#include <seqan/score.h>
#include <seqan/sequence.h>

#include "holder_tristate_overload.h"
#include "bisulfite_scoring.hpp"

namespace seqan
Expand Down Expand Up @@ -214,6 +215,25 @@ struct GetValue<Iter<TContainer const, StdIteratorAdaptor>>
using Type = std::ranges::range_reference_t<TContainer const>;
};

template <overload_c TSequence>
decltype(auto) source(Gaps<TSequence, ArrayGaps> const & gaps)
{
return value(gaps._source);
}

template <overload_c TSequence>
decltype(auto) source(Gaps<TSequence, ArrayGaps> & gaps)
{
return value(gaps._source);
}

template <overload_c TSequence>
inline void assignSource(Gaps<TSequence, ArrayGaps> & gaps, TSequence const & source)
{
setValue(gaps._source, source);
_reinitArrayGaps(gaps);
}

// –---------------------------------------------------------------------------
// range stuff
// –---------------------------------------------------------------------------
Expand Down
23 changes: 20 additions & 3 deletions test/cli/index_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@

struct index_test : public cli_test
{
std::string md5_cmd;

void determine_md5_cmd()
{
if (std::system("echo foo | md5sum > /dev/null 2>&1") == 0)
md5_cmd = "md5sum";
else if (std::system("echo foo | md5 > /dev/null 2>&1") == 0)
md5_cmd = "md5";

ASSERT_FALSE(md5_cmd.empty());
}

void run_index_test(std::string const & index_command,
std::string const & db_file,
std::string const & index_file,
Expand All @@ -18,10 +30,15 @@ struct index_test : public cli_test
"--db-index-type", index_type,
"-r", reduction);

EXPECT_EQ(result.exit_code, 0);
ASSERT_EQ(result.exit_code, 0);

if (md5_cmd.empty())
determine_md5_cmd();

std::system(("md5sum " + index_file + " > md5sum_test.txt").c_str());
std::system(("md5sum " + (std::string) data(control_file) + " > md5sum_control.txt").c_str());
int ret = std::system((md5_cmd + " " + index_file + " > md5sum_test.txt").c_str());
ASSERT_TRUE(ret == 0);
ret = std::system((md5_cmd + " " + (std::string) data(control_file) + " > md5sum_control.txt").c_str());
ASSERT_TRUE(ret == 0);

std::ifstream test_output ("md5sum_test.txt");
std::ifstream control_output ("md5sum_control.txt");
Expand Down
Loading