text:
/*******************************************************************************
 *
 * MIT License
 *
 * Copyright (c) 2017 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 *******************************************************************************/

#ifndef GUARD_MIOPEN_SEQUENCES_HPP_
#define GUARD_MIOPEN_SEQUENCES_HPP_

#include <miopen/rank.hpp>

#include <boost/range/algorithm/find.hpp>

#include <algorithm>
#include <cassert>
#include <tuple>
#include <vector>

namespace miopen {
namespace seq {

/*
Sequence classes describe sets of unique oredered values.
To be a sequence class must follow the concept:

class Sequence
{
    using ValueType = <unspecified>;

    Sequence();

    // returns iterator pointint to the first element of the sequence.
    constexpr <unspecified> begin() const;

    // returns invalid iterator.
    constexpr <unspecified> end() const;

    // returns iterator pointing to element of sequence equal to value or end().
    // this method may not be implemented. boost::find will be used instead than.
    constexpr <unspecified> find(TValue value) const;
}

ValueType may have any constraints depending on specific sequences but it also must have operator==.
It is forbidden to use any of existing sequences with several equal values. It will lead to hangs.
Each of existing sequences which can produce such scenario has assert which will fail with a reason
of failure stated.
Example: sequence 1-2-1 will be looped as:

1-2-1 -> 1-2-1 -> 1-2-1 -> 1-2-1
|          |      |          |

and Next(...) will only return true because there is no way to distinguish if a value provided is
first or second 1. It may work in whatever way for user defined types and sequences but in common
case it simply won't work. It is quite obvious in case of Sequence<int, 1, 2, 1> but it may not be
with something more complex, even like Join<Span<int, 1, 6>, Span<int, 4, 8>>. But it will hang with
any use of Next(...) based loops so any real life like usage will show invalid work of Next(...).

RuleSet is main way to use the system. They represent a set of rules of iterating over a sequence of
value tupples. Affects all the fields speceified. Has several methods:
    bool IsIn(const Container& container) const - check if value of each field in container is in
        respective sequence.
    bool Next(Container& container) const - switch to the next permutation. Returns true when
        container passed had last value of respective sequence in each field. Uses Next methods of
        respective sequences.
    void FillBegin(Container& container) const - fills provided structure with begin() values
        of sequences.
    bool Compare(const Container& left, const Container& right) const - helper method comparing
        specified fields of provided values.
    bool IsEqualToBegin(const Container& container) const - helper method comparing specified
        fields of provided value with begin()s.

Here Container means type fullfiling member definitions. In most cases member definition will look
like &S::x, meaning that Container means S. There are no other constraints for it.

Simpliest way to define a RuleSet is by MakeRuleSet. Example:

    struct S { int x, y; };

    auto Rules()
    {
        return seq::MakeRuleSet(
            std::make_tuple(seq::Span<int, 0, 9>{}, &S::x),
            std::make_tuple(seq::Sequence<int, 1, 3, 7>{}, &S::y));
    }

    int TotalCombinations()
    {
        S s;
        int count = 0;
        Rules().FillBegin(s);

        while (!Rules().Next(s))
            count++;

        return count;
    }

So to make a ruleset you call MakeRuleSet and provide tuples as arguments.
Each tuple should contain a description of a sequence as first (#0) value and a pointer to member.
In the example the ruleset describes sequence with 0,1,2,3,4,5,6,7,8,9 as applicable values for
x field and 1,3,7 for y.

Predefined sequences:
Sequence - set of any values.
Span - span with lower and upper limits.
TwoPowersSpan - span of powers of 2.
Join - join of two or more sequences.
Multiplied - sequence with each member multipled by factor.

One may argue that it is bad to pass a pointer to member as run-time value and it should only be
passed as template argument (as it can be) but there are two main reasons explaining why it is
done like it is done.
1. Expression
    int TestData::*, &TestData::x
compared to
    &TestData::x
is longer and has unrequired and duplicated code.
2. A test was made to show that it has no if any impact on execution time. It is saved as
speedtests/sequences.cpp and may be muilt as target speedtest_sequences and run as
bin/speedtest_sequences --mode std
bin/speedtest_sequences --mode tmpl
for field and template argument stored pointers respectively.

Examples of real life usages may be found in:
    src/solver/conv_asm_1x1u.cpp
    src/solver/conv_asm_3x3u.cpp
    src/solver/conv_asm_dir_BwdWrW1x1.cpp
    src/solver/conv_asm_dir_BwdWrW3x3.cpp

Rule class is not required to use RuleSet via MakeRuleSet or sequences directly mostly it's like a
sequence but operating a specified field of a class and contains several helper methods.

MemberPtr and MakeMemberPtr are used to make a pointer to member for rules.
They are not needed for external usage of rulesets but in case of need it is easy to extend the
system to accept getters/setters or whatever.

Example of extending the system may be found at
    speedtests/sequences.cpp

Existing sequences in this file may be used as an example of creating a custom sequence.
Span and Multiplied are arguably the simpliest.
 */

template <class TRange, class TValue>
auto GenericFindImpl(rank<1>, const TRange& range, const TValue& value)
    -> decltype(range.find(value))
{
    return range.find(value);
}

template <class TRange, class TValue>
auto GenericFindImpl(rank<0>, const TRange& range, const TValue& value)
{
    return boost::find(range, value);
}

template <class TRange, class TValue>
auto GenericFind(const TRange& range, const TValue& value)
{
    return GenericFindImpl(rank<16>{}, range, value);
}

/// The simpliest of sequences provided. It contains int values supplied as template arguments.
template <class TValue, TValue... values>
struct Sequence
{
    using const_iterator = const TValue*;
    using ValueType      = TValue;

    Sequence() { assert(ValidateValues() && "Values must be unique"); }

    constexpr const_iterator begin() const { return data.begin(); }
    constexpr const_iterator end() const { return data.end(); }
    constexpr const_iterator find(const TValue& value) const { return data.data() + find_(value); }

    private:
    static constexpr std::array<int, sizeof...(values)> data = {{values...}};

    static constexpr int ValuesCount() { return sizeof...(values); }

    static constexpr bool ValidateValues()
    {
        for(auto i = 0; i < ValuesCount() - 1; ++i)
            for(auto j = i + 1; j < ValuesCount(); ++j)
                if(data[i] == data[j])
                    return false;

        return true;
    }

    template <int icur, TValue cur, TValue... rest>
    struct Find
    {
        int operator()(const TValue& value) const
        {
            if(value == cur)
                return icur;
            return rest_(value);
        }

        Find<icur + 1, rest...> rest_ = {};
    };

    template <int icur, TValue cur>
    struct Find<icur, cur>
    {
        int operator()(const TValue& value) const
        {
            if(value == cur)
                return icur;
            return icur + 1;
        }
    };

    Find<0, values...> find_ = {};
};

template <class TValue, TValue... values>
constexpr std::array<int, sizeof...(values)>
    Sequence<TValue, values...>::data; // Sometimes can't link without of this line

template <class TValue>
struct SequenceIteratorBase
{
    SequenceIteratorBase() = default;
    SequenceIteratorBase(TValue value_) : value(value_) {}

    TValue operator*() const { return value; }

    protected:
    TValue value = {};
};

template <class TValue, int high>
struct SpanIterator : public SequenceIteratorBase<TValue>
{
    SpanIterator() : SequenceIteratorBase<TValue>(high + 1) {}
    SpanIterator(TValue value_) : SequenceIteratorBase<TValue>(value_) {}

    SpanIterator& operator++()
    {
        this->value = this->value + 1;
        return *this;
    }

    const SpanIterator operator++(int) // NOLINT (readability-const-return-type)
    {
        const auto copy = *this;
        ++*this;
        return copy;
    }

    bool operator==(const SpanIterator& other) const
    {
        return this->value == other.value || (this->value > high && other.value > high);
    }

    bool operator!=(const SpanIterator& other) const { return !(*this == other); }
};

/// A sequence describing a span. It describes [low; high]. Type implementing + and == is required.
template <class TValue, TValue low, TValue high>
struct Span
{
    using const_iterator = SpanIterator<int, high>;
    using ValueType      = TValue;

    constexpr const_iterator begin() const { return {low}; }
    constexpr const_iterator end() const { return {}; }

    constexpr const_iterator find(TValue value) const
    {
        static_assert(low < high, "Span low limit should be actually lower than high.");
        if(value >= low && value <= high)
            return {value};
        return end();
    }
};

template <class TValue, TValue high>
struct TwoPowersSpanIterator : public SequenceIteratorBase<TValue>
{
    TwoPowersSpanIterator(TValue value_) : SequenceIteratorBase<TValue>(value_) {}

    TwoPowersSpanIterator& operator++()
    {
        this->value = this->value * 2;
        return *this;
    }

    const TwoPowersSpanIterator operator++(int) // NOLINT (readability-const-return-type)
    {
        const auto copy = *this;
        ++*this;
        return copy;
    }

    bool operator==(const TwoPowersSpanIterator& other) const
    {
        return this->value == other.value || (this->value > high && other.value > high);
    }

    bool operator!=(const TwoPowersSpanIterator& other) const { return !(*this == other); }
};

/// A sequence containing a span of powers of two. x in [low; high] and x = 2^n. Only integer types
/// are allowed.
template <class TValue, TValue low, TValue high>
struct TwoPowersSpan
{
    using const_iterator = TwoPowersSpanIterator<int, high>;
    using ValueType      = TValue;

    constexpr const_iterator begin() const { return {low}; }
    constexpr const_iterator end() const { return {high + 1}; }

    constexpr const_iterator find(TValue i) const
    {
        static_assert(low < high, "TwoPowersSpan low limit should be actually lower than high.");
        static_assert(IsTwoPower(low), "TwoPowersSpan low limit should be actually power of two.");
        static_assert(IsTwoPower(high),
                      "TwoPowersSpan high limit should be actually power of two.");

        if(IsTwoPower(i) && low <= i && i <= high)
            return {i};

        return end();
    }

    private:
    static constexpr bool IsTwoPower(TValue i) { return ((i - 1) & i) == 0; }
};

template <class TFirst, class... TRest>
struct JoinIterator : public SequenceIteratorBase<typename TFirst::ValueType>
{
    using ValueType = typename TFirst::ValueType;

    JoinIterator() : SequenceIteratorBase<ValueType>(0) {}
    JoinIterator(ValueType value_) : SequenceIteratorBase<ValueType>(value_), finished(false) {}

    JoinIterator& operator++()
    {
        finished = Next<TFirst, TRest...>{}(this->value);
        return *this;
    }

    const JoinIterator operator++(int) // NOLINT (readability-const-return-type)
    {
        const auto copy = *this;
        ++*this;
        return copy;
    }

    operator bool() const { return !finished; }

    bool operator==(const JoinIterator& other) const
    {
        return (this->value == other.value && *this && other) || (!*this && !other);
    }

    bool operator!=(const JoinIterator& other) const { return !(*this == other); }

    private:
    bool finished = true;

    template <class...>
    struct Next
    {
    };

    template <class TCur, class TNext, class... TRest_>
    struct Next<TCur, TNext, TRest_...>
    {
        bool operator()(ValueType& value)
        {
            auto it = GenericFind(cur, value);

            if(it == cur.end())
                return rest(value);

            if(++it == cur.end())
            {
                value = *next.begin();
                return false;
            }

            value = *it;
            return false;
        }

        private:
        TCur cur                    = {};
        TNext next                  = {};
        Next<TNext, TRest_...> rest = {};
    };

    template <class TSeq>
    struct Next<TSeq>
    {
        bool operator()(ValueType& value)
        {
            auto it = GenericFind(seq, value);

            assert(it != seq.end());
            if(++it == seq.end())
                return true;

            value = *it;
            return false;
        }

        private:
        TSeq seq = {};
    };
};

/// A union of one or more sequences.
template <class TFirst, class... TRest>
struct Join
{
    using ValueType      = typename TFirst::ValueType;
    using const_iterator = JoinIterator<TFirst, TRest...>;

    Join() { assert(Validate() && "Values must be unique"); }

    constexpr const_iterator begin() const { return {*first.begin()}; }
    constexpr const_iterator end() const { return {}; }
    constexpr const_iterator find(ValueType value) const { return find_(value); }

    private:
    template <class TCur, class... TRest_>
    struct Find
    {
        const_iterator operator()(ValueType value) const
        {
            auto it = cur(value);
            return it ? it : rest(value);
        }

        private:
        Find<TCur> cur       = {};
        Find<TRest_...> rest = {};
    };

    template <class TSeq>
    struct Find<TSeq>
    {
        const_iterator operator()(ValueType value) const
        {
            auto it = GenericFind(seq, value);

            if(it != seq.end())
                return {*it};

            return {};
        }

        private:
        TSeq seq = {};
    };

