text:
///
/// Copyright(c) 2018 Aimin Huang
/// Distributed under the MIT License (http://opensource.org/licenses/MIT)
///
#ifndef SHANNON_MESSAGE_HELPER_CONSOLE_CLIENT_INITIALIZER_H
#define SHANNON_MESSAGE_HELPER_CONSOLE_CLIENT_INITIALIZER_H
#include <iostream>
#include <vector>
#include <map>
#include <mutex>
///#include <boost/thread/shared_mutex.hpp>
#include <boost/thread.hpp>
#include <boost/mpl/deref.hpp>
#include <boost/mpl/find.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/lambda.hpp>
#include <boost/mpl/replace_if.hpp>
#include <boost/mpl/empty.hpp>

#include "console_struct.h"
#include "subscribe_client.hpp"

namespace Shannon{
	namespace Message{

		template<typename VecDataStruct>
		class ConsoleClientInitializer{
		private:

			template<typename T>
			struct Galois_WApply{
				template<typename GT>
				struct apply{
					typedef boost::is_same<typename GT::type, T> type;
				};
			};

			struct RemoveValueHelper{
				template<typename T>
				struct apply{
					typedef typename T::type type;
				};
			};

			struct AddConsoleWrapperHelper{

				template<typename T>
				struct apply{
					typedef ConsoleDataStruct<typename T::type> type;
				};

			};

				struct _InstanceBase{
				const std::vector<std::string> listen_keys;
				const Shannon::Message::MessageTypeGroup  message_group;
				Shannon::Message::MessageResumeType resume_type;
				const int index;
				int data_received;
				bool is_init;
				explicit _InstanceBase(const std::vector<std::string> & t_keys,
							  const Shannon::Message::MessageTypeGroup & t_group,
							  Shannon::Message::MessageResumeType t_resume,
							  const int t_index
							  )
							  :listen_keys(t_keys), message_group(t_group),resume_type(t_resume), index(t_index), data_received(0),is_init(false){}

			};

			template<typename DataStruct>
			struct _Instance : public _InstanceBase{
				typedef DataStruct type;
				std::map<std::string, DataStruct> data_storage;
				std::function< void(DataStruct*)> updater;
				explicit _Instance(const std::vector<std::string> & t_keys,
							  const Shannon::Message::MessageTypeGroup & t_group,
							  Shannon::Message::MessageResumeType t_resume,
							  const int t_index		  )
							  :_InstanceBase(t_keys, t_group, t_resume,  t_index){}
			};
		public:
			ConsoleClientInitializer(const std::string & console_address, const std::function< void(int, const std::string &) > logger = &Shannon::Message::UnifiedLoggerForClient);
			~ConsoleClientInitializer();

			inline void SetInitTrue(){ is_init_ = true; }
			bool IsInit();

			template<typename DataStruct>
			std::map<std::string, DataStruct> RtnInitData();

			template<typename DataStruct>
			void Register(const std::vector<std::string> & t_keys, MessageResumeType t_resume = SHANNON_MESSAGE_RESUME_RESTART);

			template<typename DataStruct>
			void RegisterUpdater(const std::function< void(DataStruct*)> & t_updater);

			template<typename DataStruct>
			void OnReceiveData( ConsoleDataStruct<DataStruct>*);

		private:
			typedef typename boost::mpl::transform<VecDataStruct, RemoveValueHelper >::type void_removed_VecDataStruct;
			BOOST_MPL_ASSERT_NOT((boost::mpl::empty<void_removed_VecDataStruct>));

			typedef typename boost::mpl::transform<VecDataStruct, AddConsoleWrapperHelper >::type adjust_client_vec_datastruct;

			typedef typename Shannon::Message::SubscribeClient< adjust_client_vec_datastruct, Shannon::Message::ConsoleSubscribeField >::type ConsoleClientInitializerClient;

			const std::string console_address_;
			std::string client_name_;
			std::shared_ptr< ConsoleClientInitializerClient > initializer_client_;

			bool is_init_;

			std::map<Shannon::Message::MessageType, _InstanceBase* > instances_;
			std::vector< int > instance_type_indexes_;
			std::mutex m_mutex;
		public:
			inline void start(){
				initializer_client_->Listen();
			}
			inline void stop(){
				initializer_client_->stop();
			}
			inline void SendFeedbackMsg(const Shannon::Message::ConsoleFeedbackField & feedback){
				initializer_client_->SendMessage(&feedback, SHANNON_MESSAGE_CONSOLE_FEEDBACK_MSG_TYPE);
			}
			void SetClientName(const std::string & client_name){
				Shannon::Message::ConsoleSubscribeField console_field;
				strncpy(console_field.client_name, client_name.c_str(),sizeof(console_field.client_name)-1);
				client_name_ = client_name;
				initializer_client_->SetTplContent(console_field);
			}
		};

		template<typename VecDataStruct>
		ConsoleClientInitializer<VecDataStruct>::ConsoleClientInitializer(const std::string & console_address , const std::function< void(int, const std::string &) > logger)
			:console_address_(console_address),	initializer_client_( new ConsoleClientInitializerClient(console_address_, logger)),
			is_init_(false){}

		template<typename VecDataStruct>
		ConsoleClientInitializer<VecDataStruct>::~ConsoleClientInitializer(){
			for(auto it = instances_.begin(); it != instances_.end(); ++it ){
				delete it->second;
				it->second = NULL;
			}
		}

		template<typename VecDataStruct>
		bool ConsoleClientInitializer<VecDataStruct>::IsInit(){
			std::lock_guard<std::mutex> write_lock(m_mutex);
			is_init_ = true;
			for(auto it = instances_.begin(); it != instances_.end(); ++it){
				if( ! it->second->is_init ){ is_init_ = false; break; }
			}
			return is_init_;
		}

		template<typename VecDataStruct>
		template<typename DataStruct>
		void ConsoleClientInitializer<VecDataStruct>::Register(const std::vector<std::string> & t_keys, MessageResumeType t_resume)
		{
			typedef typename boost::mpl::find_if<VecDataStruct, Galois_WApply<DataStruct> >::type found_type;
			typedef typename boost::mpl::deref<found_type>::type galois_w_type;
			typedef boost::is_same<typename galois_w_type::type, DataStruct > value_type;
			BOOST_STATIC_ASSERT_MSG( value_type::value, "Invalid/Incompatible DataStruct" );
			BOOST_STATIC_ASSERT_MSG( !boost::is_same<void, DataStruct>::value, "The DataStruct could not be void type" );

			Shannon::Message::MessageTypeGroup  t_group;
			t_group.subscribe = 200 + galois_w_type::value * 10 + 1;
			t_group.unsubscribe = 200 + galois_w_type::value * 10 + 2;
			t_group.update = 200 + galois_w_type::value * 10 + 3;

			initializer_client_->template Register< ConsoleDataStruct<DataStruct> >( t_keys, t_group, t_resume, std::bind(&ConsoleClientInitializer<VecDataStruct>::OnReceiveData<DataStruct>, this, std::placeholders::_1 ) );

			auto it = std::find(instance_type_indexes_.begin(), instance_type_indexes_.end(), found_type::pos::value);
			if( it == instance_type_indexes_.end() && instances_.find( t_group.update ) == instances_.end() ){
				_Instance<DataStruct> * t = new _Instance<DataStruct>(t_keys, t_group, t_resume, found_type::pos::value);
				instances_.insert( std::pair<Shannon::Message::MessageType, _InstanceBase*>(  t_group.update , t ) );
				instance_type_indexes_.push_back( found_type::pos::value );
			}else{
				std::cout<<"===> You have already registered the datastruct: "<<typeid(DataStruct).name()<<" or the message update type: "<<t_group.update<<std::endl;
			}
		}

		template<typename VecDataStruct>
		template<typename DataStruct>
		void ConsoleClientInitializer<VecDataStruct>::RegisterUpdater(const std::function< void(DataStruct*)> & t_updater){

			typedef typename boost::mpl::find_if<VecDataStruct, Galois_WApply<DataStruct> >::type found_type;
			typedef typename boost::mpl::deref<found_type>::type galois_w_type;
			typedef boost::is_same<typename galois_w_type::type, DataStruct> value_type;
			BOOST_STATIC_ASSERT_MSG( value_type::value, "Invalid/Incompatible DataStruct" );
			BOOST_STATIC_ASSERT_MSG( !boost::is_same<void, DataStruct>::value, "The DataStruct could not be void type" );

			std::lock_guard<std::mutex> write_lock(m_mutex);
			auto it = instances_.begin();
			for(;it != instances_.end(); ++it){
				if( found_type::pos::value == it->second->index )
					break;
			}
			if( it != instances_.end() && t_updater ){
				_Instance<DataStruct> * t = static_cast< _Instance<DataStruct>* >( it->second );
				t->updater =  t_updater ;

				////if there is data in data_storage, we need to update them
				for(auto itData = t->data_storage.begin(); itData != t->data_storage.end(); ++itData ){
					t->updater( &(itData->second) );
				}
				t->data_storage.clear();
			}
		}

		template<typename VecDataStruct>
		template<typename DataStruct>
		void ConsoleClientInitializer<VecDataStruct>::OnReceiveData(ConsoleDataStruct<DataStruct>* data){
			typedef typename boost::mpl::find_if<VecDataStruct, Galois_WApply<DataStruct> >::type found_type;
			typedef typename boost::mpl::deref<found_type>::type galois_w_type;
			typedef boost::is_same<typename galois_w_type::type, DataStruct> value_type;
			BOOST_STATIC_ASSERT_MSG( value_type::value, "Invalid/Incompatible DataStruct" );
			BOOST_STATIC_ASSERT_MSG( !boost::is_same<void, DataStruct>::value, "The DataStruct could not be void type" );

			std::lock_guard<std::mutex> write_lock(m_mutex);
			auto it = instances_.begin();
			for(; it != instances_.end(); ++it){
				if( found_type::pos::value == it->second->index )
					break;
			}
			if( it != instances_.end() ){
				_Instance<DataStruct> * t = static_cast< _Instance<DataStruct>* >( it->second );

				if( is_init_ && t->updater){
					t->updater( &(data->data) );
				}else{
					auto itData = t->data_storage.find( data->data.key_id() );
					if( itData == t->data_storage.end() ){
						t->data_storage.insert(  std::pair<std::string, DataStruct>(data->key_id(), data->data )  );
					}else{
						itData->second = data->data;
					}
				}
				t->data_received += 1;
				if( data->is_last ){
					t->is_init = true;

					///// send feedback message
					Shannon::Message::ConsoleFeedbackField feedback;
					strncpy(feedback.id, client_name_.c_str(), sizeof( feedback.id ) - 1 );
					feedback.is_error = false;

					std::string logger_name = (typeid(DataStruct).name() );
					std::string msg("(");	msg.reserve(logger_name.size() + 22);

					std::size_t pos = logger_name.find(' ');
					if( pos == std::string::npos ) pos = 0;
					while( pos < logger_name.size() ){
						char c = logger_name[pos];
						if( ('a' <= c && c<= 'z') || ('A'<=c && c <='Z') ){
							msg.append(1, c);
						}
						++pos;
					}

					msg +=") Data Received: ";
					msg += boost::lexical_cast<std::string>( t->data_received  );
					strncpy(feedback.message, msg.c_str(), sizeof(feedback.message)-1);
					initializer_client_->SendMessage(&feedback, SHANNON_MESSAGE_CONSOLE_FEEDBACK_MSG_TYPE);

					t->data_received = 0;
				}
			}
		}

		template<typename VecDataStruct>
		template<typename DataStruct>
		std::map<std::string, DataStruct> ConsoleClientInitializer<VecDataStruct>::RtnInitData(){

			typedef typename boost::mpl::find_if<VecDataStruct, Galois_WApply<DataStruct> >::type found_type;
			typedef typename boost::mpl::deref<found_type>::type galois_w_type;
			typedef boost::is_same<typename galois_w_type::type, DataStruct> value_type;
			BOOST_STATIC_ASSERT_MSG( value_type::value, "Invalid/Incompatible DataStruct" );
			BOOST_STATIC_ASSERT_MSG( !boost::is_same<void, DataStruct>::value, "The DataStruct could not be void type" );

			std::lock_guard<std::mutex> write_lock(m_mutex);
			auto it = instances_.begin();
			for(; it != instances_.end(); ++it){
				if( found_type::pos::value == it->second->index )
					break;
			}
			std::map<std::string, DataStruct> tmpData;
			if( it != instances_.end() ){
				_Instance<DataStruct> * t = static_cast< _Instance<DataStruct>* >( it->second );
				tmpData = t->data_storage;

				//We want to clear the data_storage for storing new updated data
				t->data_storage.clear();
			}
			return tmpData;
		}

}//namespace Message
}//namespace Shannon
#endif