    bool Validate() const
    {
        auto cur = begin();
        std::vector<ValueType> values(1, *cur);

        while(++cur != end())
        {
            if(std::find(values.begin(), values.end(), *cur) != values.end())
                return false;

            values.push_back(*cur);
        }

        return true;
    }

    TFirst first                 = {};
    Find<TFirst, TRest...> find_ = {};
};

template <class TInner, typename TInner::ValueType mul>
struct MultipliedIterator
{
    using InnerIterator = typename TInner::const_iterator;
    using ValueType     = typename TInner::ValueType;

    MultipliedIterator(InnerIterator inner_) : inner(inner_) {}

    MultipliedIterator& operator++()
    {
        ++inner;
        return *this;
    }

    const MultipliedIterator operator++(int) // NOLINT (readability-const-return-type)
    {
        const auto copy = *this;
        ++*this;
        return copy;
    }

    ValueType operator*() const { return mul * *inner; }
    bool operator==(const MultipliedIterator& other) const { return inner == other.inner; }
    bool operator!=(const MultipliedIterator& other) const { return !(*this == other); }

    private:
    InnerIterator inner = {};
};

/// A sequence containing values of another sequence multiplied by a constant.
template <class TInner, typename TInner::ValueType mul>
struct Multiplied
{
    using ValueType      = typename TInner::ValueType;
    using const_iterator = MultipliedIterator<TInner, mul>;

    constexpr const_iterator begin() const { return {inner.begin()}; }
    constexpr const_iterator end() const { return {inner.end()}; }
    constexpr const_iterator find(ValueType value) const
    {
        return {GenericFind(inner, value / mul)};
    }

    private:
    TInner inner = {};
};

/// A common declaration for member pointer containing types. Implementations should have
/// a ctor accepting what they pass as MemberPtr template arguments.
template <class...>
struct MemberPtr
{
};

/// An explicit declaration for pointers to fields.
template <class TType, class TContainer>
struct MemberPtr<TType TContainer::*>
{
    using Container = TContainer;

    MemberPtr(TType TContainer::*field_) : field(field_) {}

    const TType& RV(const TContainer& cont) const { return cont.*field; }
    TType& LV(TContainer& cont) const { return cont.*field; }

    private:
    TType TContainer::*field;
};

/// A helper method for declaring MemberPtr's
template <class... TParams>
inline auto MakeMemberPtr(TParams... args)
{
    return MemberPtr<TParams...>(args...);
}

template <class TValue, TValue, TValue...>
struct SeqNextImpl_Sequence
{
};

template <class TValue, TValue first, TValue cur, TValue next, TValue... values>
struct SeqNextImpl_Sequence<TValue, first, cur, next, values...>
{
    bool operator()(TValue& value) const
    {
        if(value == cur)
        {
            value = next;
            return false;
        }

        return rest(value);
    }

    private:
    SeqNextImpl_Sequence<TValue, first, next, values...> rest = {};
};

template <class TValue, TValue first, TValue cur>
struct SeqNextImpl_Sequence<TValue, first, cur>
{
    bool operator()(TValue& value) const
    {
        assert(value == cur);
        value = first;
        return true;
    }
};

template <class TValue, TValue first, TValue... values>
bool SeqNextImpl(rank<1>, const Sequence<TValue, first, values...>&, TValue& value)
{
    return SeqNextImpl_Sequence<TValue, first, first, values...>{}(value);
}

template <class TSequence>
bool SeqNextImpl(rank<0>, const TSequence& seq, typename TSequence::ValueType& value)
{
    auto it = GenericFind(seq, value);

    assert(it != seq.end());
    if(++it == seq.end())
    {
        value = *seq.begin();
        return true;
    }

    value = *it;
    return false;
}

template <class TSequence>
bool SeqNext(const TSequence& seq, typename TSequence::ValueType& value)
{
    return SeqNextImpl(rank<16>{}, seq, value);
}

/// A rule applying a sequence to a specified member of a specified class instance provided.
/// Also contains Compare and IsEqualToBegin helper methods.
template <class TMember, class TSequence>
struct Rule
{
    using Container = typename TMember::Container;

    Rule(const TMember& member_) : member(member_) {}

    bool IsIn(const Container& container) const
    {
        return GenericFind(sequence, member.RV(container)) != sequence.end();
    }

    bool Next(Container& container) const { return SeqNext(sequence, member.LV(container)); }

    void FillBegin(Container& container) const { member.LV(container) = *sequence.begin(); }

    /// Compares provided members of two values.
    bool Compare(const Container& left, const Container& right) const
    {
        return member.RV(left) == member.RV(right);
    }

    /// Check if value provided is equal to the begin value of the sequence.
    bool IsEqualToBegin(const Container& container) const
    {
        return member.RV(container) == *sequence.begin();
    }

    private:
    TMember member;
    TSequence sequence = {};
};

/// Rule creation helper.
template <class TMember, class TSequence>
inline auto MakeRule(const TMember& member, TSequence)
{
    return Rule<TMember, TSequence>(member);
}

/// A type describing a set of rules and applying them to a provided value.
/// Rules must be of type Rule<...>.
/// Also provides Compare and IsEqualToBegin helper methods.
template <class TFirst, class... TRules>
struct RuleSet
{
    using Container = typename TFirst::Container;

    RuleSet(TFirst first, TRules... rules) : impl(first, rules...) {}

    bool IsIn(const Container& container) const { return impl.IsIn(container); }

    bool Next(Container& container) const { return impl.Next(container); }

    void FillBegin(Container& container) const { impl.FillBegin(container); }

    /// Compares all the fields specified in rules.
    bool Compare(const Container& left, const Container& right) const
    {
        return impl.Compare(left, right);
    }

    /// Compares all the fields specified in rules to appropriate begin() values.
    bool IsEqualToBegin(const Container& container) const { return impl.IsEqualToBegin(container); }

    private:
    template <class...>
    struct Impl
    {
    };

    template <class TRule, class... TRest>
    struct Impl<TRule, TRest...>
    {
        Impl(const TRule& rule_, TRest... rest_) : rule(rule_), rest(rest_...) {}

        bool IsIn(const Container& container) const
        {
            return rule.IsIn(container) && rest.IsIn(container);
        }

        bool Next(Container& container) const
        {
            if(!rule.Next(container))
                return false;

            return rest.Next(container);
        }

        void FillBegin(Container& container) const
        {
            rule.FillBegin(container);
            rest.FillBegin(container);
        }

        bool Compare(const Container& left, const Container& right) const
        {
            return rule.Compare(left, right) && rest.Compare(left, right);
        }

        bool IsEqualToBegin(const Container& container) const
        {
            return rule.IsEqualToBegin(container) && rest.IsEqualToBegin(container);
        }

        private:
        TRule rule;
        Impl<TRest...> rest;
    };

    template <class TRule>
    struct Impl<TRule>
    {
        Impl(const TRule& rule_) : rule(rule_) {}

        bool IsIn(const Container& container) const { return rule.IsIn(container); }

        bool Next(Container& container) const { return rule.Next(container); }

        void FillBegin(Container& container) const { rule.FillBegin(container); }

        bool Compare(const Container& left, const Container& right) const
        {
            return rule.Compare(left, right);
        }

        bool IsEqualToBegin(const Container& container) const
        {
            return rule.IsEqualToBegin(container);
        }

        private:
        TRule rule;
    };

    Impl<TFirst, TRules...> impl;
};

namespace detail {
template <class TTuple, std::size_t first, std::size_t... indexes>
auto MakeMemberPtrFromTuple(const TTuple& tuple, std::index_sequence<first, indexes...>)
{
    return MakeMemberPtr(std::get<indexes>(tuple)...);
}

/// A function making MemberPtr from tuples from MakeRuleSet.
template <class TTuple>
auto MakeMemberPtrFromTuple(const TTuple& tuple)
{
    return MakeMemberPtrFromTuple(tuple,
                                  std::make_index_sequence<std::tuple_size<TTuple>::value>{});
}

/// A type making a rule type from a tuple passed to MakeRuleSet.
template <class TTuple>
struct RuleFromTuple
{
    private:
    using Sequence      = typename std::tuple_element<0, TTuple>::type;
    using MemberPtrType = decltype(MakeMemberPtrFromTuple(std::declval<TTuple>()));

    public:
    using Type = Rule<MemberPtrType, Sequence>;
};
} // namespace detail

template <class... TTuples>
auto MakeRuleSet(TTuples... rules)
{
    return RuleSet<typename detail::RuleFromTuple<TTuples>::Type...>(
        MakeRule(detail::MakeMemberPtrFromTuple(rules), std::get<0>(rules))...);
}

} // namespace seq
} // namespace miopen

#endif // GUARD_MIOPEN_SEQUENCES_HPP_


text:
#ifndef MPI_BOOST_MPI_BOOSTMPIPROVIDER_HPP_
#define MPI_BOOST_MPI_BOOSTMPIPROVIDER_HPP_

#include "MPIProvider.hpp"
#include <boost/mpi.hpp>

namespace xacc {
namespace vqe {

class BoostCommunicator : public Communicator {

protected:
	boost::mpi::communicator comm;
public:

	BoostCommunicator(boost::mpi::communicator& c) :comm(c) {}

	virtual const int rank() {
		return comm.rank();
	}

	virtual const int size() {
		return comm.size();
	}

	virtual void broadcast(std::vector<double>& d, const int r) {
		boost::mpi::broadcast(comm, d, r);
	}

	virtual void broadcast(std::string& s, const int r) {
		boost::mpi::broadcast(comm, s, r);
	}

	virtual void sumDoubles(double& myVal, double& result) {
		boost::mpi::all_reduce(comm, myVal, result, std::plus<double>());
	}

	virtual void sumInts(int& myVal, int& result) {
		boost::mpi::all_reduce(comm, myVal, result, std::plus<int>());
	}

	virtual void maxDouble(double& myVal, double& result) {
		boost::mpi::all_reduce(comm, myVal, result, boost::mpi::maximum<double>());
	}

	virtual ~BoostCommunicator() {}

};

class BoostMPIProvider : public MPIProvider {

protected:

	std::shared_ptr<boost::mpi::environment> env;

	std::shared_ptr<Communicator> comm;
public:

	virtual void initialize() {
		if (!env) env = std::make_shared<boost::mpi::environment>();
		boost::mpi::communicator c;
		comm = std::make_shared<BoostCommunicator>(c);
	}

	virtual void initialize(int argc, char** argv) {
		env = std::make_shared<boost::mpi::environment>(argc, argv);
		boost::mpi::communicator c;
		comm = std::make_shared<BoostCommunicator>(c);
	}

	virtual std::shared_ptr<Communicator> getCommunicator() {
		return comm;
	}

	virtual const std::string name() const {
		return "boost-mpi";
	}

	virtual const std::string description() const {
		return "";
	}

	virtual ~BoostMPIProvider() {}
};

}
}
#endif

ext: hpp


text:
#ifndef BOOST_SERIALIZATION_TEST_A_HPP
#define BOOST_SERIALIZATION_TEST_A_HPP

// MS compatible compilers support #pragma once
#if defined(_MSC_VER)
# pragma once
#endif

/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// A.hpp    simple class test

// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to 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)

//  See http://www.boost.org for updates, documentation, and revision history.

#include <ostream> // for friend output operators
#include <cstddef> // size_t
#include <boost/config.hpp>

#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
    using ::size_t;
}
#endif

#include <boost/limits.hpp>
#include <boost/cstdint.hpp>

#include <boost/serialization/access.hpp>
#include <boost/serialization/string.hpp>

#if defined(A_IMPORT)
    #define A_DLL_DECL BOOST_SYMBOL_IMPORT
    #pragma message("A imported")
#elif defined(A_EXPORT)
    #define A_DLL_DECL BOOST_SYMBOL_EXPORT
    #pragma message ("A exported")
#else
    #define A_DLL_DECL
#endif

class A_DLL_DECL A {
private:
    friend class boost::serialization::access;
    template<class Archive>
    void serialize(
        Archive &ar,
        const unsigned int /* file_version */
    );
    bool b;
    #ifndef BOOST_NO_INT64_T
    boost::int64_t f;
    boost::uint64_t g;
    #endif
    enum h {
        i = 0,
        j,
        k
    } l;
    std::size_t m;
    signed long n;
    unsigned long o;
    signed  short p;
    unsigned short q;
    #ifndef BOOST_NO_CWCHAR
    wchar_t r;
    #endif
    char c;
    signed char s;
    unsigned char t;
    signed int u;
    unsigned int v;
    float w;
    double x;
    std::string y;
    #ifndef BOOST_NO_STD_WSTRING
    std::wstring z;
    #endif
public:
    A();
    bool check_equal(const A &rhs) const;
    bool operator==(const A &rhs) const;
    bool operator!=(const A &rhs) const;
    bool operator<(const A &rhs) const; // used by less
    // hash function for class A
    operator std::size_t () const;
    friend std::ostream & operator<<(std::ostream & os, A const & a);
};