ext: hpp


text:
// All content Copyright (C) 2018 Genomics plc
#include "alignment/cigar.hpp"
#include "samtools/bam.h"
#include "alignment/cigarItems.hpp"

#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <vector>

using wecall::alignment::Cigar;
using wecall::alignment::CigarItem;
using wecall::alignment::cigarFlags;
using wecall::alignment::CigarItemBuilder;

BOOST_AUTO_TEST_CASE( shouldRollFrom0To6 )
{
    std::vector< std::string > cigarStrings;
    for ( uint32_t cigarInt = 0; cigarInt < 9u; ++cigarInt )
    {
        cigarStrings.emplace_back( CigarItemBuilder::roll( cigarInt )->toString() );
    }
    std::vector< std::string > expectedCigarItems = {"0M", "0I", "0D", "0N", "0S", "0H", "0P", "0=", "0X"};
    BOOST_CHECK_EQUAL_COLLECTIONS( cigarStrings.begin(), cigarStrings.end(), expectedCigarItems.begin(),
                                   expectedCigarItems.end() );
}

BOOST_AUTO_TEST_CASE( shouldRollMatch )
{
    auto cigar = CigarItemBuilder::roll( cigarFlags::MATCH, 2 );
    BOOST_CHECK( dynamic_cast< wecall::alignment::CigarMatch * >( cigar.get() ) != nullptr );
}

BOOST_AUTO_TEST_CASE( shouldRollDeletion )
{
    auto cigar = CigarItemBuilder::roll( cigarFlags::DELETION, 2 );
    BOOST_CHECK( dynamic_cast< wecall::alignment::CigarDeletion * >( cigar.get() ) != nullptr );
}

BOOST_AUTO_TEST_CASE( shouldRollInsertion )
{
    auto cigar = CigarItemBuilder::roll( cigarFlags::INSERTION, 2 );
    BOOST_CHECK( dynamic_cast< wecall::alignment::CigarInsertion * >( cigar.get() ) != nullptr );
}

BOOST_AUTO_TEST_CASE( shouldRollSkip )
{
    auto cigar = CigarItemBuilder::roll( cigarFlags::SKIP, 2 );
    BOOST_CHECK( dynamic_cast< wecall::alignment::CigarSkip * >( cigar.get() ) != nullptr );
}

BOOST_AUTO_TEST_CASE( shouldRollHardClip )
{
    auto cigar = CigarItemBuilder::roll( cigarFlags::HARD_CLIP, 2 );
    BOOST_CHECK( dynamic_cast< wecall::alignment::CigarHardClip * >( cigar.get() ) != nullptr );
}

BOOST_AUTO_TEST_CASE( shouldRollSoftClip )
{
    auto cigar = CigarItemBuilder::roll( cigarFlags::SOFT_CLIP, 2 );
    BOOST_CHECK( dynamic_cast< wecall::alignment::CigarSoftClip * >( cigar.get() ) != nullptr );
}

BOOST_AUTO_TEST_CASE( shouldRollPadding )
{
    auto cigar = CigarItemBuilder::roll( cigarFlags::PADDING, 2 );
    BOOST_CHECK( dynamic_cast< wecall::alignment::CigarPadding * >( cigar.get() ) != nullptr );
}

BOOST_AUTO_TEST_CASE( shouldComputeLengthsOneMatchItem )
{
    Cigar cigar( "4M" );
    BOOST_CHECK_EQUAL( cigar.length(), 4 );
    BOOST_CHECK_EQUAL( cigar.lengthInRef(), 4 );
}

BOOST_AUTO_TEST_CASE( shouldComputeLengthsMultipleItems )
{
    Cigar cigar( "4M7I" );
    BOOST_CHECK_EQUAL( cigar.length(), 11 );
    BOOST_CHECK_EQUAL( cigar.lengthInRef(), 4 );
}

BOOST_AUTO_TEST_CASE( shouldComputeLengthWithoutSoftCippling )
{
    Cigar cigar( "2S4M1S4S7I100S" );
    BOOST_CHECK_EQUAL( cigar.lengthInSeqWithoutSoftClipping(), 11 );
}

BOOST_AUTO_TEST_CASE( shouldGetTheCorrectRelativePositions )
{
    using wecall::alignment::emptyPos;
    Cigar cigar( "2M1I3D1M" );
    auto actualPositions = cigar.getRefPositions( 0 );
    std::vector< int64_t > expectedPositions{0, 1, emptyPos, 5};
    BOOST_CHECK_EQUAL_COLLECTIONS( actualPositions.begin(), actualPositions.end(), expectedPositions.begin(),
                                   expectedPositions.end() );
}

BOOST_AUTO_TEST_CASE( testShouldOutputCorrectCigarString )
{
    std::string cigarString = "2M1I3D4P5H8S9N123567=342342X";
    Cigar cigar( cigarString );
    BOOST_CHECK_EQUAL( cigarString, cigar.toString() );
}

BOOST_AUTO_TEST_CASE( shouldGetEmptyIntervalIfInputIsEmptyAndCigarMatch )
{
    Cigar cigar( "5M" );
    wecall::utils::Interval inputInterval( 1L, 1L );
    wecall::utils::Interval expectedResult( 1L, 1L );
    BOOST_CHECK_EQUAL( expectedResult, cigar.getInverseInterval( inputInterval ) );
}

BOOST_AUTO_TEST_CASE( shouldGetMatchingIntervalIfInputIsNonEmptyAndCigarMatch )
{
    Cigar cigar( "5M" );
    wecall::utils::Interval inputInterval( 1L, 4L );
    wecall::utils::Interval expectedResult( 1L, 4L );
    BOOST_CHECK_EQUAL( expectedResult, cigar.getInverseInterval( inputInterval ) );
}

BOOST_AUTO_TEST_CASE( shouldGetIntervalCorrespondingToInsertion )
{
    Cigar cigar( "1M2I3M" );
    wecall::utils::Interval inputInterval( 1L, 1L );
    wecall::utils::Interval expectedResult( 1L, 3L );
    BOOST_CHECK_EQUAL( expectedResult, cigar.getInverseInterval( inputInterval ) );
}