#endif // BOOST_SERIALIZATION_TEST_A_HPP


text:
#include <boost/python.hpp>
#include <Python.h>

#include <Executer.h>
#include <Interceptor.h>

using namespace boost::python;

Executer::Executer () {
    //logger = log4cxx::Logger::getLogger("Console.Executer");
    // Initialize context
    Py_Initialize();
    //LOG4CXX_INFO(logger, "Python environment initialized");
    // Retrieve the main module
    object main_module((handle<>(borrowed(PyImport_AddModule("__main__")))));
    // Retrieve the main module's namespace
    main_namespace = main_module.attr("__dict__");
    //LOG4CXX_INFO(logger, "Borrowed reference to main module");
}

Executer::~Executer () {
    Py_Finalize();
    //LOG4CXX_INFO(logger, "Python environment destroyed");
}

void Executer::execute (QString command) {
    //LOG4CXX_INFO(logger, "Executing \"" << command << "\"");

    if(!command.endsWith('\n'))
        command.append("\n");

    PyRun_SimpleString(command.toUtf8().constData());
}

object Executer::get_main_namespace() {
    //LOG4CXX_DEBUG(logger, "Getting main namespace");
    return main_namespace;
}

ext: cpp

max_stars_repo_name: szmurlor/fiver

max_issues_repo_name: szmurlor/fiver

max_forks_repo_name: szmurlor/fiver


text:
#define BOOST_TEST_MODULE MRC_Test
#include <boost/test/included/unit_test.hpp>

#include "mrsrc.h"

BOOST_AUTO_TEST_CASE(test_1)
{
	mrsrc::rsrc r1("resource-1.txt");

	BOOST_ASSERT((bool)r1);

	BOOST_TEST(r1.data() != nullptr);
	BOOST_TEST(r1.size() == 50);

	int r = std::memcmp(r1.data(), R"(This is the first line
And this is the second line)", r1.size());

	BOOST_TEST(r == 0);
}

BOOST_AUTO_TEST_CASE(test_2)
{
	mrsrc::rsrc r2("resource-2.txt");

	BOOST_ASSERT((bool)r2);

	BOOST_TEST(r2.data() != nullptr);
	BOOST_TEST(r2.size() == 102);
/*
		const char16_t* t = u"\xfeffThis is the first line\
And this is the second line";
		// t[0] = 0xfeff;

		int r = std::memcmp(r2.data(), (char*)t, r2.size());

		BOOST_TEST(r == 0);
*/
}

BOOST_AUTO_TEST_CASE(test_3)
{
	mrsrc::streambuf buf("resource-1.txt");
	std::istream is(&buf);

	std::string line;
	BOOST_TEST((bool)std::getline(is, line));
	BOOST_TEST(line == "This is the first line");
	BOOST_TEST((bool)std::getline(is, line));
	BOOST_TEST(line == "And this is the second line");
	BOOST_TEST(not std::getline(is, line));
}

BOOST_AUTO_TEST_CASE(test_4)
{
	mrsrc::istream is("resource-1.txt");

	std::string line;
	BOOST_TEST((bool)std::getline(is, line));
	BOOST_TEST(line == "This is the first line");
	BOOST_TEST((bool)std::getline(is, line));
	BOOST_TEST(line == "And this is the second line");
	BOOST_TEST(not std::getline(is, line));
}

BOOST_AUTO_TEST_CASE(test_10)
{
	mrsrc::rsrc r0("");

	BOOST_TEST(std::distance(r0.begin(), r0.end()) == 3);

	std::set<std::string> found;
	for (auto& r1: r0)
		found.insert(r1.name());

	std::set<std::string> kTest{"resource-1.txt", "resource-2.txt", "subdir"};

	BOOST_TEST(found == kTest);

	if (found != kTest)
	{
		for (auto& f: found)
			std::cout << f << std::endl;
	}
}

BOOST_AUTO_TEST_CASE(test_11)
{
	mrsrc::rsrc r0("subdir/resource-3.txt");

	BOOST_TEST((bool)r0);

	mrsrc::istream is(r0);
	std::string line;
	BOOST_TEST((bool)std::getline(is, line));
	BOOST_TEST(line == "Dit is resource 3");
}

BOOST_AUTO_TEST_CASE(test_12)
{
	mrsrc::rsrc r0("subdir/subsubdir/resource-4.txt");

	BOOST_TEST((bool)r0);

	mrsrc::istream is(r0);
	std::string line;
	BOOST_TEST((bool)std::getline(is, line));
	BOOST_TEST(line == "Dit is resource 4");
}

max_stars_repo_name: mhekkel/mrc

max_issues_repo_name: mhekkel/mrc

max_forks_repo_name: mhekkel/mrc


text:
#include <boost/test/unit_test.hpp>
#include <util/ustring/UString.h>
#include <algorithm>

#define scoped_alloc NULL_ALLOCATOR

using namespace std;
using namespace izenelib::util;;
using namespace boost::unit_test;
using namespace boost;

BOOST_AUTO_TEST_SUITE(FindChar_test)

BOOST_AUTO_TEST_CASE(Empty_test)
{
    UString ustr;
    BOOST_CHECK_EQUAL(UString::npos, ustr.find('a'));
}

BOOST_AUTO_TEST_CASE(First_test)
{
    UString ustr("123", UString::UTF_8);
    BOOST_CHECK_EQUAL(0U, ustr.find('1'));
}
BOOST_AUTO_TEST_CASE(Middle_test)
{
    UString ustr("123", UString::UTF_8);
    BOOST_CHECK_EQUAL(1U, ustr.find('2'));
}
BOOST_AUTO_TEST_CASE(Last_test)
{
    UString ustr("123", UString::UTF_8);
    BOOST_CHECK_EQUAL(2U, ustr.find('3'));
}
BOOST_AUTO_TEST_CASE(NotFound_test)
{
    UString ustr("123", UString::UTF_8);
    BOOST_CHECK_EQUAL(UString::npos, ustr.find('0'));
    BOOST_CHECK_EQUAL(UString::npos, ustr.find('4'));
}

BOOST_AUTO_TEST_CASE(BeforePos_test)
{
    UString ustr("123", UString::UTF_8);
    BOOST_CHECK_EQUAL(UString::npos, ustr.find('2', 2));
}

BOOST_AUTO_TEST_CASE(AfterPos_test)
{
    UString ustr("123", UString::UTF_8);
    BOOST_CHECK_EQUAL(1U, ustr.find('2', 0));
}

BOOST_AUTO_TEST_CASE(AtPos_test)
{
    UString ustr("123", UString::UTF_8);
    BOOST_CHECK_EQUAL(1U, ustr.find('2', 1));
}

BOOST_AUTO_TEST_SUITE_END() // Find_test

#undef scoped_alloc

max_stars_repo_name: izenecloud/izenelib

max_issues_repo_name: izenecloud/izenelib

max_forks_repo_name: izenecloud/izenelib


text: #include <boost/type_traits/is_base_of_tr1.hpp>

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino


text:
//          Copyright Oliver Kowalke 2013.
// 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)
//
// This test is based on the tests of Boost.Thread

#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <mutex>
#include <stdexcept>
#include <vector>

#include <boost/test/unit_test.hpp>

#include <boost/fiber/all.hpp>

typedef std::chrono::nanoseconds  ns;
typedef std::chrono::milliseconds ms;

int value1 = 0;

inline
std::chrono::system_clock::time_point delay(int secs, int msecs = 0, int /*nsecs*/ = 0) {
    std::chrono::system_clock::time_point t = std::chrono::system_clock::now();
    t += std::chrono::seconds( secs);
    t += std::chrono::milliseconds( msecs);
    //t += std::chrono::nanoseconds( nsecs);

    return t;
}

struct condition_test_data {
    condition_test_data() : notified(0), awoken(0) { }

    boost::fibers::mutex mutex;
    boost::fibers::condition_variable cond;
    int notified;
    int awoken;
};

void condition_test_fiber(condition_test_data* data) {
    std::unique_lock<boost::fibers::mutex> lock(data->mutex);
    BOOST_CHECK(lock ? true : false);
    while (!(data->notified > 0))
        data->cond.wait(lock);
    BOOST_CHECK(lock ? true : false);
    data->awoken++;
}

struct cond_predicate {
    cond_predicate(int& var, int val) : _var(var), _val(val) { }

    bool operator()() { return _var == _val; }

    int& _var;
    int _val;
private:
    void operator=(cond_predicate&);

};

void notify_one_fn( boost::fibers::condition_variable & cond) {
	cond.notify_one();
}

void notify_all_fn( boost::fibers::condition_variable & cond) {
	cond.notify_all();
}

void wait_fn(
	boost::fibers::mutex & mtx,
	boost::fibers::condition_variable & cond) {
	std::unique_lock< boost::fibers::mutex > lk( mtx);
	cond.wait( lk);
	++value1;
}

void test_one_waiter_notify_one() {
	value1 = 0;
	boost::fibers::mutex mtx;
	boost::fibers::condition_variable cond;

    boost::fibers::fiber f1(
                boost::fibers::launch::dispatch,
                wait_fn,
                std::ref( mtx),
                std::ref( cond) );
	BOOST_CHECK_EQUAL( 0, value1);

	boost::fibers::fiber f2(
                boost::fibers::launch::dispatch,
                notify_one_fn,
                std::ref( cond) );

	BOOST_CHECK_EQUAL( 0, value1);

    f1.join();
    f2.join();

	BOOST_CHECK_EQUAL( 1, value1);
}

void test_two_waiter_notify_one() {
	value1 = 0;
	boost::fibers::mutex mtx;
	boost::fibers::condition_variable cond;

    boost::fibers::fiber f1(
                boost::fibers::launch::dispatch,
                wait_fn,
                std::ref( mtx),
                std::ref( cond) );
	BOOST_CHECK_EQUAL( 0, value1);

    boost::fibers::fiber f2(
                boost::fibers::launch::dispatch,
                wait_fn,
                std::ref( mtx),
                std::ref( cond) );
	BOOST_CHECK_EQUAL( 0, value1);

    boost::fibers::fiber f3(
                boost::fibers::launch::dispatch,
                notify_one_fn,
                std::ref( cond) );
	BOOST_CHECK_EQUAL( 0, value1);

    boost::fibers::fiber f4(
                boost::fibers::launch::dispatch,
                notify_one_fn,
                std::ref( cond) );
	BOOST_CHECK_EQUAL( 1, value1);

    f1.join();
    f2.join();
    f3.join();
    f4.join();

	BOOST_CHECK_EQUAL( 2, value1);
}

void test_two_waiter_notify_all() {
	value1 = 0;
	boost::fibers::mutex mtx;
	boost::fibers::condition_variable cond;

    boost::fibers::fiber f1(
                boost::fibers::launch::dispatch,
                wait_fn,
                std::ref( mtx),
                std::ref( cond) );
	BOOST_CHECK_EQUAL( 0, value1);

    boost::fibers::fiber f2(
                boost::fibers::launch::dispatch,
                wait_fn,
                std::ref( mtx),
                std::ref( cond) );
	BOOST_CHECK_EQUAL( 0, value1);

    boost::fibers::fiber f3(
                boost::fibers::launch::dispatch,
                notify_all_fn,
                std::ref( cond) );
	BOOST_CHECK_EQUAL( 0, value1);

    boost::fibers::fiber f4(
                boost::fibers::launch::dispatch,
                wait_fn,
                std::ref( mtx),
                std::ref( cond) );
	BOOST_CHECK_EQUAL( 2, value1);

    boost::fibers::fiber f5(
                boost::fibers::launch::dispatch,
                notify_all_fn,
                std::ref( cond) );
	BOOST_CHECK_EQUAL( 2, value1);

    f1.join();
    f2.join();
    f3.join();
    f4.join();
    f5.join();

	BOOST_CHECK_EQUAL( 3, value1);
}

int test1 = 0;
int test2 = 0;

int runs = 0;

void fn1( boost::fibers::mutex & m, boost::fibers::condition_variable & cv) {
    std::unique_lock< boost::fibers::mutex > lk( m);
    BOOST_CHECK(test2 == 0);
    test1 = 1;
    cv.notify_one();
    while (test2 == 0) {
        cv.wait(lk);
    }
    BOOST_CHECK(test2 != 0);
}

void fn2( boost::fibers::mutex & m, boost::fibers::condition_variable & cv) {
    std::unique_lock< boost::fibers::mutex > lk( m);
    BOOST_CHECK(test2 == 0);
    test1 = 1;
    cv.notify_one();
    std::chrono::system_clock::time_point t0 = std::chrono::system_clock::now();
    std::chrono::system_clock::time_point t = t0 + ms(250);
    int count=0;
    while (test2 == 0 && cv.wait_until(lk, t) == boost::fibers::cv_status::no_timeout)
        count++;
    std::chrono::system_clock::time_point t1 = std::chrono::system_clock::now();
    if (runs == 0) {
        BOOST_CHECK(t1 - t0 < ms(250));
        BOOST_CHECK(test2 != 0);
    } else {
        BOOST_CHECK(t1 - t0 - ms(250) < ms(count*250+100+1000));
        BOOST_CHECK(test2 == 0);
    }
    ++runs;
}

class Pred {
     int    &   i_;

public:
    explicit Pred(int& i) :
        i_(i)
    {}

    bool operator()()
    { return i_ != 0; }
};

void fn3( boost::fibers::mutex & m, boost::fibers::condition_variable & cv) {
    std::unique_lock< boost::fibers::mutex > lk( m);
    BOOST_CHECK(test2 == 0);
    test1 = 1;
    cv.notify_one();
    std::chrono::steady_clock::time_point t0 = std::chrono::steady_clock::now();
    std::chrono::steady_clock::time_point t = t0 + ms(250);
    bool r = cv.wait_until(lk, t, Pred(test2));
    std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();
    if (runs == 0) {
        BOOST_CHECK(t1 - t0 < ms(250));
        BOOST_CHECK(test2 != 0);
        BOOST_CHECK(r);
    } else {
        BOOST_CHECK(t1 - t0 - ms(250) < ms(250+100));
        BOOST_CHECK(test2 == 0);
        BOOST_CHECK(!r);
    }
    ++runs;
}

void fn4( boost::fibers::mutex & m, boost::fibers::condition_variable & cv) {
    std::unique_lock< boost::fibers::mutex > lk( m);
    BOOST_CHECK(test2 == 0);
    test1 = 1;
    cv.notify_one();
    std::chrono::steady_clock::time_point t0 = std::chrono::steady_clock::now();
    int count=0;
    while (test2 == 0 && cv.wait_for(lk, ms(250)) == boost::fibers::cv_status::no_timeout)
        count++;
    std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();
    if (runs == 0) {
        BOOST_CHECK(t1 - t0 < ms(250));
        BOOST_CHECK(test2 != 0);
    } else {
        BOOST_CHECK(t1 - t0 - ms(250) < ms(count*250+100+1000));
        BOOST_CHECK(test2 == 0);
    }
    ++runs;
}

void fn5( boost::fibers::mutex & m, boost::fibers::condition_variable & cv) {
    std::unique_lock< boost::fibers::mutex > lk( m);
    BOOST_CHECK(test2 == 0);
    test1 = 1;
    cv.notify_one();
    std::chrono::steady_clock::time_point t0 = std::chrono::steady_clock::now();
    int count=0;
    cv.wait_for(lk, ms(250), Pred(test2));
    count++;
    std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();
    if (runs == 0) {
        BOOST_CHECK(t1 - t0 < ms(250+1000));
        BOOST_CHECK(test2 != 0);
    } else {
        BOOST_CHECK(t1 - t0 - ms(250) < ms(count*250+100));
        BOOST_CHECK(test2 == 0);
    }
    ++runs;
}

void do_test_condition_wait() {
    test1 = 0;
    test2 = 0;
    runs = 0;

    boost::fibers::mutex m;
    boost::fibers::condition_variable cv;
    std::unique_lock< boost::fibers::mutex > lk( m);
    boost::fibers::fiber f( boost::fibers::launch::dispatch, & fn1, std::ref( m), std::ref( cv) );
    BOOST_CHECK(test1 == 0);
    while (test1 == 0)
        cv.wait(lk);
    BOOST_CHECK(test1 != 0);
    test2 = 1;
    lk.unlock();
    cv.notify_one();
    f.join();
}

void test_condition_wait() {
    boost::fibers::fiber( boost::fibers::launch::dispatch, & do_test_condition_wait).join();
    do_test_condition_wait();
}

void do_test_condition_wait_until() {
    test1 = 0;
    test2 = 0;
    runs = 0;

    boost::fibers::mutex m;
    boost::fibers::condition_variable cv;
    {
        std::unique_lock< boost::fibers::mutex > lk( m);
        boost::fibers::fiber f( boost::fibers::launch::dispatch, & fn2, std::ref( m), std::ref( cv) );
        BOOST_CHECK(test1 == 0);
        while (test1 == 0)
            cv.wait(lk);
        BOOST_CHECK(test1 != 0);
        test2 = 1;
        lk.unlock();
        cv.notify_one();
        f.join();
    }
    test1 = 0;
    test2 = 0;
    {
        std::unique_lock< boost::fibers::mutex > lk( m);
        boost::fibers::fiber f( boost::fibers::launch::dispatch, & fn2, std::ref( m), std::ref( cv) );
        BOOST_CHECK(test1 == 0);
        while (test1 == 0)
            cv.wait(lk);
        BOOST_CHECK(test1 != 0);
        lk.unlock();
        f.join();
    }
}

void test_condition_wait_until() {
    boost::fibers::fiber( boost::fibers::launch::dispatch, & do_test_condition_wait_until).join();
    do_test_condition_wait_until();
}

void do_test_condition_wait_until_pred() {
    test1 = 0;
    test2 = 0;
    runs = 0;

    boost::fibers::mutex m;
    boost::fibers::condition_variable cv;
    {
        std::unique_lock< boost::fibers::mutex > lk( m);
        boost::fibers::fiber f( boost::fibers::launch::dispatch, & fn3, std::ref( m), std::ref( cv) );
        BOOST_CHECK(test1 == 0);
        while (test1 == 0)
            cv.wait(lk);
        BOOST_CHECK(test1 != 0);
        test2 = 1;
        lk.unlock();
        cv.notify_one();
        f.join();
    }
    test1 = 0;
    test2 = 0;
    {
        std::unique_lock< boost::fibers::mutex > lk( m);
        boost::fibers::fiber f( boost::fibers::launch::dispatch, & fn3, std::ref( m), std::ref( cv) );
        BOOST_CHECK(test1 == 0);
        while (test1 == 0)
            cv.wait(lk);
        BOOST_CHECK(test1 != 0);
        lk.unlock();
        f.join();
    }
}

void test_condition_wait_until_pred() {
    boost::fibers::fiber( boost::fibers::launch::dispatch, & do_test_condition_wait_until_pred).join();
    do_test_condition_wait_until_pred();
}

void do_test_condition_wait_for() {
    test1 = 0;
    test2 = 0;
    runs = 0;

    boost::fibers::mutex m;
    boost::fibers::condition_variable cv;
    {
        std::unique_lock< boost::fibers::mutex > lk( m);
        boost::fibers::fiber f( boost::fibers::launch::dispatch, & fn4, std::ref( m), std::ref( cv) );
        BOOST_CHECK(test1 == 0);
        while (test1 == 0)
            cv.wait(lk);
        BOOST_CHECK(test1 != 0);
        test2 = 1;
        lk.unlock();
        cv.notify_one();
        f.join();
    }
    test1 = 0;
    test2 = 0;
    {
        std::unique_lock< boost::fibers::mutex > lk( m);
        boost::fibers::fiber f( boost::fibers::launch::dispatch, & fn4, std::ref( m), std::ref( cv) );
        BOOST_CHECK(test1 == 0);
        while (test1 == 0)
            cv.wait(lk);
        BOOST_CHECK(test1 != 0);
        lk.unlock();
        f.join();
    }
}

void test_condition_wait_for() {
    boost::fibers::fiber( boost::fibers::launch::dispatch, & do_test_condition_wait_for).join();
    do_test_condition_wait_for();
}

void do_test_condition_wait_for_pred() {
    test1 = 0;
    test2 = 0;
    runs = 0;

    boost::fibers::mutex m;
    boost::fibers::condition_variable cv;
    {
        std::unique_lock< boost::fibers::mutex > lk( m);
        boost::fibers::fiber f( boost::fibers::launch::dispatch, & fn5, std::ref( m), std::ref( cv) );
        BOOST_CHECK(test1 == 0);
        while (test1 == 0)
            cv.wait(lk);
        BOOST_CHECK(test1 != 0);
        test2 = 1;
        lk.unlock();
        cv.notify_one();
        f.join();
    }
    test1 = 0;
    test2 = 0;
    {
        std::unique_lock< boost::fibers::mutex > lk( m);
        boost::fibers::fiber f( boost::fibers::launch::dispatch, & fn5, std::ref( m), std::ref( cv) );
        BOOST_CHECK(test1 == 0);
        while (test1 == 0)
            cv.wait(lk);
        BOOST_CHECK(test1 != 0);
        lk.unlock();
        f.join();
    }
}

void test_condition_wait_for_pred() {
    boost::fibers::fiber( boost::fibers::launch::dispatch, & do_test_condition_wait_for_pred).join();
    do_test_condition_wait_for_pred();
}

boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
{
    boost::unit_test::test_suite * test =
        BOOST_TEST_SUITE("Boost.Fiber: condition_variable test suite");

    test->add( BOOST_TEST_CASE( & test_one_waiter_notify_one) );
    test->add( BOOST_TEST_CASE( & test_two_waiter_notify_one) );
    test->add( BOOST_TEST_CASE( & test_two_waiter_notify_all) );
    test->add( BOOST_TEST_CASE( & test_condition_wait) );
    test->add( BOOST_TEST_CASE( & test_condition_wait_until) );
    test->add( BOOST_TEST_CASE( & test_condition_wait_until_pred) );
    test->add( BOOST_TEST_CASE( & test_condition_wait_for) );
    test->add( BOOST_TEST_CASE( & test_condition_wait_for_pred) );

	return test;
}


text:
//
// detail/string_view.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2009-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// 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 URDL_DETAIL_STRING_VIEW_HPP
#define URDL_DETAIL_STRING_VIEW_HPP

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)

#include <boost/asio/detail/string_view.hpp>

#include "urdl/detail/abi_prefix.hpp"

#if defined(BOOST_ASIO_HAS_STD_STRING_VIEW)
namespace urdl {
using boost::asio::basic_string_view;
using boost::asio::string_view;
} // namespace urdl
#endif

#define URDL_STRING_VIEW_PARAM BOOST_ASIO_STRING_VIEW_PARAM

#include "urdl/detail/abi_suffix.hpp"

#endif // URDL_DETAIL_SCOPED_PTR_HPP

max_stars_repo_name: gnified/urdl

max_issues_repo_name: gnified/urdl

max_forks_repo_name: gnified/urdl


text:
#include "root_path.hpp"
#include "../../common/content_format.hpp"

#include <pxp-agent/modules/script.hpp>
#include <pxp-agent/configuration.hpp>
#include <pxp-agent/util/process.hpp>

#include <cpp-pcp-client/protocol/chunks.hpp>       // ParsedChunks

#include <leatherman/json_container/json_container.hpp>
#include <leatherman/util/scope_exit.hpp>
#include <leatherman/file_util/file.hpp>

#include <boost/filesystem.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/erase.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>

#include <catch.hpp>

#include <string>
#include <vector>
#include <unistd.h>

using namespace PXPAgent;

namespace fs = boost::filesystem;
namespace pt = boost::posix_time;
namespace lth_jc = leatherman::json_container;
namespace lth_util = leatherman::util;
namespace lth_file = leatherman::file_util;

#ifdef _WIN32
    static const std::string TESTING_SCRIPT = "test_script.ps1";
    static const std::string TESTING_SCRIPT_SHA265 = "3D57FCC5FBDC53E667D16493D38621F36B2CF7DB244986B07A4FBCFECE9E19BD";
#else
    static const std::string TESTING_SCRIPT = "test_script.sh";
    static const std::string TESTING_SCRIPT_SHA265 = "71A2725F36221AAE75AF076D01D18744DA461A02DD2AB746447BC41C71248562";
#endif

static const std::string SPOOL_DIR { std::string { PXP_AGENT_ROOT_PATH }
                                     + "/lib/tests/resources/test_spool" };

static const auto STORAGE = std::make_shared<ResultsStorage>(SPOOL_DIR, "0d");

static const std::string CACHE_DIR { std::string { PXP_AGENT_ROOT_PATH }
                                          + "/lib/tests/resources/scripts_cache" };

// Disable cache ttl so we don't delete fixtures.
static const std::string CACHE_TTL { "0d" };

static const auto MODULE_CACHE_DIR = std::make_shared<ModuleCacheDir>(CACHE_DIR, CACHE_TTL);

static const std::string TEMP_CACHE_DIR { CACHE_DIR + "/temp" };