BOOST_AUTO_TEST_CASE( shouldGetIntervalCorrespondingToDeletion )
{
    Cigar cigar( "1M2D3M" );
    wecall::utils::Interval inputInterval( 1L, 3L );
    wecall::utils::Interval expectedResult( 1L, 1L );
    BOOST_CHECK_EQUAL( expectedResult, cigar.getInverseInterval( inputInterval ) );
}

BOOST_AUTO_TEST_CASE( shouldGetIntervalCorrespondingToMatchAfterInsertion )
{
    Cigar cigar( "1M2I3M" );
    wecall::utils::Interval inputInterval( 2L, 3L );
    wecall::utils::Interval expectedResult( 4L, 5L );
    BOOST_CHECK_EQUAL( expectedResult, cigar.getInverseInterval( inputInterval ) );
}

BOOST_AUTO_TEST_CASE( shouldGetIntervalCorrespondingToMatchAfterDeletion )
{
    Cigar cigar( "1M2D3M" );
    wecall::utils::Interval inputInterval( 4L, 5L );
    wecall::utils::Interval expectedResult( 2L, 3L );
    BOOST_CHECK_EQUAL( expectedResult, cigar.getInverseInterval( inputInterval ) );
}

BOOST_AUTO_TEST_CASE( shouldClipCigarWithOnlySoftClipping )
{
    Cigar cigar( "10S" );

    const auto clippings = cigar.stripSoftClipping();
    BOOST_CHECK_EQUAL( std::distance( cigar.cbegin(), cigar.cend() ), 0 );
    BOOST_CHECK_EQUAL( cigar.lengthInSeq(), 0L );
    BOOST_CHECK_EQUAL( cigar.lengthInRef(), 0L );
    BOOST_CHECK_EQUAL( clippings.first, 10L );
    BOOST_CHECK_EQUAL( clippings.second, 0L );
}

BOOST_AUTO_TEST_CASE( shouldClipEmptyCigar )
{
    Cigar cigar( "" );

    const auto clippings = cigar.stripSoftClipping();
    BOOST_CHECK_EQUAL( std::distance( cigar.cbegin(), cigar.cend() ), 0 );
    BOOST_CHECK_EQUAL( cigar.lengthInSeq(), 0L );
    BOOST_CHECK_EQUAL( cigar.lengthInRef(), 0L );
    BOOST_CHECK_EQUAL( clippings.first, 0L );
    BOOST_CHECK_EQUAL( clippings.second, 0L );
}

BOOST_AUTO_TEST_CASE( shouldClipSoftClippingAtStart )
{
    Cigar cigar( "10S2M" );

    const auto clippings = cigar.stripSoftClipping();
    BOOST_CHECK_EQUAL( std::distance( cigar.cbegin(), cigar.cend() ), 1 );
    BOOST_CHECK_EQUAL( cigar.lengthInSeq(), 2L );
    BOOST_CHECK_EQUAL( cigar.lengthInRef(), 2L );
    BOOST_CHECK_EQUAL( clippings.first, 10L );
    BOOST_CHECK_EQUAL( clippings.second, 0L );
}

BOOST_AUTO_TEST_CASE( shouldClipSoftClippingAtEnd )
{
    Cigar cigar( "2M10S" );

    const auto clippings = cigar.stripSoftClipping();
    BOOST_CHECK_EQUAL( std::distance( cigar.cbegin(), cigar.cend() ), 1 );
    BOOST_CHECK_EQUAL( cigar.lengthInSeq(), 2L );
    BOOST_CHECK_EQUAL( cigar.lengthInRef(), 2L );
    BOOST_CHECK_EQUAL( clippings.first, 0L );
    BOOST_CHECK_EQUAL( clippings.second, 10L );
}

BOOST_AUTO_TEST_CASE( shouldClipSoftClippingAtStartAndEnd )
{
    Cigar cigar( "8S2M10S" );

    const auto clippings = cigar.stripSoftClipping();
    BOOST_CHECK_EQUAL( std::distance( cigar.cbegin(), cigar.cend() ), 1 );
    BOOST_CHECK_EQUAL( cigar.lengthInSeq(), 2L );
    BOOST_CHECK_EQUAL( cigar.lengthInRef(), 2L );
    BOOST_CHECK_EQUAL( clippings.first, 8L );
    BOOST_CHECK_EQUAL( clippings.second, 10L );
}

BOOST_AUTO_TEST_CASE( shouldNotClipInMiddle )
{
    Cigar cigar( "2M10S2M" );

    const auto clippings = cigar.stripSoftClipping();
    BOOST_CHECK_EQUAL( std::distance( cigar.cbegin(), cigar.cend() ), 3 );

    BOOST_CHECK_EQUAL( clippings.first, 0L );
    BOOST_CHECK_EQUAL( clippings.second, 0L );
}

ext: cpp

max_stars_repo_name: dylex/wecall

max_issues_repo_name: dylex/wecall

max_forks_repo_name: dylex/wecall


text:
//          Copyright surrealwaffle 2018 - 2020.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          https://www.boost.org/LICENSE_1_0.txt)

#pragma once

#include <cstddef>
#include <cmath>

#include <algorithm>
#include <functional>
#include <type_traits>
#include <utility>

#include <sentinel/config.hpp>

#include <boost/geometry/core/access.hpp>
#include <boost/geometry/core/coordinate_dimension.hpp>
#include <boost/geometry/core/coordinate_type.hpp>
#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/geometries/register/point.hpp>

namespace sentinel { namespace math {

template<class T, std::size_t N>
struct vector {
    using value_type      = T;
    using size_type       = std::size_t;
    using difference_type = std::ptrdiff_t;
    using reference       = value_type&;
    using const_reference = const value_type&;
    using pointer         = value_type*;
    using const_pointer   = const value_type*;
    using iterator        = pointer;
    using const_iterator  = const_pointer;

    static_assert(N > 0);
    value_type array[N];

    static inline constexpr vector zero = vector(/*ZERO INITIALIZED*/);

    constexpr reference       operator[](size_type pos)       { return array[pos]; }
    constexpr const_reference operator[](size_type pos) const { return array[pos]; }

    constexpr pointer       data() noexcept       { return array; }
    constexpr const_pointer data() const noexcept { return array; }

    static
    constexpr size_type size() noexcept { return N; }

    constexpr iterator begin() noexcept { return array; }
    constexpr iterator end()   noexcept { return begin() + size(); }