static const std::vector<std::string> MASTER_URIS { { "https://_master1", "https://_master2", "https://_master3" } };

static const std::string CA { "mock_ca" };

static const std::string CRT { "mock_crt" };

static const std::string KEY { "mock_key" };

static const ActionRequest script_request(const std::string& destination, const std::string& sha, const std::string& args) {
    auto params = boost::format("{\"script\": {"
                                                        "\"uri\":{"
                                                                "\"path\":\"/dl_files/fake-request-file.txt\","
                                                                "\"params\":{"
                                                                    "\"environment\":\"production\""
                                                                "}"
                                                        "},"
                                                        "\"sha256\":\"%1%\","
                                                        "\"filename\":\"%2%\""
                                                    "},"
                                        "\"arguments\":\"%3%\""
                                        "}") % sha % destination % args;
    const PCPClient::ParsedChunks non_blocking_content {
        lth_jc::JsonContainer(ENVELOPE_TXT),           // envelope
        lth_jc::JsonContainer(std::string { (NON_BLOCKING_DATA_FORMAT % "\"1988\""
                                                                        % "\"script\""
                                                                        % "\"run\""
                                                                        % params
                                                                        % "false").str() }),  // data
        {},   // debug
        0 };
    ActionRequest request { RequestType::NonBlocking, non_blocking_content };
    fs::path spool_path { SPOOL_DIR };
    auto results_dir = (spool_path / request.transactionId()).string();
    fs::create_directories(results_dir);
    request.setResultsDir(results_dir);

    return request;
}

TEST_CASE("Modules::Script", "[modules]") {
    SECTION("can successfully instantiate") {
        REQUIRE_NOTHROW(Modules::Script(PXP_AGENT_BIN_PATH, MASTER_URIS, CA, CRT, KEY, "", 10, 20, MODULE_CACHE_DIR, STORAGE));
    }
}

TEST_CASE("Modules::Script::hasAction", "[modules]") {
    Modules::Script mod { PXP_AGENT_BIN_PATH, MASTER_URIS, CA, CRT, KEY, "", 10, 20, MODULE_CACHE_DIR, STORAGE };
    SECTION("correctly reports false") {
        REQUIRE(!mod.hasAction("foo"));
    }

    SECTION("correctly reports true") {
        REQUIRE(mod.hasAction("run"));
    }
}

TEST_CASE("Modules::Script can execute a script", "[modules]") {
    Modules::Script mod { PXP_AGENT_BIN_PATH, MASTER_URIS, CA, CRT, KEY, "", 10, 20, MODULE_CACHE_DIR, STORAGE };
    SECTION("script executes and writes to stdout") {
        auto response = mod.executeAction(script_request(TESTING_SCRIPT, TESTING_SCRIPT_SHA265, ""));
        boost::trim(response.output.std_out);
        REQUIRE(response.output.std_out == "TESTING");
        REQUIRE(response.output.std_err == "");
        REQUIRE(response.output.exitcode == 0);
    }
    SECTION("script executes with multiple parameters") {
        auto response = mod.executeAction(script_request(TESTING_SCRIPT, TESTING_SCRIPT_SHA265, "THREE TEST ARGS"));
        boost::trim(response.output.std_out);
        REQUIRE(response.output.std_out == "| THREE | TEST | ARGS");
        REQUIRE(response.output.std_err == "");
        REQUIRE(response.output.exitcode == 0);
    }
    SECTION("script executes with params with quotes and spaces") {
        auto response = mod.executeAction(script_request(TESTING_SCRIPT, TESTING_SCRIPT_SHA265, "TWO \\\"TEST ARGS\\\""));
        boost::trim(response.output.std_out);
        REQUIRE(response.output.std_out == "| TWO | TEST ARGS");
        REQUIRE(response.output.std_err == "");
        REQUIRE(response.output.exitcode == 0);
    }
#ifdef _WIN32
    SECTION("script executes with a filename that has spaces") {
        auto response = mod.executeAction(script_request("test script.ps1", TESTING_SCRIPT_SHA265, ""));
        boost::trim(response.output.std_out);
        REQUIRE(response.output.std_out == "TESTING");
        REQUIRE(response.output.std_err == "");
        REQUIRE(response.output.exitcode == 0);
    }
#endif
}

TEST_CASE("Modules::Script correctly reports failures", "[modules]") {
    Modules::Script mod { PXP_AGENT_BIN_PATH, MASTER_URIS, CA, CRT, KEY, "", 10, 20, MODULE_CACHE_DIR, STORAGE };
    SECTION("Reports exit code 1 when the script fails") {
        auto response = mod.executeAction(script_request(TESTING_SCRIPT, TESTING_SCRIPT_SHA265, "FAIL"));
        boost::trim(response.output.std_err);
        REQUIRE(response.output.std_out == "");
        REQUIRE(response.output.std_err.find("FAIL TESTING") != std::string::npos);
        REQUIRE(response.output.exitcode == 5);
    }

    // This will produce a failure because the file does not exist yet, so the module
    // will attempt the download from master URIs that aren't real.
    SECTION("Reports invalid results on failed file download") {
        auto response = mod.executeAction(script_request("script_failure.rb", "SCRIPT_FAILING_SHA", "FAIL"));
        REQUIRE_FALSE(response.action_metadata.get<bool>("results_are_valid"));
        REQUIRE(response.action_metadata.includes("execution_error"));
    }
}

// Present in Boost 1.58. That's currently not required, so reproducing it here since it's simple.
static std::time_t my_to_time_t(pt::ptime t)
{
    return (t - pt::ptime(boost::gregorian::date(1970, 1, 1))).total_seconds();
}

TEST_CASE("Modules::Script::purge purges old cached files", "[modules]") {
    const std::string PURGE_CACHE { std::string { PXP_AGENT_ROOT_PATH }
        + "/lib/tests/resources/purge_test" };

    const std::string OLD_TRANSACTION { "valid_old" };
    const std::string RECENT_TRANSACTION { "valid_recent" };

    static const auto PURGE_MODULE_CACHE_DIR = std::make_shared<ModuleCacheDir>(PURGE_CACHE, CACHE_TTL);

    // Start with 0 TTL to prevent initial cleanup
    Modules::Script mod { PXP_AGENT_BIN_PATH, MASTER_URIS, CA, CRT, KEY, "", 10, 20, PURGE_MODULE_CACHE_DIR, STORAGE };

    unsigned int num_purged_results { 0 };
    auto purgeCallback =
        [&num_purged_results](const std::string&) -> void { num_purged_results++; };

    SECTION("Purges only the old results based on ttl") {
        num_purged_results = 0;
        auto now = pt::second_clock::universal_time();
        auto recent = now - pt::minutes(50);
        auto old = now - pt::minutes(61);
        fs::last_write_time(fs::path(PURGE_CACHE)/OLD_TRANSACTION, my_to_time_t(old));
        fs::last_write_time(fs::path(PURGE_CACHE)/RECENT_TRANSACTION, my_to_time_t(recent));

        auto results = mod.purge("1h", {}, purgeCallback);
        REQUIRE(results == 1);
        REQUIRE(num_purged_results == 1);
    }
}

ext: cc

max_stars_repo_name: Dorin-Pleava/pxp-agent

max_issues_repo_name: Dorin-Pleava/pxp-agent

max_forks_repo_name: Dorin-Pleava/pxp-agent


text:
// This file is part of SWGANH which is released under the MIT license.
// See file LICENSE or go to http://swganh.com/LICENSE

#include <boost/test/unit_test.hpp>
#include "swganh/byte_buffer.h"

using namespace swganh;

namespace
{

BOOST_AUTO_TEST_SUITE(ANHByteBuffer)

BOOST_AUTO_TEST_CASE(ByteBufferIsEmptyWhenCreated)
{
    ByteBuffer buffer;
    BOOST_CHECK_EQUAL(uint32_t(0), buffer.size());
}

BOOST_AUTO_TEST_CASE(ByteBufferDefaultCapacityIsZero)
{
    ByteBuffer buffer;
    BOOST_CHECK_EQUAL(uint32_t(0), buffer.capacity());
}

BOOST_AUTO_TEST_CASE(WritingIntReportsCorrectSizeAndCapacity)
{
    ByteBuffer buffer;
    buffer.write<int>(10);

    BOOST_CHECK_EQUAL(uint32_t(4), buffer.size());
    BOOST_CHECK_EQUAL(uint32_t(4), buffer.capacity());
}

BOOST_AUTO_TEST_CASE(WritingTwoIntsReportsCorrectSizeAndCapacity)
{
    ByteBuffer buffer;

    buffer.write<int>(10);
    BOOST_CHECK_EQUAL(uint32_t(4), buffer.size());
    BOOST_CHECK_EQUAL(uint32_t(4), buffer.capacity());

    buffer.write<int>(20);
    BOOST_CHECK_EQUAL(uint32_t(8), buffer.size());
    BOOST_CHECK_EQUAL(uint32_t(8), buffer.capacity());
}

BOOST_AUTO_TEST_CASE(CanReadIntWrittenToTheBuffer)
{
    ByteBuffer buffer;

    buffer.write<int>(10);
    BOOST_CHECK_EQUAL(10, buffer.read<int>());
}

BOOST_AUTO_TEST_CASE(CanReadTwoIntsWrittenToTheBuffer)
{
    ByteBuffer buffer;

    buffer.write<int>(10);
    buffer.write<int>(20);

    BOOST_CHECK_EQUAL(10, buffer.read<int>());
    BOOST_CHECK_EQUAL(20, buffer.read<int>());
}

BOOST_AUTO_TEST_CASE(ReadingPastBufferEndThrowsException)
{
    ByteBuffer buffer;
    BOOST_CHECK_EQUAL(uint32_t(0), buffer.size());

    BOOST_CHECK_THROW(buffer.read<int>(), std::out_of_range);
}

BOOST_AUTO_TEST_CASE(WritingStringReportsCorrectSizeAndCapacity)
{
    ByteBuffer buffer;
    BOOST_CHECK_EQUAL(uint32_t(0), buffer.size());
    BOOST_CHECK_EQUAL(uint32_t(0), buffer.capacity());

    buffer.write<std::string>(std::string("test string"));

    BOOST_CHECK_EQUAL(uint32_t(13), buffer.size());
    BOOST_CHECK_EQUAL(uint32_t(13), buffer.capacity());
}

BOOST_AUTO_TEST_CASE(CanReadStringWrittenToTheBuffer)
{
    ByteBuffer buffer;
    std::string test_string("test string data");

    buffer.write<std::string>(test_string);

    BOOST_CHECK_EQUAL(test_string, buffer.read<std::string>());
}

BOOST_AUTO_TEST_CASE(CanReadTwoStringsWrittenToTheBuffer)
{
    ByteBuffer buffer;
    std::string test_string1("first test string");
    std::string test_string2("second test string");

    buffer.write<std::string>(test_string1);
    buffer.write<std::string>(test_string2);

    BOOST_CHECK_EQUAL(test_string1, buffer.read<std::string>());
    BOOST_CHECK_EQUAL(test_string2, buffer.read<std::string>());
}

BOOST_AUTO_TEST_CASE(WritingUnicodeStringReportsCorrectSizeAndCapacity)
{
    ByteBuffer buffer;
    BOOST_CHECK_EQUAL(uint32_t(0), buffer.size());
    BOOST_CHECK_EQUAL(uint32_t(0), buffer.capacity());

    buffer.write<std::wstring>(std::wstring(L"test string"));

    // Length and Capacity should be size of int + size of string * size of wchar_t.
    BOOST_CHECK_EQUAL(sizeof(uint32_t) + (11 * 2), buffer.size());
    BOOST_CHECK_EQUAL(sizeof(uint32_t) + (11 * 2), buffer.capacity());
}

BOOST_AUTO_TEST_CASE(CanReadUnicodeStringWrittenToTheBuffer)
{
    ByteBuffer buffer;
    std::wstring test_string(L"test string data");

    buffer.write<std::wstring>(test_string);
    BOOST_CHECK_EQUAL(test_string.c_str(), buffer.read<std::wstring>().c_str());
}

BOOST_AUTO_TEST_CASE(UnicodeStringStoredAs16Bit)
{
    ByteBuffer buffer;
    std::wstring test_string(L"testdata");

    BOOST_CHECK_EQUAL(uint32_t(8), test_string.length());

    buffer.write<std::wstring>(test_string);

    BOOST_CHECK_EQUAL(uint32_t(8), buffer.read<uint32_t>());

    BOOST_CHECK_EQUAL('t', buffer.read<uint8_t>());
    BOOST_CHECK_EQUAL(0, buffer.read<uint8_t>());
    BOOST_CHECK_EQUAL('e', buffer.read<uint8_t>());
    BOOST_CHECK_EQUAL(0, buffer.read<uint8_t>());
    BOOST_CHECK_EQUAL('s', buffer.read<uint8_t>());
    BOOST_CHECK_EQUAL(0, buffer.read<uint8_t>());
    BOOST_CHECK_EQUAL('t', buffer.read<uint8_t>());
    BOOST_CHECK_EQUAL(0, buffer.read<uint8_t>());
    BOOST_CHECK_EQUAL('d', buffer.read<uint8_t>());
    BOOST_CHECK_EQUAL(0, buffer.read<uint8_t>());
    BOOST_CHECK_EQUAL('a', buffer.read<uint8_t>());
    BOOST_CHECK_EQUAL(0, buffer.read<uint8_t>());
    BOOST_CHECK_EQUAL('t', buffer.read<uint8_t>());
    BOOST_CHECK_EQUAL(0, buffer.read<uint8_t>());
    BOOST_CHECK_EQUAL('a', buffer.read<uint8_t>());
    BOOST_CHECK_EQUAL(0, buffer.read<uint8_t>());
}

BOOST_AUTO_TEST_CASE(CanClearBufferData)
{
    ByteBuffer buffer;
    BOOST_CHECK_EQUAL(uint32_t(0), buffer.size());

    buffer.write<int>(3);
    BOOST_CHECK_EQUAL(uint32_t(4), buffer.size());

    buffer.clear();
    BOOST_CHECK_EQUAL(uint32_t(0), buffer.size());
    BOOST_CHECK_EQUAL(uint32_t(0), buffer.read_position());
    BOOST_CHECK_EQUAL(uint32_t(0), buffer.write_position());
}

BOOST_AUTO_TEST_CASE(CanStreamData)
{
    ByteBuffer buffer;
    int testInt = 3;

    buffer << testInt;
    BOOST_CHECK_EQUAL(3, buffer.read<int>());
}

BOOST_AUTO_TEST_CASE(PeekingDataDoesNotMoveReadPosition)
{
    ByteBuffer buffer;
    buffer.write<int>(3);
    buffer.write<int>(10);

    // Peek the data twice, this should return the same integer value (3) both times.
    BOOST_CHECK_EQUAL(3, buffer.peek<int>());
    BOOST_CHECK_EQUAL(3, buffer.peek<int>());
}

BOOST_AUTO_TEST_CASE(CanReadAndWriteUnsignedData)
{
    ByteBuffer buffer;
    buffer.write<uint16_t>(3);

    BOOST_CHECK_EQUAL(uint32_t(2), buffer.size()); // First check that the right datasize was written.
    BOOST_CHECK_EQUAL(3, buffer.read<uint16_t>()); // Check that the value is correct.
}

BOOST_AUTO_TEST_CASE(CanPeekAtOffset)
{
    ByteBuffer buffer;
    buffer.write<int>(3);
    buffer.write<int>(32);
    buffer.write<int>(979);
    buffer.write<int>(5467);

    BOOST_CHECK_EQUAL(979, buffer.peekAt<int>(8));
    BOOST_CHECK_EQUAL(32, buffer.peekAt<int>(4));
}

BOOST_AUTO_TEST_CASE(CanWriteAtOffset)
{
    ByteBuffer buffer;
    buffer.write<int>(3);
    buffer.write<int>(32);
    buffer.write<int>(979);
    buffer.write<int>(5467);

    buffer.writeAt<int>(8, 52);
    buffer.writeAt<int>(4, 3532);

    BOOST_CHECK_EQUAL(52, buffer.peekAt<int>(8));
    BOOST_CHECK_EQUAL(3532, buffer.peekAt<int>(4));
}

BOOST_AUTO_TEST_CASE(CanAppendBuffers)
{
    ByteBuffer buffer1;
    buffer1.write<int>(0);
    buffer1.write<int>(1);
    buffer1.write<int>(2);

    ByteBuffer buffer2;
    buffer2.write<int>(3);
    buffer2.write<int>(4);
    buffer2.write<int>(5);

    buffer1.append(buffer2);

    BOOST_CHECK_EQUAL(6 * sizeof(int), buffer1.size());
    BOOST_CHECK_EQUAL(5, buffer1.peekAt<int>(5 * sizeof(int)));
}

BOOST_AUTO_TEST_CASE(CanSwapEndian)
{
    ByteBuffer buffer;

    buffer.write<char>(0);
    buffer.write<char>(0);
    buffer.write<char>(0);
    buffer.write<char>(2);

    BOOST_CHECK_EQUAL(uint32_t(2), buffer.peek<uint32_t>(true));

    // Start a new check with a 64bit value
    buffer.clear();
    buffer.write<char>(0);
    buffer.write<char>(0);
    buffer.write<char>(0);
    buffer.write<char>(0);
    buffer.write<char>(0);
    buffer.write<char>(0);
    buffer.write<char>(0);
    buffer.write<char>(2);

    BOOST_CHECK_EQUAL(uint64_t(2), buffer.peek<uint64_t>(true));
}

BOOST_AUTO_TEST_CASE(CanCompareByteBuffers)
{
    ByteBuffer buffer1;
    buffer1.write<int>(0);
    buffer1.write<int>(1);
    buffer1.write<int>(2);

    ByteBuffer buffer2;
    buffer2.write<int>(3);
    buffer2.write<int>(4);
    buffer2.write<int>(5);

    BOOST_CHECK(buffer1 == buffer1);
    BOOST_CHECK(buffer1 != buffer2);
}
BOOST_AUTO_TEST_CASE(CanWriteVectors)
{
    ByteBuffer buffer;
    std::vector<uint32_t> int_vects;
    int_vects.push_back(12345);
    int_vects.push_back(67890);
    buffer.write(int_vects);
    BOOST_CHECK_EQUAL(2 * sizeof(int), buffer.size());
}
}
BOOST_AUTO_TEST_SUITE_END()

max_stars_repo_name: obi-two/GameServer

max_issues_repo_name: obi-two/GameServer

max_forks_repo_name: obi-two/GameServer


text:
//  Copyright (c) 2007-2014 Hartmut Kaiser
//  Copyright (c) 2011      Bryce Lelbach
//
//  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)

/// \file hpx_fwd.hpp

#if !defined(HPX_HPX_FWD_MAR_24_2008_1119AM)
#define HPX_HPX_FWD_MAR_24_2008_1119AM

#include <hpx/config.hpp>

#if defined(HPX_MSVC)
#  pragma message("The header hpx_fwd.hpp is deprecated")
#else
#  warning "The header hpx_fwd.hpp is deprecated"
#endif

#include <cstdlib>
#include <string>
#include <vector>

#include <boost/config.hpp>
#include <boost/version.hpp>

#if defined(HPX_WINDOWS)
#if !defined(WIN32)
#  define WIN32
#endif
#include <windows.h>
#include <winsock2.h>
#endif

#include <boost/intrusive_ptr.hpp>
#include <boost/system/error_code.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/type_traits/remove_reference.hpp>

#include <hpx/exception_fwd.hpp>
#include <hpx/lcos_fwd.hpp>
#include <hpx/runtime_fwd.hpp>
#include <hpx/util/function.hpp>
// ^ this has to come before the naming/id_type.hpp below
#include <hpx/runtime/agas_fwd.hpp>
#include <hpx/runtime/applier_fwd.hpp>
#include <hpx/runtime/components/component_type.hpp>
#include <hpx/runtime/components_fwd.hpp>
#include <hpx/runtime/find_here.hpp>
#include <hpx/runtime/launch_policy.hpp>
#include <hpx/runtime/naming/id_type.hpp>
#include <hpx/runtime/naming_fwd.hpp>
#include <hpx/runtime/parcelset_fwd.hpp>
#include <hpx/runtime/runtime_mode.hpp>
#include <hpx/runtime/threads/detail/combined_tagged_state.hpp>
#include <hpx/runtime/threads/thread_enums.hpp>
#include <hpx/runtime/threads_fwd.hpp>
#include <hpx/util/unique_function.hpp>
#include <hpx/util/unused.hpp>

#include <hpx/runtime/find_localities.hpp>
#include <hpx/runtime/get_colocation_id.hpp>
#include <hpx/runtime/get_num_localities.hpp>
#include <hpx/runtime/get_thread_name.hpp>
#include <hpx/runtime/shutdown_function.hpp>
#include <hpx/runtime/startup_function.hpp>

/// \namespace hpx
///
/// The namespace \a hpx is the main namespace of the HPX library. All classes
/// functions and variables are defined inside this namespace.
namespace hpx
{
    /// \cond NOINTERNAL

    namespace performance_counters
    {
        struct counter_info;
    }

    /// \endcond
}

// Including declarations of various API function declarations
#include <hpx/runtime/basename_registration.hpp>
#include <hpx/runtime/get_config_entry.hpp>
#include <hpx/runtime/get_locality_id.hpp>
#include <hpx/runtime/get_locality_name.hpp>
#include <hpx/runtime/get_os_thread_count.hpp>
#include <hpx/runtime/get_worker_thread_num.hpp>
#include <hpx/runtime/message_handler_fwd.hpp>
#include <hpx/runtime/set_parcel_write_handler.hpp>
#include <hpx/runtime/trigger_lco.hpp>

#include <hpx/lcos/async_callback_fwd.hpp>
#include <hpx/lcos/async_fwd.hpp>

#endif

max_stars_repo_name: brycelelbach/hpx

max_issues_repo_name: brycelelbach/hpx

max_forks_repo_name: brycelelbach/hpx


text:
#include <string>
#include <vector>

#include <boost/log/trivial.hpp>

#include <graphtyper/constants.hpp>
#include <graphtyper/typer/event.hpp>
#include <graphtyper/utilities/options.hpp>

namespace
{
/*
std::vector<uint8_t>
get_phred_biallelic(uint32_t count, uint32_t anti_count, uint32_t eps)
{
  std::vector<uint8_t> phred(3);

  uint64_t gt00 = count * eps;
  uint64_t gt01 = count + anti_count;
  uint64_t gt11 = anti_count * eps;
  uint64_t const min_gt = std::min({gt00, gt01, gt11});
  gt00 = (gt00 - min_gt) * 3ul;
  gt01 = (gt01 - min_gt) * 3ul;
  gt11 = (gt11 - min_gt) * 3ul;

  uint64_t constexpr MAX = std::numeric_limits<uint8_t>::max();
  phred[0] = std::min(gt00, MAX);
  phred[1] = std::min(gt01, MAX);
  phred[2] = std::min(gt11, MAX);
  return phred;
}
*/

} // anon namespace