    constexpr const_iterator cbegin() const noexcept { return array; }
    constexpr const_iterator cend()   const noexcept { return begin() + size(); }

    constexpr const_iterator begin() const noexcept { return cbegin(); }
    constexpr const_iterator end()   const noexcept { return cend(); }

    constexpr void fill(const T& value) { for (auto& v : *this) v = value; }

    constexpr bool operator==(const vector& other) const {
        return std::mismatch(begin(), end(), other.begin()).first == end();
    }

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

    static constexpr vector filled(const T& value)
    {
        auto return_fill_value = [&value] (auto&&...) -> const T& { return value; };
        return [&return_fill_value] <std::size_t... I> (std::index_sequence<I...>) {
            return vector{return_fill_value(I)...};
        } (std::make_index_sequence<N>{});
    }

    template<class BinaryOp>
    constexpr vector& pointwise_transform(const vector& other, BinaryOp op)
    {
        auto other_it = other.begin();
        for (auto it = begin(), end = this->end(); it != end; ++it, ++other_it)
             *it = op(*it, *other_it);
        return *this;
    }

    constexpr vector& operator+=(const vector& other) { return pointwise_transform(other, std::plus{}); }
    constexpr vector& operator-=(const vector& other) { return pointwise_transform(other, std::minus{}); }
    constexpr vector& operator*=(const vector& other) { return pointwise_transform(other, std::multiplies{}); }
    constexpr vector& operator/=(const vector& other) { return pointwise_transform(other, std::divides{}); }

    constexpr vector& operator*=(const T& scalar) { return (*this) *= filled(scalar); }

    constexpr vector operator+(const vector& other) const { vector result = *this; result += other; return result; }
    constexpr vector operator-(const vector& other) const { vector result = *this; result -= other; return result; }
    constexpr vector operator*(const vector& other) const { vector result = *this; result *= other; return result; }
    constexpr vector operator/(const vector& other) const { vector result = *this; result /= other; return result; }

    constexpr vector operator-() const;
};

template<class T, std::size_t N>
constexpr vector<T, N> vector<T, N>::operator-() const
{
    vector res = *this;
    for (auto& v : res)
        v = -v;
    return res;
}

/** \brief Computes the dot product of two vectors.
 */
template<class T, std::size_t N>
constexpr T dot(const vector<T, N>& a, const vector<T, N>& b)
{
    T result = static_cast<T>(0);
    for (std::size_t pos = 0; pos < N; ++pos)
        result += a[pos] * b[pos];
    return result;
}

/** \brief Computes the cross product of two vector.
 */
template<class T>
constexpr vector<T, 3> cross(const vector<T, 3>& a, const vector<T, 3>& b)
{
    return {
        a[1] * b[2] - a[2] * b[1],
        a[2] * b[0] - a[0] * b[2],
        a[0] * b[1] - a[1] * b[0]
    };
}

/** \brief Computes the square of the norm of a vector.
 */
template<class T, std::size_t N>
constexpr float norm2(const vector<T, N>& vec) { return dot(vec, vec); }

/** \brief Computes the norm of a vector.
 */
template<class T, std::size_t N>
constexpr float norm(const vector<T, N>& vec) { return std::sqrt(norm2(vec)); }

/** \brief Computes a normalized vector.
 *
 * If the norm of \a vec is less than or equal to SENTINEL_VECTOR_SMALL_NORM,
 * the returned vector is the `0` vector.
 */
template<class T, std::size_t N>
constexpr vector<T, N> normalized(const vector<T, N>& vec)
{
    const auto length = norm(vec);
    return length > SENTINEL_VECTOR_SMALL_NORM ? (1 / length) * vec
                                               : vector<T, N>::zero;
}

/** \brief Performs scalar-vector multiplication.
 */
template<class T, std::size_t N>
constexpr vector<T, N> operator*(const T& scalar, const vector<T, N>& vec)
{
    return vector<T, N>::filled(scalar) * vec;
}

/** \brief Performs scalar-vector multiplication.
 */
template<class T, std::size_t N>
constexpr vector<T, N> operator*(const vector<T, N>& vec, const T& scalar)
{
    return vec * vector<T, N>::filled(scalar);
}

template<class T, std::size_t N, class BinaryOp>
constexpr vector<T, N> pointwise_compose(const vector<T, N>& a,
                                         const vector<T, N>& b,
                                         BinaryOp op)
{
    vector<T, N> result = a;
    a.pointwise_accumulate(a, std::cref(op));
    return result;
}

using fvec2 = vector<float, 2>;
using fvec3 = vector<float, 3>;

using dvec2 = vector<double, 2>;
using dvec3 = vector<double, 3>;

} } // namespace sentinel::math

BOOST_GEOMETRY_REGISTER_POINT_2D(sentinel::math::fvec2,
                                 float,
                                 boost::geometry::cs::cartesian,
                                 operator[](0),
                                 operator[](1)
                                 );

BOOST_GEOMETRY_REGISTER_POINT_3D(sentinel::math::fvec3,
                                 float,
                                 boost::geometry::cs::cartesian,
                                 operator[](0),
                                 operator[](1),
                                 operator[](2)
                                 );

BOOST_GEOMETRY_REGISTER_POINT_2D(sentinel::math::dvec2,
                                 double,
                                 boost::geometry::cs::cartesian,
                                 operator[](0),
                                 operator[](1)
                                 );

BOOST_GEOMETRY_REGISTER_POINT_3D(sentinel::math::dvec3,
                                 double,
                                 boost::geometry::cs::cartesian,
                                 operator[](0),
                                 operator[](1),
                                 operator[](2)
                                 );

max_stars_repo_name: surrealwaffle/thesurrealwaffle

max_issues_repo_name: surrealwaffle/thesurrealwaffle

max_forks_repo_name: surrealwaffle/thesurrealwaffle


text:
// Copyright (c) 2016 The Bitcoin XT developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <boost/test/unit_test_suite.hpp>
#include <boost/test/test_tools.hpp>
#include "compactprefiller.h"
#include "test/thinblockutil.h"

BOOST_AUTO_TEST_SUITE(comapactprefiller_tests)

BOOST_AUTO_TEST_CASE(coinbase_only_test) {
    CoinbaseOnlyPrefiller filler;
    CBlock block = TestBlock2();

    std::vector<PrefilledTransaction> prefilled = filler.fillFrom(block);
    BOOST_CHECK_EQUAL(size_t(1), prefilled.size());
    BOOST_CHECK_EQUAL(
            block.vtx.at(0).GetHash().ToString(),
            prefilled.at(0).tx.GetHash().ToString());
}