namespace gyper
{

long
BaseCount::get_depth_without_deleted() const
{
  return acgt[0] + acgt[1] + acgt[2] + acgt[3];
}

long
BaseCount::get_depth_with_deleted() const
{
  return acgt[0] + acgt[1] + acgt[2] + acgt[3] + deleted;
}

std::string
BaseCount::to_string() const
{
  std::ostringstream ss;

  ss << acgt[0] << "," << acgt[1] << "," << acgt[2] << "," << acgt[3] << ":"
     << acgt_qualsum[0] << "," << acgt_qualsum[1] << "," << acgt_qualsum[2]
     << "," << acgt_qualsum[3] << " " << deleted;

  return ss.str();
}

void
BaseCount::add_base(char seq, char qual)
{
  if (qual == 0)
  {
    ++unknown;
    return;
  }

  long i = base2index(seq);

  if (i < 0)
  {
    if (i == -1)
    {
      ++unknown;
      return;
    }
    else
    {
      assert(i == -2);
      // -2 is deleted base
      ++deleted;
      return;
    }
  }

  assert(i < 4);
  ++(acgt[i]);
  acgt_qualsum[i] += static_cast<int64_t>(qual);
}

uint32_t
get_log_qual(uint32_t count, uint32_t anti_count, uint32_t eps)
{
  uint32_t const gt00 = count * eps;
  uint32_t const gt01 = count + anti_count;
  uint32_t const gt11 = anti_count * eps;
  uint32_t const gt_alt = std::min(gt01, gt11);

  if (gt00 > gt_alt)
    return gt00 - gt_alt;
  else
    return 0u;
}

uint32_t
get_log_qual_double(double count, double anti_count, double eps)
{
  double const gt00 = count * eps;
  double const gt01 = count + anti_count;
  double const gt11 = anti_count * eps;
  double const gt_alt = std::min(gt01, gt11);

  if (gt00 > gt_alt)
    return static_cast<uint32_t>(gt00 - gt_alt + 0.5);
  else
    return 0u;
}

long
base2index(char const base)
{
  switch (base)
  {
  case 'A':
  {
    return 0;
  }

  case 'C':
  {
    return 1;
  }

  case 'G':
  {
    return 2;
  }

  case 'T':
  {
    return 3;
  }

  case 'N':
  {
    return -1;
  }

  case '*':
  {
    return -2;
  }

  default:
  {
    BOOST_LOG_TRIVIAL(error) << __HERE__ << " Unexpected base '" << base << "'";
    std::exit(1);
  }
  }   // switch ends
}

bool
Event::operator==(Event const & b) const
{
  return (pos == b.pos) &&
         (type == b.type) &&
         (sequence == b.sequence);
}

bool
Event::operator!=(Event const & b) const
{
  return !(*this == b);
}

bool
Event::operator<(Event const & b) const
{
  // order is indel, deletions, snp
  auto const order_a = (type == 'D') + 2 * (type == 'X');
  auto const order_b = (b.type == 'D') + 2 * (b.type == 'X');

  return pos < b.pos ||
         (pos == b.pos && order_a < order_b) ||
         (pos == b.pos && order_a == order_b && sequence < b.sequence);
}

void
EventSupport::clear()
{
  hq_count = 0;
  lq_count = 0;
  proper_pairs = 0;
  first_in_pairs = 0;
  sequence_reversed = 0;
  clipped = 0;
  max_mapq = 0;
  max_distance = 0;
  uniq_pos1 = -1;
  uniq_pos2 = -1;
  uniq_pos3 = -1;
  //phase.clear();
  // do not clear indel only things
}

int
EventSupport::get_raw_support() const
{
  return hq_count + lq_count;
}

double
EventSupport::corrected_support() const
{
  return static_cast<double>(hq_count) + static_cast<double>(lq_count) / 2.0;
}

bool
EventSupport::has_good_support(long const cov) const
{
  gyper::Options const & copts = *(Options::const_instance());

  int const raw_support = get_raw_support();
  bool const is_very_promising = uniq_pos3 != -1 &&
                                 hq_count >= 8 &&
                                 (!copts.filter_on_proper_pairs || proper_pairs >= 6) &&
                                 (static_cast<double>(raw_support) / static_cast<double>(cov) > 0.35);
  bool const is_promising = uniq_pos3 != -1 && hq_count >= 7 && (!copts.filter_on_proper_pairs || proper_pairs >= 4);

  return (copts.no_filter_on_begin_pos || uniq_pos2 != -1)
         &&
         (!copts.filter_on_proper_pairs || (proper_pairs >= 2))
         &&
         (hq_count >= 3)
         &&
         (!copts.filter_on_read_bias ||
          is_promising ||
          (first_in_pairs > 0 && first_in_pairs < raw_support))
         &&
         (is_very_promising ||
          !copts.filter_on_strand_bias ||
          (is_promising && sequence_reversed > 0 && sequence_reversed < raw_support) ||
          (sequence_reversed > 1 && sequence_reversed < (raw_support - 1)))
         &&
         (clipped <= 1 || (clipped + 5) <= raw_support)
         &&
         (max_distance >= 10 || (is_promising && hq_count >= 10))
         &&
         (corrected_support() >= 3.9)
         &&
         (cov <= 0 ||
          (static_cast<double>(raw_support) / static_cast<double>(cov) > 0.26) ||
          (is_promising && static_cast<double>(raw_support) / static_cast<double>(cov) > 0.19)
         );
}

std::string
EventSupport::to_string() const
{
  std::ostringstream ss;

  ss << "hq=" << hq_count
     << ",lq=" << lq_count
     << ",pp=" << proper_pairs
     << ",first=" << first_in_pairs
     << ",reversed=" << sequence_reversed
     << ",clipped=" << clipped
     << ",max_mapq=" << static_cast<long>(max_mapq)
     << ",max_distance=" << static_cast<long>(max_distance)
     << ",uniq_pos1=" << uniq_pos1
     << ",uniq_pos2=" << uniq_pos2
     << ",uniq_pos3=" << uniq_pos3
     << ",phase_num=" << phase.size()
     << ",anti_count=" << anti_count
     << ",span=" << span
     << ",max_log_qual=" << max_log_qual
     << ",max_log_qual_file_i=" << max_log_qual_file_i;

  return ss.str();
}

uint32_t
EventSupport::log_qual(uint32_t eps) const
{
  return get_log_qual(hq_count + lq_count, anti_count, eps);
}

bool
EventSupport::is_good_indel(uint32_t eps) const
{
  long const depth = hq_count + lq_count + anti_count + multi_count;

  if (depth == 0 || sequence_reversed <= 0 || sequence_reversed >= depth || proper_pairs <= 4 ||
      (hq_count < 10 && max_mapq <= 10))
  {
    return false;
  }

  assert(sequence_reversed <= depth);
  long const qual = 3 * get_log_qual(hq_count + lq_count, anti_count, eps);

  if (qual < 50)
    return false;

  double const qd = static_cast<double>(qual) / static_cast<double>(depth);
  return qd >= 3.5;
}

bool
apply_indel_event(std::vector<char> & sequence,
                  std::vector<int32_t> & ref_positions,
                  Event const & indel_event,
                  long const offset,
                  bool const is_debug)
{
  assert(sequence.size() == ref_positions.size());
  long const ref_pos{indel_event.pos - offset};

  if (ref_pos <= 0)
    return false;

  long pos{ref_pos}; // Start the search for the reference position here
  long const event_size{static_cast<long>(indel_event.sequence.size())};
  long const seq_size{static_cast<long>(sequence.size())};

  if (pos >= seq_size)
    return false;

  if (ref_positions[pos] != ref_pos)
  {
    while ((pos + 1) < seq_size && ref_positions[pos] < ref_pos)
      ++pos;

    while (pos > 0 && ref_positions[pos] > ref_pos)
      --pos;

    // Check again
    if (ref_positions[pos] != ref_pos)
    {
      if (is_debug)
        BOOST_LOG_TRIVIAL(warning) << __HERE__ << " Couldn't find pos for event " << indel_event.to_string();

      return false;
    }
  }

  // Check purity
  {
    long constexpr PURITY_PAD{3};
    long const begin = std::max(0l, pos - PURITY_PAD);
    long const end = std::min(static_cast<long>(ref_positions.size()), pos + PURITY_PAD);

    assert(begin >= 0);
    assert(begin <= end);
    assert(end <= static_cast<long>(ref_positions.size()));

    long prev_ref_pos = ref_positions[begin];

    for (long p{begin + 1}; p < end; ++p)
    {
      if (ref_positions[p] == prev_ref_pos + 1)
      {
        ++prev_ref_pos;
      }
      else
      {
        if (is_debug)
          BOOST_LOG_TRIVIAL(debug) << __HERE__ << " Not pure " << indel_event.to_string();

        return false; // Not pure, skip indel
      }
    }
  }

  if (indel_event.type == 'D')
  {
    if ((pos + event_size) >= static_cast<long>(ref_positions.size()) ||
        ref_positions[pos + event_size] != (ref_pos + event_size))
    {
      if (is_debug)
        BOOST_LOG_TRIVIAL(debug) << __HERE__ << " Cannot apply deletion";

      return false;
    }

    std::vector<char>::iterator end_it = sequence.end();
    std::vector<int32_t>::iterator end_pos_it = ref_positions.end();

    if ((pos + event_size) < seq_size)
    {
      end_it = sequence.begin() + pos + event_size;
      end_pos_it = ref_positions.begin() + pos + event_size;
    }

    sequence.erase(sequence.begin() + pos, end_it);
    ref_positions.erase(ref_positions.begin() + pos, end_pos_it);
  }
  else if (indel_event.type == 'I')
  {
    sequence.insert(sequence.begin() + pos, indel_event.sequence.begin(), indel_event.sequence.end());

    std::vector<int32_t> new_pos(event_size, pos + 1);
    ref_positions.insert(ref_positions.begin() + pos + 1, new_pos.begin(), new_pos.end());
  }
  else
  {
    BOOST_LOG_TRIVIAL(error) << "Unknown type: " << indel_event.type;
    return false;
  }

  assert(sequence.size() == ref_positions.size());
  return true;
}

Event
make_deletion_event(std::vector<char> const & reference_sequence, long ref_offset, int32_t pos, long count)
{
  Event new_event(pos, 'D');

  assert(ref_offset >= 0);
  assert(ref_offset + count < static_cast<long>(reference_sequence.size()));

  new_event.sequence = std::vector<char>(reference_sequence.begin() + ref_offset,
                                         reference_sequence.begin() + ref_offset + count);

  return new_event;
}

Event
make_insertion_event(int32_t pos, std::vector<char> && event_sequence)
{
  Event new_event(pos, 'I');
  new_event.sequence = std::move(event_sequence);
  return new_event;
}

} // namespace gyper


text:
#include <puppet/runtime/values/value.hpp>
#include <puppet/cast.hpp>
#include <boost/functional/hash.hpp>

using namespace std;

namespace puppet { namespace runtime { namespace types {

    type::type(unique_ptr<values::type const> parameter) :
        _parameter(rvalue_cast(parameter))
    {
    }

    type::type(type const& other) :
        _parameter(other.parameter() ? new values::type(*other.parameter()) : nullptr)
    {
    }

    type& type::operator=(type const& other)
    {
        _parameter.reset(other.parameter() ? new values::type(*other.parameter()) : nullptr);
        return *this;
    }

    unique_ptr<values::type const> const& type::parameter() const
    {
        return _parameter;
    }

    char const* type::name()
    {
        return "Type";
    }

    values::type type::generalize() const
    {
        return types::type{ _parameter ? make_unique<values::type>(_parameter->generalize()) : nullptr };
    }

    bool type::is_instance(values::value const& value, recursion_guard& guard) const
    {
        auto ptr = value.as<values::type>();
        if (!ptr) {
            return false;
        }
        return !_parameter || _parameter->is_assignable(*ptr, guard);
    }

    bool type::is_assignable(values::type const& other, recursion_guard& guard) const
    {
        auto type = boost::get<types::type>(&other);
        if (!type) {
            return false;
        }
        if (!_parameter) {
            // Any type can be assigned to Type
            return true;
        }
        if (!type->_parameter) {
            // Type cannot assign to Type[T]
            return false;
        }
        return _parameter->is_assignable(*type->_parameter, guard);
    }

    void type::write(ostream& stream, bool expand) const
    {
        stream << types::type::name();
        if (!_parameter) {
            return;
        }
        stream << '[';
        _parameter->write(stream, false);
        stream << ']';
    }

    ostream& operator<<(ostream& os, types::type const& type)
    {
        type.write(os);
        return os;
    }

    bool operator==(type const& left, type const& right)
    {
        if (!left.parameter() && !right.parameter()) {
            return true;
        } else if (!left.parameter()) {
            return false;
        } else if (!right.parameter()) {
            return false;
        }
        return *left.parameter() == *right.parameter();
    }

    bool operator!=(type const& left, type const& right)
    {
        return !(left == right);
    }

    size_t hash_value(types::type const& type)
    {
        static const size_t name_hash = boost::hash_value(types::type::name());

        size_t seed = 0;
        boost::hash_combine(seed, name_hash);
        if (type.parameter()) {
            boost::hash_combine(seed, *type.parameter());
        }
        return seed;
    }

}}}  // namespace puppet::runtime::types

max_stars_repo_name: puppetlabs/puppetcpp

max_issues_repo_name: puppetlabs/puppetcpp

max_forks_repo_name: puppetlabs/puppetcpp


text:
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include "CameraMoveController.h"

const float expectedNormalizedAngle = 0.09999;
const float expectedAngle = 35.9964;
const float angleFactor = 360;

BOOST_AUTO_TEST_CASE( TestSubtractTwoFloats ) {
	float value = SubTwoFloats(0.1, 0.00001);
	BOOST_CHECK_EQUAL(value, expectedNormalizedAngle);
	BOOST_CHECK_EQUAL(value*angleFactor, expectedNormalizedAngle*angleFactor);
	BOOST_CHECK_EQUAL(value*angleFactor, 0.09999*angleFactor);
};

BOOST_AUTO_TEST_CASE( TestForStateMachine ) {
	CameraMoveController c;
	BOOST_CHECK_EQUAL(c.GetCurrentState(), EngineState::HomePosition);
	c.StopCamera();
	BOOST_CHECK_EQUAL(c.GetCurrentState(), EngineState::Stopped);
	c.GoToHome();
	BOOST_CHECK_EQUAL(c.GetCurrentState(), EngineState::HomePosition);
};

BOOST_AUTO_TEST_CASE( TestForStateMachineMoveTests ) {
	CameraMoveController c;
	c.MoveCamera();
	BOOST_CHECK_EQUAL(c.GetCurrentPos(), 0.5);
	c.MoveCamera();
	BOOST_CHECK_EQUAL(c.GetCurrentPos(), 0.2);
};


text: #include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>


text:
#ifndef MY_ASYNC_UTIL_CALLBACK_HPP__
#define MY_ASYNC_UTIL_CALLBACK_HPP__

#include <functional>
#include <memory>

#include <boost/system/error_code.hpp>

namespace My_Async{
namespace Util{

template<class Comm, class InContainer>
class Callback{
	public:
		using on_open_t = std::function<void(std::shared_ptr<Comm>)>;
		using on_close_t = std::function<void(std::shared_ptr<Comm>, boost::system::error_code)>;
		using on_message_t = std::function<void(std::shared_ptr<Comm>, InContainer const&)>;
		using on_error_t = std::function<void(std::shared_ptr<Comm>, boost::system::error_code, char const*)>;

		void set_on_open(on_open_t func = nullptr) noexcept
		{
			on_open_f = func;
		}

		void set_on_close(on_close_t func = nullptr) noexcept
		{
			on_close_f = func;
		}

		void set_on_message(on_message_t func = nullptr) noexcept
		{
			on_message_f = func;
		}

		void set_on_error(on_error_t func = nullptr) noexcept
		{
			on_error_f = func;
		}
	protected:
		on_open_t on_open_f;
		on_close_t on_close_f;
		on_message_t on_message_f;
		on_error_t on_error_f;
};
//
//template<class Comm,
//		typename InContainer>
//typename Callback<Comm, InContainer>::on_open_t
//Callback<Comm, InContainer>::on_open_f;
//
//template<class Comm,
//		typename InContainer>
//typename Callback<Comm, InContainer>::on_close_t
//Callback<Comm, InContainer>::on_close_f;
//
//template<class Comm,
//		typename InContainer>
//typename Callback<Comm, InContainer>::on_message_t
//Callback<Comm, InContainer>::on_message_f;
//
//template<class Comm,
//		typename InContainer>
//typename Callback<Comm, InContainer>::on_error_t
//Callback<Comm, InContainer>::on_error_f;

}//Util
}//My_Async

#endif /* MY_ASYNC_UTIL_CALLBACK_HPP__ */


text:
//=======================================================================
// Copyright 2007 Aaron Windsor
//
// 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 __BOYER_MYRVOLD_PLANAR_TEST_HPP__
#define __BOYER_MYRVOLD_PLANAR_TEST_HPP__

#include <boost/graph/planar_detail/boyer_myrvold_impl.hpp>
#include <boost/parameter.hpp>
#include <boost/type_traits.hpp>
#include <boost/mpl/bool.hpp>

namespace boost
{

  struct no_kuratowski_subgraph_isolation {};
  struct no_planar_embedding {};

  namespace boyer_myrvold_params
  {

    BOOST_PARAMETER_KEYWORD(tag, graph)
    BOOST_PARAMETER_KEYWORD(tag, embedding)
    BOOST_PARAMETER_KEYWORD(tag, kuratowski_subgraph)
    BOOST_PARAMETER_KEYWORD(tag, vertex_index_map)
    BOOST_PARAMETER_KEYWORD(tag, edge_index_map)

    typedef parameter::parameters< parameter::required<tag::graph>,
                                   tag::embedding,
                                   tag::kuratowski_subgraph,
                                   tag::vertex_index_map,
                                   tag::edge_index_map
                                   > boyer_myrvold_params_t;

    namespace core
    {

      template <typename ArgumentPack>
      bool dispatched_boyer_myrvold(ArgumentPack const& args,
                                    mpl::true_,
                                    mpl::true_
                                    )
      {
        //Dispatch for no planar embedding, no kuratowski subgraph isolation

        typedef typename remove_const<
            typename parameter::value_type<ArgumentPack, tag::graph>::type
        >::type graph_t;

        typedef typename property_map<
            graph_t,
            vertex_index_t
        >::const_type vertex_default_index_map_t;

        typedef typename parameter::value_type<
            ArgumentPack,
            tag::vertex_index_map,
            vertex_default_index_map_t
        >::type vertex_index_map_t;

        graph_t const& g = args[graph];
        vertex_default_index_map_t v_d_map = get(vertex_index, g);
        vertex_index_map_t v_i_map = args[vertex_index_map | v_d_map];
        boyer_myrvold_impl
          <graph_t,
           vertex_index_map_t,
           graph::detail::no_old_handles,
           graph::detail::no_embedding
          >
          planarity_tester(g, v_i_map);

        return planarity_tester.is_planar() ? true : false;
      }

      template <typename ArgumentPack>
      bool dispatched_boyer_myrvold(ArgumentPack const& args,
                                    mpl::true_,
                                    mpl::false_
                                    )
      {
        //Dispatch for no planar embedding, kuratowski subgraph isolation
        typedef typename remove_const<
            typename parameter::value_type<ArgumentPack, tag::graph>::type
        >::type graph_t;

        typedef typename property_map<
            graph_t,
            vertex_index_t
        >::const_type vertex_default_index_map_t;

        typedef typename parameter::value_type<
            ArgumentPack,
            tag::vertex_index_map,
            vertex_default_index_map_t
        >::type vertex_index_map_t;

        typedef typename property_map<
            graph_t,
            edge_index_t
        >::const_type edge_default_index_map_t;

        typedef typename parameter::value_type<
            ArgumentPack,
            tag::edge_index_map,
            edge_default_index_map_t
        >::type edge_index_map_t;

        graph_t const& g = args[graph];
        vertex_default_index_map_t v_d_map = get(vertex_index, g);
        vertex_index_map_t v_i_map = args[vertex_index_map | v_d_map];
        edge_default_index_map_t e_d_map = get(edge_index, g);
        edge_index_map_t e_i_map = args[edge_index_map | e_d_map];
        boyer_myrvold_impl
          <graph_t,
           vertex_index_map_t,
           graph::detail::store_old_handles,
           graph::detail::no_embedding
          >
          planarity_tester(g, v_i_map);

        if (planarity_tester.is_planar())
          return true;
        else
          {
            planarity_tester.extract_kuratowski_subgraph
              (args[kuratowski_subgraph], e_i_map);
            return false;
          }
      }

      template <typename ArgumentPack>
      bool dispatched_boyer_myrvold(ArgumentPack const& args,
                                    mpl::false_,
                                    mpl::true_
                                    )
      {
        //Dispatch for planar embedding, no kuratowski subgraph isolation
        typedef typename remove_const<
            typename parameter::value_type<ArgumentPack, tag::graph>::type
        >::type graph_t;

        typedef typename property_map<
            graph_t,
            vertex_index_t
        >::const_type vertex_default_index_map_t;

        typedef typename parameter::value_type<
            ArgumentPack,
            tag::vertex_index_map,
            vertex_default_index_map_t
        >::type vertex_index_map_t;

        graph_t const& g = args[graph];
        vertex_default_index_map_t v_d_map = get(vertex_index, g);
        vertex_index_map_t v_i_map = args[vertex_index_map | v_d_map];
        boyer_myrvold_impl
          <graph_t,
           vertex_index_map_t,
           graph::detail::no_old_handles,
#ifdef BOOST_GRAPH_PREFER_STD_LIB
           graph::detail::std_list
#else
           graph::detail::recursive_lazy_list
#endif
          >
          planarity_tester(g, v_i_map);

        if (planarity_tester.is_planar())
          {
            planarity_tester.make_edge_permutation(args[embedding]);
            return true;
          }
        else
          return false;
      }

      template <typename ArgumentPack>
      bool dispatched_boyer_myrvold(ArgumentPack const& args,
                                    mpl::false_,
                                    mpl::false_
                                    )
      {
        //Dispatch for planar embedding, kuratowski subgraph isolation
        typedef typename remove_const<
            typename parameter::value_type<ArgumentPack, tag::graph>::type
        >::type graph_t;

        typedef typename property_map<
            graph_t,
            vertex_index_t
        >::const_type vertex_default_index_map_t;

        typedef typename parameter::value_type<
            ArgumentPack,
            tag::vertex_index_map,
            vertex_default_index_map_t
        >::type vertex_index_map_t;

        typedef typename property_map<
            graph_t,
            edge_index_t
        >::const_type edge_default_index_map_t;

        typedef typename parameter::value_type<
            ArgumentPack,
            tag::edge_index_map,
            edge_default_index_map_t
        >::type edge_index_map_t;

        graph_t const& g = args[graph];
        vertex_default_index_map_t v_d_map = get(vertex_index, g);
        vertex_index_map_t v_i_map = args[vertex_index_map | v_d_map];
        edge_default_index_map_t e_d_map = get(edge_index, g);
        edge_index_map_t e_i_map = args[edge_index_map | e_d_map];
        boyer_myrvold_impl
          <graph_t,
          vertex_index_map_t,
          graph::detail::store_old_handles,
#ifdef BOOST_BGL_PREFER_STD_LIB
           graph::detail::std_list
#else
           graph::detail::recursive_lazy_list
#endif
          >
          planarity_tester(g, v_i_map);

        if (planarity_tester.is_planar())
          {
            planarity_tester.make_edge_permutation(args[embedding]);
            return true;
          }
        else
          {
            planarity_tester.extract_kuratowski_subgraph
              (args[kuratowski_subgraph], e_i_map);
            return false;
          }
      }

      template <typename ArgumentPack>
      bool boyer_myrvold_planarity_test(ArgumentPack const& args)
      {

        typedef typename parameter::binding
          < ArgumentPack,
            tag::kuratowski_subgraph,
            const no_kuratowski_subgraph_isolation&
          >::type
          kuratowski_arg_t;

        typedef typename parameter::binding
          < ArgumentPack,
            tag::embedding,
            const no_planar_embedding&
          >::type
          embedding_arg_t;

         return dispatched_boyer_myrvold
           (args,
            boost::is_same
              <embedding_arg_t, const no_planar_embedding&>(),
            boost::is_same
              <kuratowski_arg_t, const no_kuratowski_subgraph_isolation&>()
            );
      }

    } //namespace core

  } //namespace boyer_myrvold_params

  template <typename A0>
  bool boyer_myrvold_planarity_test(A0 const& arg0)
  {
    return boyer_myrvold_params::core::boyer_myrvold_planarity_test
      (boyer_myrvold_params::boyer_myrvold_params_t()(arg0));
  }

  template <typename A0, typename A1>
  //  bool boyer_myrvold_planarity_test(A0 const& arg0, A1 const& arg1)
  bool boyer_myrvold_planarity_test(A0 const& arg0, A1 const& arg1)
  {
    return boyer_myrvold_params::core::boyer_myrvold_planarity_test
      (boyer_myrvold_params::boyer_myrvold_params_t()(arg0,arg1));
  }

  template <typename A0, typename A1, typename A2>
  bool boyer_myrvold_planarity_test(A0 const& arg0,
                                    A1 const& arg1,
                                    A2 const& arg2
                                    )
  {
    return boyer_myrvold_params::core::boyer_myrvold_planarity_test
      (boyer_myrvold_params::boyer_myrvold_params_t()(arg0,arg1,arg2));
  }

  template <typename A0, typename A1, typename A2, typename A3>
  bool boyer_myrvold_planarity_test(A0 const& arg0,
                                    A1 const& arg1,
                                    A2 const& arg2,
                                    A3 const& arg3
                                    )
  {
    return boyer_myrvold_params::core::boyer_myrvold_planarity_test
      (boyer_myrvold_params::boyer_myrvold_params_t()(arg0,arg1,arg2,arg3));
  }

  template <typename A0, typename A1, typename A2, typename A3, typename A4>
  bool boyer_myrvold_planarity_test(A0 const& arg0,
                                    A1 const& arg1,
                                    A2 const& arg2,
                                    A3 const& arg3,
                                    A4 const& arg4
                                    )
  {
    return boyer_myrvold_params::core::boyer_myrvold_planarity_test
      (boyer_myrvold_params::boyer_myrvold_params_t()
       (arg0,arg1,arg2,arg3,arg4)
       );
  }

}

#endif //__BOYER_MYRVOLD_PLANAR_TEST_HPP__

max_stars_repo_name: cpp-pm/boost

max_issues_repo_name: cpp-pm/boost

max_forks_repo_name: cpp-pm/boost


text:
// Creating arrays from array-expressions
#include "testsuite.h"
#include <blitz/array.h>

BZ_USING_NAMESPACE(blitz)

int main()
{
    Array<float,2> A(4,3,fortranArray);
    Array<float,2> B(4,3,fortranArray);

    A = 2.0;
    B = 1.0;

    Array<float,2> C(A+B);

    BZTEST(C.ordering(0) == A.ordering(0));
    BZTEST(C.ordering(1) == A.ordering(1));

    Array<float,2> D(4,3);

    beginCheckAssert();
    Array<float,2> C3(A+D);   // conflicting storage formats
    endCheckAssert();

    return 0;
}

max_stars_repo_name: fraguela/depspawn

max_issues_repo_name: MSV-Project/IBAMR

max_forks_repo_name: MSV-Project/IBAMR