BOOST_AUTO_TEST_CASE(inventory_known_test) {

    CBlock block = TestBlock1();

    // Transactions that we know that peer knows about.
    uint256 known1 = block.vtx[2].GetHash();
    uint256 known2 = block.vtx[3].GetHash();
    uint256 known3 = block.vtx[5].GetHash();

    std::unique_ptr<CRollingBloomFilter> inventoryKnown(new CRollingBloomFilter(100, 0.000001));

    inventoryKnown->insert(known1);
    inventoryKnown->insert(known2);
    inventoryKnown->insert(known3);

    InventoryKnownPrefiller filler(std::move(inventoryKnown));
    std::vector<PrefilledTransaction> prefilled = filler.fillFrom(block);

    // Should have prefilled all except known1, known2 and known3
    BOOST_CHECK_EQUAL(block.vtx.size() - 3, prefilled.size());

    // inventoryKnown should not be included
    auto findFunc = [&known1, &known2, &known3](const PrefilledTransaction& tx) {
        return tx.tx.GetHash() == known1
            || tx.tx.GetHash() == known2
            || tx.tx.GetHash() == known3;
    };
    auto res = std::find_if(
            begin(prefilled), end(prefilled), findFunc);
    BOOST_CHECK(res == end(prefilled));

    // indexes should be "differentially encoded"
    BOOST_CHECK_EQUAL(prefilled.at(0).index, 0);
    BOOST_CHECK_EQUAL(prefilled.at(1).index, 0);
    BOOST_CHECK_EQUAL(prefilled.at(2).index, 2);
    BOOST_CHECK_EQUAL(prefilled.at(3).index, 1);
}

unsigned int sumTx(std::vector<CTransaction>& txs) {
    unsigned int sum = 0;
    for (auto& t : txs)
        sum += ::GetSerializeSize(t, SER_NETWORK, PROTOCOL_VERSION);
    return sum;
}

unsigned int sumTx(std::vector<PrefilledTransaction>& txs) {
    unsigned int sum = 0;
    for (auto& t : txs)
        sum += ::GetSerializeSize(t.tx, SER_NETWORK, PROTOCOL_VERSION);
    return sum;
}

BOOST_AUTO_TEST_CASE(prefill_dont_exceed_10kb) {
    // From BIP152
    // Nodes sending cmpctblock messages SHOULD limit prefilledtxn to 10KB of transactions

    CBlock block = TestBlock1();

    // Block with ~20KB tx
    while (sumTx(block.vtx) < 20 * 1000 /* 20 KB */) {
        CMutableTransaction newTx(block.vtx.back());
        newTx.vin[0].prevout.hash = GetRandHash();
        block.vtx.push_back(CTransaction(newTx));
    }

    // Filter matches nothing, should prefill as much as possible.
    std::unique_ptr<CRollingBloomFilter> inventoryKnown(new CRollingBloomFilter(100, 0.000001));
    InventoryKnownPrefiller filler(std::move(inventoryKnown));

    std::vector<PrefilledTransaction> prefilled = filler.fillFrom(block);

    BOOST_CHECK(sumTx(prefilled) < 10 * 1000 /* 10KB */);
    BOOST_CHECK(sumTx(prefilled) > 9 * 1000); // Want close to the limit
}

BOOST_AUTO_TEST_CASE(test_choose_prefiller) {

    DummyNode node;
    node.fRelayTxes = false;

    std::unique_ptr<CompactPrefiller> prefiller = choosePrefiller(node);
    BOOST_CHECK(dynamic_cast<CoinbaseOnlyPrefiller*>(prefiller.get()) != nullptr);

    node.fRelayTxes = true;
    prefiller = choosePrefiller(node);
    BOOST_CHECK(dynamic_cast<InventoryKnownPrefiller*>(prefiller.get()) != nullptr);
}

BOOST_AUTO_TEST_SUITE_END()

max_stars_repo_name: WestonReed/bitcoinxt

max_issues_repo_name: WestonReed/bitcoinxt

max_forks_repo_name: WestonReed/bitcoinxt


text:
#ifndef MPI_RPC_HPP
#define MPI_RPC_HPP

#include "config.hpp"

#include <mpi.h>
#include <stdint.h>
#include <vector>
#include <string>

#ifdef USE_THREAD
#include <pthread.h>
#endif

#ifdef USE_YAS
#include <yas/mem_streams.hpp>
#include <yas/binary_iarchive.hpp>
#include <yas/binary_oarchive.hpp>
#endif
#ifdef USE_CEREAL
#include <sstream>
#include <cereal/archives/binary.hpp>
#endif
#ifdef USE_BOOST_SERIALIZATION
#include <sstream>
#include <boost/serialization/serialization.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#endif

#if defined(USE_YAS_FOR_RPC)
namespace frovedis{
typedef yas::mem_istream my_istream;
typedef yas::mem_ostream my_ostream;
typedef yas::binary_iarchive<yas::mem_istream,yas::binary|yas::no_header>
  my_iarchive;
typedef yas::binary_oarchive<yas::mem_ostream,yas::binary|yas::no_header>
  my_oarchive;
}
#define STRING_TO_ISTREAM(is, str) my_istream is(str.c_str(), str.size())
#define OSTREAM_TO_STRING(os, str)                    \
  std::string str;                                    \
  auto os ## _yas_buf = os.get_intrusive_buffer();    \
  str.assign(os ## _yas_buf.data, os ## _yas_buf.size)
#elif defined(USE_CEREAL_FOR_RPC)
namespace frovedis{
typedef std::istringstream my_istream;
typedef std::ostringstream my_ostream;
typedef cereal::BinaryInputArchive my_iarchive;
typedef cereal::BinaryOutputArchive my_oarchive;
}
#define STRING_TO_ISTREAM(is, str) my_istream is(str)
#define OSTREAM_TO_STRING(os, r) auto r = os.str()
#else
namespace frovedis{
typedef std::istringstream my_istream;
typedef std::ostringstream my_ostream;
typedef boost::archive::binary_iarchive my_iarchive;
typedef boost::archive::binary_oarchive my_oarchive;
}
#define STRING_TO_ISTREAM(is, str) my_istream is(str)
#define OSTREAM_TO_STRING(os, r) auto r = os.str()
#endif

namespace frovedis {

typedef int NID;

extern MPI_Comm frovedis_comm_rpc;
extern int frovedis_self_rank;
extern int frovedis_comm_size;

// for shared memory between MPI processes
extern bool frovedis_shm_init;
extern MPI_Comm frovedis_shm_comm;
extern int frovedis_shm_self_rank;
extern int frovedis_shm_comm_size;
extern MPI_Comm frovedis_shmroot_comm;
extern int frovedis_shmroot_self_rank;
extern int frovedis_shmroot_comm_size;

// stacks for split_context_execution
extern std::vector<MPI_Comm> frovedis_comm_rpc_stack;
extern std::vector<int> frovedis_self_rank_stack;
extern std::vector<int> frovedis_comm_size_stack;

extern std::vector<bool> frovedis_shm_init_stack;
extern std::vector<MPI_Comm> frovedis_shm_comm_stack;
extern std::vector<int> frovedis_shm_self_rank_stack;
extern std::vector<int> frovedis_shm_comm_size_stack;
extern std::vector<MPI_Comm> frovedis_shmroot_comm_stack;
extern std::vector<int> frovedis_shmroot_self_rank_stack;
extern std::vector<int> frovedis_shmroot_comm_size_stack;

extern std::string frovedis_tmpdir;

#ifdef USE_THREAD
extern pthread_mutex_t mpi_tag_lock;
#endif
extern int mpi_tag;

// INT_MAX is OK, but make it power of 2
const size_t mpi_max_count = 1 << 30; // 1G

const int system_tag_fence = 1 << 14; // 16384
const int bcast_tag = system_tag_fence + 1;

inline NID get_selfid(){return frovedis_self_rank;}
inline int get_nodesize(){return frovedis_comm_size;}

inline int get_shm_id(){return frovedis_shm_self_rank;}
inline int get_shm_size(){return frovedis_shm_comm_size;}
inline bool is_shm_root(){return frovedis_shm_self_rank == 0 ? true : false;}

enum rpc_type {
  rpc_async_type,
  rpc_oneway_type,
  bcast_rpc_type,
  bcast_rpc_oneway_type,
  finalize_type
};

struct rpc_header {
  rpc_type type;
  int tag;
  intptr_t function_addr;
  intptr_t wrapper_addr;
  size_t count;
};

int get_mpi_tag();
void handle_req();
bool handle_one_bcast_req();
int send_rpcreq(rpc_type, NID, intptr_t, intptr_t, const std::string&);
void send_bcast_rpcreq(rpc_type, intptr_t, intptr_t, const std::string&,
                       std::vector<std::string>&);
void send_bcast_rpcreq_oneway(rpc_type, intptr_t, intptr_t,
                              const std::string&);
}

#endif

max_stars_repo_name: XpressAI/frovedis

max_issues_repo_name: XpressAI/frovedis

max_forks_repo_name: XpressAI/frovedis


text:
#include <NTL/vec_ZZVec.h>

#include <NTL/new.h>

NTL_START_IMPL

NTL_vector_impl(ZZVec,vec_ZZVec)

NTL_END_IMPL

max_stars_repo_name: vshesh/RUNEtag

max_issues_repo_name: vshesh/RUNEtag

max_forks_repo_name: vshesh/RUNEtag


text:
// Copyright (c) 2016 Klemens D. Morgenstern
//
// 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 BOOST_PROCESS_DETAIL_TRAITS_WCHAR_T_HPP_
#define BOOST_PROCESS_DETAIL_TRAITS_WCHAR_T_HPP_

#include <algorithm>

#include <boost/process/detail/traits/decl.hpp>
#include <boost/process/detail/traits/cmd_or_exe.hpp>
#include <boost/process/detail/traits/env.hpp>
#include <boost/process/locale.hpp>

namespace boost { namespace process { namespace detail {

//template

template<typename T> struct is_wchar_t : std::false_type {};

template<> struct is_wchar_t<boost::filesystem::path> : std::is_same<typename boost::filesystem::path::value_type, wchar_t>
{
};

template<> struct is_wchar_t<const wchar_t* > : std::true_type {};

template<> struct is_wchar_t<wchar_t* > : std::true_type {};

template<std::size_t Size> struct is_wchar_t<const wchar_t [Size]>    : std::true_type {};
template<std::size_t Size> struct is_wchar_t<const wchar_t (&)[Size]> : std::true_type {};

template<> struct is_wchar_t<std::wstring>               : std::true_type {};
template<> struct is_wchar_t<std::vector<std::wstring>>  : std::true_type {};
template<> struct is_wchar_t<std::initializer_list<std::wstring>> : std::true_type {};
template<> struct is_wchar_t<std::vector<wchar_t *>>           : std::true_type {};
template<> struct is_wchar_t<std::initializer_list<wchar_t *>> : std::true_type {};

template<typename Char, typename T>
struct char_converter
{
    static T&  conv(T & in)
    {
        return in;
    }
    static T&& conv(T&& in)
    {
        return std::move(in);
    }
    static const T&  conv(const T & in)
    {
        return in;
    }
};

template<typename Char, typename T>
using char_converter_t = char_converter<Char,
        typename std::remove_cv<typename std::remove_reference<T>::type>::type>;

template<>
struct char_converter<char, const wchar_t*>
{
    static std::string conv(const wchar_t* in)
    {
        std::size_t size = 0;
        while (in[size] != L'\0') size++;
        return ::boost::process::detail::convert(in, in + size);
    }
};

template<>
struct char_converter<char, wchar_t*>
{
    static std::string conv(wchar_t* in)
    {
        std::size_t size = 0;
        while (in[size] != L'\0') size++;
        return ::boost::process::detail::convert(in, in + size);
    }
};

template<std::size_t Size>
struct char_converter<char, wchar_t[Size]>
{
    static std::string conv(const wchar_t(&in)[Size])
    {
        return ::boost::process::detail::convert(in, in + Size -1);
    }
};

template<>
struct char_converter<wchar_t, const char*>
{
    static std::wstring conv(const char* in)
    {
        std::size_t size = 0;
        while (in[size] != '\0') size++;
        return ::boost::process::detail::convert(in, in + size);
    }
};

template<>
struct char_converter<wchar_t, char*>
{
    static std::wstring conv(char* in)
    {
        std::size_t size = 0;
        while (in[size] != '\0') size++;
        return ::boost::process::detail::convert(in, in + size);
    }
};

template<std::size_t Size>
struct char_converter<wchar_t, char[Size]>
{
    static std::wstring conv(const char(&in)[Size])
    {
        return ::boost::process::detail::convert(in, in + Size -1);
    }
};

//all the containers.
template<>
struct char_converter<wchar_t, std::string>
{
    static std::wstring conv(const std::string & in)
    {
        return ::boost::process::detail::convert(in);
    }
};

template<>
struct char_converter<char, std::wstring>
{
    static std::string conv(const std::wstring & in)
    {
        return ::boost::process::detail::convert(in);
    }
};

template<>
struct char_converter<wchar_t, std::vector<std::string>>
{
    static std::vector<std::wstring> conv(const std::vector<std::string> & in)
    {
        std::vector<std::wstring> ret(in.size());
        std::transform(in.begin(), in.end(), ret.begin(),
                [](const std::string & st)
                {
                    return convert(st);
                });
        return ret;
    }
};

template<>
struct char_converter<wchar_t, std::initializer_list<std::string>>
{
    static std::vector<std::wstring> conv(const std::initializer_list<std::string> & in)
    {
        std::vector<std::wstring> ret(in.size());
        std::transform(in.begin(), in.end(), ret.begin(),
                [](const std::string & st)
                {
                    return convert(st);
                });
        return ret;
    }
};

template<>
struct char_converter<wchar_t, std::vector<char* >>
{
    static std::vector<std::wstring> conv(const std::vector<char* > & in)
    {
        std::vector<std::wstring> ret(in.size());
        std::transform(in.begin(), in.end(), ret.begin(),
                [](const char* st)
                {
                    std::size_t sz = 0;
                    while (st[sz] != '\0') sz++;
                    return convert(st, st + sz);
                });
        return ret;
    }
};

template<>
struct char_converter<wchar_t, std::initializer_list<char *>>
{
    static std::vector<std::wstring>  conv(const std::initializer_list<char * > & in)
    {
        std::vector<std::wstring> ret(in.size());
        std::transform(in.begin(), in.end(), ret.begin(),
                [](const char* st)
                {
                    std::size_t sz = 0;
                    while (st[sz] != '\0') sz++;
                    return convert(st, st + sz);
                });
        return ret;
    }
};

template<>
struct char_converter<char, std::vector<std::wstring>>
{
    static std::vector<std::string> conv(const std::vector<std::wstring> & in)
    {
        std::vector<std::string> ret(in.size());
        std::transform(in.begin(), in.end(), ret.begin(),
                [](const std::wstring & st)
                {
                    return convert(st);
                });
        return ret;
    }
};

template<>
struct char_converter<char, std::initializer_list<std::wstring>>
{
    static std::vector<std::string> conv(const std::initializer_list<std::wstring> & in)
    {
        std::vector<std::string> ret(in.size());
        std::transform(in.begin(), in.end(), ret.begin(),
                [](const std::wstring & st)
                {
                    return convert(st);
                });
        return ret;
    }
};

template<>
struct char_converter<char, std::vector<wchar_t* >>
{
    static std::vector<std::string> conv(const std::vector<wchar_t* > & in)
    {
        std::vector<std::string> ret(in.size());
        std::transform(in.begin(), in.end(), ret.begin(),
                [](const wchar_t* st)
                {
                    std::size_t sz = 0;
                    while (st[sz] != L'\0') sz++;
                    return convert(st, st + sz);
                });
        return ret;
    }
};

template<>
struct char_converter<char, std::initializer_list<wchar_t * >>
{
    static std::vector<std::string> conv(const std::initializer_list<wchar_t *> & in)
    {
        std::vector<std::string> ret(in.size());
        std::transform(in.begin(), in.end(), ret.begin(),
                [](const wchar_t* st)
                {
                    std::size_t sz = 0;
                    while (st[sz] != L'\0') sz++;
                    return convert(st, st + sz);
                });
        return ret;
    }
};

}}}
#endif /* BOOST_PROCESS_DETAIL_TRAITS_WCHAR_T_HPP_ */


text:
// Copyright Eric Crampton, 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(callback_registry_tests)

BOOST_AUTO_TEST_CASE(test_foo)
{
}

BOOST_AUTO_TEST_SUITE_END()

max_stars_repo_name: respu/meridian

max_issues_repo_name: yggchan/meridian

max_forks_repo_name: yggchan/meridian


text:
/*=============================================================================
  Copyright (c) 2010-2016 Bolero MURAKAMI
  https://github.com/bolero-MURAKAMI/Sprig

  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 SPRIG_GET_POINTER_HPP
#define SPRIG_GET_POINTER_HPP

#include <sprig/config/config.hpp>

#ifdef SPRIG_USING_PRAGMA_ONCE
#	pragma once
#endif	// #ifdef SPRIG_USING_PRAGMA_ONCE

#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/scoped_ptr.hpp>
#include <boost/smart_ptr/intrusive_ptr.hpp>
#include <boost/optional/optional.hpp>

namespace sprig {
	//
	// get_pointer
	//
	template<typename T>
	SPRIG_INLINE T* get_pointer(T* p) {
		return p;
	}
	template<typename T>
	SPRIG_INLINE T const* get_pointer(T const* p) {
		return p;
	}
	template<typename T>
	SPRIG_INLINE typename boost::shared_ptr<T>::pointer
	get_pointer(boost::shared_ptr<T> const& p) {
		return boost::get_pointer(p);
	}
	template<typename T>
	SPRIG_INLINE typename boost::scoped_ptr<T>::element_type*
	get_pointer(boost::scoped_ptr<T> const& p) {
		return boost::get_pointer(p);
	}
	template<typename T>
	SPRIG_INLINE typename boost::intrusive_ptr<T>::element_type*
	get_pointer(boost::intrusive_ptr<T> const& p) {
		return boost::get_pointer(p);
	}
	template<typename T>
	SPRIG_INLINE typename boost::optional<T>::pointer_type
	get_pointer(boost::optional<T>& p) {
		return boost::get_pointer(p);
	}
}	// namespace sprig

#endif	// #ifndef SPRIG_GET_POINTER_HPP

max_stars_repo_name: bolero-MURAKAMI/Sprig

max_issues_repo_name: bolero-MURAKAMI/Sprig

max_forks_repo_name: bolero-MURAKAMI/Sprig