text:
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE http1_parsers

#include <chrono>
#include <boost/test/unit_test.hpp>
#include <http_parser/utils/find.hpp>
#include <http_parser/utils/headers_parser.hpp>
#include <http_parser/utils/http1_head_parsers.hpp>
#include <http_parser/utils/chunked_body_parser.hpp>

using namespace std::literals;
namespace utf = boost::unit_test_framework;

constexpr bool enable_speed_tests =
        #ifdef  ENABLE_SPEED_TESTS
        true
        #else
        false
        #endif
        ;

BOOST_AUTO_TEST_SUITE(utils)
BOOST_AUTO_TEST_SUITE(fast_find)
BOOST_AUTO_TEST_CASE(simple)
{
	std::string data = "abc:abc:";
	auto pos = http_parser::find((std::uint64_t*)data.data(), data.size(), (std::uint8_t)0x3A);
	BOOST_TEST(pos == 3);

	data = "1234567:";
	pos = http_parser::find((std::uint64_t*)data.data(), data.size(), (std::uint8_t)0x3A);
	BOOST_TEST(pos == 7);

	data = "12345678:";
	pos = http_parser::find((std::uint64_t*)data.data(), data.size(), (std::uint8_t)0x3A);
	BOOST_TEST(pos == 8);
}
BOOST_AUTO_TEST_CASE(over)
{
	std::string data = "123456789:";
	auto pos = http_parser::find((std::uint64_t*)data.data(), data.size(), (std::uint8_t)0x3A);
	BOOST_TEST(pos == 9);
}
BOOST_AUTO_TEST_SUITE_END() // fast_find
BOOST_AUTO_TEST_SUITE_END() // utils

BOOST_AUTO_TEST_SUITE(core)
BOOST_AUTO_TEST_SUITE(http1_parsers)
BOOST_AUTO_TEST_SUITE(heads)
BOOST_AUTO_TEST_CASE(sates)
{
	std::string data;
	http_parser::basic_position_string_view view{&data};
	http_parser::http1_request_head_parser prs(view);

	data = "HTTP/1.1 200 OK\r\n"s;
	BOOST_TEST( prs() == http_parser::http1_head_state::http1_resp );
	BOOST_TEST(prs.end_position() == data.size());

	data = "GET /path HTTP/1.1\r"s;
	BOOST_TEST( prs() == http_parser::http1_head_state::wait );
	BOOST_TEST(prs.end_position() == data.size());

	data += "\n";
	BOOST_TEST( prs() == http_parser::http1_head_state::http1_req );
	BOOST_TEST(prs.end_position() == data.size());
}
BOOST_AUTO_TEST_CASE(request_message)
{
	std::string data = "GET /path HTTP/1.1\r\n"s;
	http_parser::basic_position_string_view view{&data};
	http_parser::http1_request_head_parser prs(view);
	prs();
	BOOST_TEST(prs.end_position() == data.size());
	BOOST_TEST(prs.req_msg().method() == "GET"sv);
	BOOST_TEST(prs.req_msg().url().uri() == "/path"sv);
}
BOOST_AUTO_TEST_CASE(response_message)
{
	std::string data = "HTTP/1.1 200 OK OK\r\n"s;
	http_parser::basic_position_string_view view{&data};
	http_parser::http1_request_head_parser prs(view);
	prs();
	BOOST_TEST(prs.end_position() == data.size());
	BOOST_TEST(prs.resp_msg().code == 200);
	BOOST_TEST(prs.resp_msg().reason == "OK OK"sv);
}
BOOST_AUTO_TEST_CASE(max_len)
{
	std::string data = "12345678912345678900"s;
	BOOST_TEST_REQUIRE(data.size() == 20);
	http_parser::basic_position_string_view view{&data};
	http_parser::http1_request_head_parser<std::string, 19> prs(view);
	BOOST_TEST(prs() == http_parser::http1_head_state::garbage);
}
BOOST_AUTO_TEST_CASE(containers)
{
	std::vector<std::byte> data;
	std::string str_data = "HTTP/1.1 200 OK OK\r\nH1:v\r\n"s;
	for(auto& c:str_data) data.emplace_back((std::byte)c);

	http_parser::basic_position_string_view view{&data};
	http_parser::http1_request_head_parser prs(view);
	prs();
	BOOST_TEST(prs.end_position() == data.size()-6);
	BOOST_TEST(prs.resp_msg().code == 200);
	BOOST_TEST(prs.resp_msg().reason == "OK OK"sv);
}
BOOST_AUTO_TEST_SUITE(bugs)
BOOST_AUTO_TEST_CASE(max_size)
{
	std::string data = "GET /path HTTP/1.1\r\n"
	                   "Header-With-Long-Value:longvalue long value long value\r\n"
	                   "Header-With-Long-Value:longvalue long value long value\r\n"
	                   "Header-With-Long-Value:longvalue long value long value\r\n"
	                   "Header-With-Long-Value:longvalue long value long value\r\n"
	                   "Header-With-Long-Value:longvalue long value long value\r\n"
	                   "Header-With-Long-Value:longvalue long value long value\r\n"
	                   "Header-With-Long-Value:longvalue long value long value\r\n"
	                   "Header-With-Long-Value:longvalue long value long value\r\n"
	                   "Header-With-Long-Value:longvalue long value long value\r\n"
	                   "\r\n"s;
	http_parser::basic_position_string_view view{&data};
	http_parser::http1_request_head_parser prs(view);
	BOOST_TEST(prs() == http_parser::http1_head_state::http1_req);
	BOOST_TEST(prs.end_position() == 20);
	BOOST_TEST(prs.req_msg().method() == "GET"sv);
	BOOST_TEST(prs.req_msg().url().uri() == "/path"sv);
}
BOOST_AUTO_TEST_CASE(correct_http)
{
	std::string data = "GET /path http/1.1\rHTTP/1.1\r\n"s;
	http_parser::basic_position_string_view view{&data};
	http_parser::http1_request_head_parser prs(view);
	BOOST_TEST(prs() == http_parser::http1_head_state::garbage);
}
BOOST_AUTO_TEST_SUITE_END() // bugs
BOOST_AUTO_TEST_SUITE_END() // heads
BOOST_AUTO_TEST_SUITE(headers)
BOOST_AUTO_TEST_CASE(common)
{
	std::string data = "Name: value\r\nother:v\r\n\r\n";
	http_parser::basic_position_string_view view(&data);
	http_parser::headers_parser<std::string, std::vector> prs(view);
	BOOST_TEST( prs() == data.size() );
	BOOST_TEST(prs.is_finished() == true);
	auto& res = prs.result();
	BOOST_TEST_REQUIRE(res.headers().size() == 2);
	BOOST_TEST(res.find_header("Name").value() == "value"sv);
	BOOST_TEST(res.find_header("other").value() == "v"sv);
}
BOOST_AUTO_TEST_CASE(by_pieces)
{
	std::string data = "";
	http_parser::basic_position_string_view view(&data);
	http_parser::headers_parser<std::string, std::vector> prs(view);

	BOOST_TEST(prs() == 0);
	BOOST_TEST(prs.is_finished() == false);

	data += "nam";
	BOOST_TEST(prs() == 3);
	BOOST_TEST(prs.is_finished() == false);

	data += "e: v";
	BOOST_TEST(prs() == 7);
	BOOST_TEST(prs.is_finished() == false);

	data += "al\r\n";
	BOOST_TEST(prs() == 12);
	BOOST_TEST(prs.is_finished() == false);

	data += "n2:v\r\n";
	BOOST_TEST(prs() == 18);
	BOOST_TEST(prs.is_finished() == false);

	data += "\r";
	BOOST_TEST(prs() == 18);
	BOOST_TEST(prs.is_finished() == false);

	data += "\n";
	BOOST_TEST(prs() == data.size());
	BOOST_TEST(prs.is_finished() == true);

	auto old = data.size();
	data += "body";
	http_parser::basic_position_string_view data_view(&data, old, 4);
	BOOST_TEST( data_view == "body"sv );

	auto& res = prs.result();
	BOOST_TEST_REQUIRE(res.headers().size() == 2);
	BOOST_TEST(res.find_header("name").value() == "val"sv);
	BOOST_TEST(res.find_header("n2").value() == "v"sv);
}
BOOST_AUTO_TEST_CASE(single)
{
	std::string data = "name:value\r\n\r\n";
	http_parser::basic_position_string_view view(&data);
	http_parser::headers_parser<std::string, std::vector> prs(view);
	BOOST_TEST(prs() == data.size());
	BOOST_TEST(prs.is_finished() == true);
	auto& res = prs.result();
	BOOST_TEST_REQUIRE(res.headers().size() == 1);
	BOOST_TEST(res.find_header("name").value() == "value"sv);
}
BOOST_AUTO_TEST_CASE(skip_first_bytes)
{
	std::string data = "garbagename:value\r\n\r\n";
	http_parser::basic_position_string_view view(&data);
	http_parser::headers_parser<std::string, std::vector> prs(view);
	prs.skip_first_bytes(7);
	BOOST_TEST(prs() == data.size());
	BOOST_TEST(prs.is_finished() == true);
	auto& res = prs.result();
	BOOST_TEST_REQUIRE(res.headers().size() == 1);
	BOOST_TEST(res.headers()[0].name == "name"sv);
}
BOOST_AUTO_TEST_CASE(skip_first_bytes_steps)
{
	std::string data = "garba"s;
	http_parser::basic_position_string_view view(&data);
	http_parser::headers_parser<std::string, std::vector> prs(view);
	prs.skip_first_bytes(7);
	prs();
	BOOST_TEST(prs.is_finished() == false);
	data += "gename:value\r\n\r\n"s;
	BOOST_TEST(prs() == data.size());
	BOOST_TEST(prs.is_finished() == true);
	auto& res = prs.result();
	BOOST_TEST_REQUIRE(res.headers().size() == 1);
	BOOST_TEST(res.headers()[0].name == "name"sv);
}
BOOST_AUTO_TEST_CASE(speed, * utf::enable_if<enable_speed_tests>())
{
	std::string data = "name:value\r\nname: value\r\n\r\n";
	http_parser::basic_position_string_view view(&data);
	auto start = std::chrono::high_resolution_clock::now();
	for(std::size_t i=0;i<10'000'000;++i) {
		http_parser::headers_parser<std::string, std::vector> prs(view);
		prs();
	}
	auto end = std::chrono::high_resolution_clock::now();
	BOOST_TEST(std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count() < 2'000);
}
BOOST_AUTO_TEST_SUITE_END() // headers
BOOST_AUTO_TEST_SUITE(chunked_body)
BOOST_AUTO_TEST_CASE(simple)
{
	std::string data = "2\r\noka\r\n12345678901\r\na";
	http_parser::basic_position_string_view view(&data);
	http_parser::chunked_body_parser prs(view);
	BOOST_TEST(prs.finish() == false);
	BOOST_TEST(prs.ready() == false);
	for(std::size_t i=1;i<4;++i) {
		BOOST_TEST_CONTEXT("i == " << i) {
			BOOST_TEST(prs() == true);
			BOOST_TEST(prs.finish() == false);
			BOOST_TEST(prs.ready() == true);
			if(i == 1) BOOST_TEST(prs.result() == "ok"sv);
			if(i == 2) BOOST_TEST(prs.result() == "1234567890"sv);
			if(i == 3) BOOST_TEST(prs.result() == "a"sv);
		}
	}

	BOOST_TEST(prs() == false);
	BOOST_TEST(prs.ready() == false);
	BOOST_TEST(prs.finish() == false);

	data += "0\r\n";
	BOOST_TEST(prs() == true);
	BOOST_TEST(prs.result() == ""sv);
	BOOST_TEST(prs.finish() == true);
	BOOST_TEST(prs.ready() == true);

	BOOST_TEST(prs() == false);
	BOOST_TEST(prs.finish() == true);
	BOOST_TEST(prs.ready() == true);
}
BOOST_AUTO_TEST_CASE(by_peaces)
{
	std::string data = "1\r\na2";
	http_parser::basic_position_string_view view(&data);
	http_parser::chunked_body_parser prs(view);
	prs();
	BOOST_TEST(prs.ready() == true);
	BOOST_TEST(prs.finish() == false);
	BOOST_TEST(prs.result() == "a"sv);
	BOOST_TEST(prs.end_pos() == 4);

	prs();
	BOOST_TEST(prs.ready() == false);
	BOOST_TEST(prs.end_pos() == 4);

	data += "\r"sv;
	prs();
	BOOST_TEST(prs.ready() == false);
	BOOST_TEST(prs.end_pos() == 4);

	data += "\n"sv;
	prs();
	BOOST_TEST(prs.ready() == false);
	BOOST_TEST(prs.end_pos() == 4);

	data += "o"sv;
	prs();
	BOOST_TEST(prs.ready() == false);
	BOOST_TEST(prs.end_pos() == 4);

	data += "k"sv;
	prs();
	BOOST_TEST(prs.ready() == true);
	BOOST_TEST(prs.result() == "ok"sv);
	BOOST_TEST(prs.end_pos() == 9);

	data += "0"sv;
	prs();
	BOOST_TEST(prs.ready() == false);
	BOOST_TEST(prs.end_pos() == 9);

	data += "\r"sv;
	prs();
	BOOST_TEST(prs.ready() == false);
	BOOST_TEST(prs.finish() == false);
	BOOST_TEST(prs.end_pos() == 9);

	data += "\n"sv;
	prs();
	BOOST_TEST(prs.ready() == true);
	BOOST_TEST(prs.finish() == true);
	BOOST_TEST(prs.result() == ""sv);
	BOOST_TEST(prs.end_pos() == 12);

}
BOOST_AUTO_TEST_CASE(greater_16_body)
{
	std::string data = "14\r\n12345678901234567890";
	http_parser::basic_position_string_view view(&data);
	http_parser::chunked_body_parser prs(view);
	prs();
	BOOST_TEST(prs.ready() == true);
	BOOST_TEST(prs.finish() == false);
	BOOST_TEST(prs.result() == "12345678901234567890"sv);
	BOOST_TEST(prs.end_pos() == 24);
}
BOOST_AUTO_TEST_CASE(wrong)
{
	std::string data = "\r\na";
	http_parser::basic_position_string_view view(&data);
	http_parser::chunked_body_parser prs(view);
	prs();
	BOOST_TEST(prs.ready() == true);
	BOOST_TEST(prs.finish() == true);
	BOOST_TEST(prs.error() == true);
	BOOST_TEST(prs.result() == ""sv);
}
BOOST_AUTO_TEST_CASE(with_trash)
{
	std::string data = "2\r\noktrash14\r\n12345678901234567890";
	http_parser::basic_position_string_view view(&data);
	http_parser::chunked_body_parser prs(view);
	prs();
	BOOST_TEST(prs.ready() == true);
	BOOST_TEST(prs.finish() == false);
	BOOST_TEST(prs.result() == "ok"sv);
	BOOST_TEST(prs.end_pos() == 5);

	prs();
	BOOST_TEST(prs.ready() == true);
	BOOST_TEST(prs.finish() == false);
	BOOST_TEST(prs.result() == "12345678901234567890"sv);
}
BOOST_AUTO_TEST_SUITE_END() // chunked_body
BOOST_AUTO_TEST_SUITE_END() // http1_parsers
BOOST_AUTO_TEST_SUITE_END() // core


text:
/**
 * @file   GLTexture2D.cpp
 * @author Sebastian Maisch <sebastian.maisch@googlemail.com>
 * @date   2013.12.31
 *
 * @brief  Contains the implementation of GLTexture2D.
 */

#include "GLTexture2D.h"
#include "GLTexture.h"
#include <GL/gl.h>
#include <stb_image.h>
#include <boost/filesystem.hpp>
#include "app/ApplicationBase.h"
#include "app/Configuration.h"

namespace cgu {

    /**
     * Constructor.
     * @param texFilename the textures file name
     */
    GLTexture2D::GLTexture2D(const std::string& texFilename, ApplicationBase* app) :
        Resource{ texFilename, app },
        texture_()
    {
        auto filename = FindResourceLocation(GetParameters()[0]);
        if (!boost::filesystem::exists(filename)) {
            LOG(ERROR) << "File \"" << filename.c_str() << L"\" cannot be opened.";
            throw resource_loading_error() << ::boost::errinfo_file_name(filename) << resid_info(getId())
                << errdesc_info("Cannot open texture file.");
        }

        stbi_set_flip_vertically_on_load(1);

        if (stbi_is_hdr(filename.c_str()) != 0) LoadTextureHDR(filename);
        else LoadTextureLDR(filename);

        if (CheckNamedParameterFlag("mirror")) texture_->SampleWrapMirror();
        if (CheckNamedParameterFlag("repeat")) texture_->SampleWrapRepeat();
        if (CheckNamedParameterFlag("clamp")) texture_->SampleWrapClamp();
        if (CheckNamedParameterFlag("mirror-clamp")) texture_->SampleWrapMirrorClamp();
    }

    /** Copy constructor. */
    GLTexture2D::GLTexture2D(const GLTexture2D& rhs) : GLTexture2D(rhs.getId(), rhs.application)
    {
    }

    /** Copy assignment operator. */
    GLTexture2D& GLTexture2D::operator=(const GLTexture2D& rhs)
    {
        auto tmp(rhs);
        std::swap(texture_, tmp.texture_);
        return *this;
    }

    /** Default move constructor. */
    GLTexture2D::GLTexture2D(GLTexture2D&& rhs) : Resource(std::move(rhs)), texture_(std::move(rhs.texture_)) {}

    /** Default move assignment operator. */
    GLTexture2D& GLTexture2D::operator=(GLTexture2D&& rhs)
    {
        if (this != &rhs) {
            this->~GLTexture2D();
            Resource* tRes = this;
            *tRes = static_cast<Resource&&>(std::move(rhs));
            texture_ = std::move(rhs.texture_);
        }
        return *this;
    }

    /** Destructor. */
    GLTexture2D::~GLTexture2D() = default;

    /** Returns the texture object. */
    GLTexture* GLTexture2D::GetTexture()
    {
        return texture_.get();
    }

    /** Returns the texture object. */
    const GLTexture* GLTexture2D::GetTexture() const
    {
        return texture_.get();
    }

    void GLTexture2D::LoadTextureLDR(const std::string& filename)
    {
        auto imgWidth = 0, imgHeight = 0, imgChannels = 0;
        auto image = stbi_load(filename.c_str(), &imgWidth, &imgHeight, &imgChannels, 0);
        if (!image) {
            LOG(ERROR) << L"Could not load texture \"" << filename.c_str() << L"\".";
            throw resource_loading_error() << ::boost::errinfo_file_name(filename) << resid_info(getId())
                << errdesc_info("Cannot load texture data.");
        }

        auto internalFmt = GL_RGBA8;
        auto fmt = GL_RGBA;
        std::tie(internalFmt, fmt) = FindFormat(filename, imgChannels);

        TextureDescriptor texDesc(4, internalFmt, fmt, GL_UNSIGNED_BYTE);
        texture_ = std::make_unique<GLTexture>(imgWidth, imgHeight, texDesc, image);

        stbi_image_free(image);
    }

    void GLTexture2D::LoadTextureHDR(const std::string& filename)
    {
        auto imgWidth = 0, imgHeight = 0, imgChannels = 0;
        auto image = stbi_loadf(filename.c_str(), &imgWidth, &imgHeight, &imgChannels, 0);
        if (!image) {
            LOG(ERROR) << L"Could not load texture \"" << filename.c_str() << L"\".";
            throw resource_loading_error() << ::boost::errinfo_file_name(filename) << resid_info(getId())
                << errdesc_info("Cannot load texture data.");
        }

        auto internalFmt = GL_RGBA8;
        auto fmt = GL_RGBA;
        std::tie(internalFmt, fmt) = FindFormat(filename, imgChannels);

        TextureDescriptor texDesc(4, internalFmt, fmt, GL_FLOAT);
        texture_ = std::make_unique<GLTexture>(imgWidth, imgHeight, texDesc, image);

        stbi_image_free(image);
    }

    std::tuple<int, int> GLTexture2D::FindFormat(const std::string& filename, int imgChannels) const
    {
        auto useSRGB = (CheckNamedParameterFlag("sRGB") && application->GetConfig().useSRGB);
        auto internalFmt = GL_RGBA8;
        auto fmt = GL_RGBA;
        switch (imgChannels) {
        case 1: internalFmt = GL_R8; fmt = GL_RED; break;
        case 2: internalFmt = GL_RG8; fmt = GL_RG; break;
        case 3: internalFmt = useSRGB ? GL_SRGB8 : GL_RGB8; fmt = GL_RGB; break;
        case 4: internalFmt = useSRGB ? GL_SRGB8_ALPHA8 : GL_RGBA8; fmt = GL_RGBA; break;
        default:
            LOG(ERROR) << L"Invalid number of texture channels (" << imgChannels << ").";
            throw resource_loading_error() << ::boost::errinfo_file_name(filename) << resid_info(getId())
                << errdesc_info("Invalid number of texture channels.");
        }
        return std::make_tuple(internalFmt, fmt);
    }
}

ext: cpp


text:
//  Copyright John Maddock 2015.
//  Use, modification and distribution are 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)

#ifndef BOOST_MATH_BINDINGS
#define BOOST_MATH_BINDINGS

#define ERROR_REPORTING_MODE

#if TEST_LIBSTDCXX

#include <tr1/cmath>
#include <stdexcept>

#define TEST_LIBRARY_NAME "<tr1/cmath>"

#define LOG1P_FUNCTION_TO_TEST std::tr1::log1p
#define EXPM1_FUNCTION_TO_TEST std::tr1::log1p

#define CBRT_FUNCTION_TO_TEST std::tr1::cbrt
#define ERF_FUNCTION_TO_TEST std::tr1::erf
#define ERFC_FUNCTION_TO_TEST std::tr1::erfc

#define LGAMMA_FUNCTION_TO_TEST std::tr1::lgamma
#define TGAMMA_FUNCTION_TO_TEST std::tr1::tgamma

#define BESSEL_I_FUNCTION_TO_TEST std::tr1::cyl_bessel_i
#define BESSEL_IN_FUNCTION_TO_TEST std::tr1::cyl_bessel_i
#define BESSEL_J_FUNCTION_TO_TEST std::tr1::cyl_bessel_j
#define BESSEL_JN_FUNCTION_TO_TEST std::tr1::cyl_bessel_j
#define BESSEL_JS_FUNCTION_TO_TEST std::tr1::sph_bessel
#define BESSEL_K_FUNCTION_TO_TEST std::tr1::cyl_bessel_k
#define BESSEL_KN_FUNCTION_TO_TEST std::tr1::cyl_bessel_k
#define BESSEL_Y_FUNCTION_TO_TEST std::tr1::cyl_neumann
#define BESSEL_YN_FUNCTION_TO_TEST std::tr1::cyl_neumann
#define BESSEL_YS_FUNCTION_TO_TEST std::tr1::sph_neumann

#define BETA_FUNCTION_TO_TEST std::tr1::beta

#define ELLINT_1_FUNCTION_TO_TEST std::tr1::ellint_1
#define ELLINT_1C_FUNCTION_TO_TEST std::tr1::comp_ellint_1
#define ELLINT_2_FUNCTION_TO_TEST std::tr1::ellint_2
#define ELLINT_2C_FUNCTION_TO_TEST std::tr1::comp_ellint_2
#define ELLINT_3_FUNCTION_TO_TEST std::tr1::ellint_3
#define ELLINT_3C_FUNCTION_TO_TEST std::tr1::comp_ellint_3

#define EI_FUNCTION_TO_TEST std::tr1::expint

#define LAGUERRE_FUNCTION_TO_TEST std::tr1::laguerre
#define ASSOC_LAGUERRE_FUNCTION_TO_TEST std::tr1::assoc_laguerre

inline long double legendre_p_binder(int i, long double d)
{
   if(i < 0)
      throw std::domain_error("order parameters less than 0 not supported in TR1");
   return std::tr1::legendre(i, d);
}
inline long double assoc_legendre_p_binder(int i, int j, long double d)
{
   if((i < 0) || (j < 0))
      throw std::domain_error("order parameters less than 0 not supported in TR1");
   return std::tr1::assoc_legendre(i, j, d);
}

#define LEGENDRE_P_FUNCTION_TO_TEST legendre_p_binder
#define LEGENDRE_PA_FUNCTION_TO_TEST assoc_legendre_p_binder
#define ZETA_FUNCTION_TO_TEST std::tr1::riemann_zeta

#define TYPE_TO_TEST long double

#elif defined(TEST_C99)

#include <math.h>

#define TEST_LIBRARY_NAME "<math.h>"

#ifdef _MSC_VER

#define LOG1P_FUNCTION_TO_TEST ::log1p
#define EXPM1_FUNCTION_TO_TEST ::expm1

#define CBRT_FUNCTION_TO_TEST ::cbrt
#define ERF_FUNCTION_TO_TEST ::erf
#define ERFC_FUNCTION_TO_TEST ::erfc

#define LGAMMA_FUNCTION_TO_TEST ::lgamma
#define TGAMMA_FUNCTION_TO_TEST ::tgamma
#define BESSEL_JN_FUNCTION_TO_TEST ::jn
#define BESSEL_YN_FUNCTION_TO_TEST ::yn

#define TYPE_TO_TEST double

#else

#define LOG1P_FUNCTION_TO_TEST ::log1pl
#define EXPM1_FUNCTION_TO_TEST ::expm1l

#define CBRT_FUNCTION_TO_TEST ::cbrtl
#define ERF_FUNCTION_TO_TEST ::erfl
#define ERFC_FUNCTION_TO_TEST ::erfcl

#define LGAMMA_FUNCTION_TO_TEST ::lgammal
#define TGAMMA_FUNCTION_TO_TEST ::tgammal
//#define BESSEL_JN_FUNCTION_TO_TEST ::jnl
//#define BESSEL_JN_FUNCTION_TO_TEST ::ynl

#define TYPE_TO_TEST long double
#endif

#elif defined(TEST_GSL)

#include <stdexcept>

#include <gsl/gsl_sf.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_version.h>

#define TEST_LIBRARY_NAME "GSL " GSL_VERSION

void gsl_handler(const char * reason, const char * file, int line, int gsl_errno)
{
   if(gsl_errno == GSL_ERANGE) return; // handle zero or infinity in our test code.
   throw std::domain_error(reason);
}

struct gsl_error_handler_setter
{
   gsl_error_handler_t * old_handler;
   gsl_error_handler_setter()
   {
      old_handler = gsl_set_error_handler(gsl_handler);
   }
   ~gsl_error_handler_setter()
   {
      gsl_set_error_handler(old_handler);
   }
};

static const gsl_error_handler_setter handler;

inline double gsl_bessel_ys(unsigned i, double d)
{
   return gsl_sf_bessel_yl(i, d);
}

inline double gsl_bessel_js(unsigned i, double d)
{
   return gsl_sf_bessel_jl(i, d);
}

//#define CBRT_FUNCTION_TO_TEST boost::cbrt
#define ERF_FUNCTION_TO_TEST gsl_sf_erf
#define ERFC_FUNCTION_TO_TEST gsl_sf_erfc
//#define ERF_INV_FUNCTION_TO_TEST boost::math::erf_inv
//#define ERFC_INV_FUNCTION_TO_TEST boost::math::erfc_inv

#define LGAMMA_FUNCTION_TO_TEST gsl_sf_lngamma
#define TGAMMA_FUNCTION_TO_TEST gsl_sf_gamma
//#define TGAMMA1PM1_FUNCTION_TO_TEST boost::math::tgamma1pm1

#define BESSEL_I_FUNCTION_TO_TEST gsl_sf_bessel_Inu
#define BESSEL_IN_FUNCTION_TO_TEST gsl_sf_bessel_In
//#define BESSEL_IP_FUNCTION_TO_TEST boost::math::cyl_bessel_i_prime
//#define BESSEL_IPN_FUNCTION_TO_TEST boost::math::cyl_bessel_i_prime
#define BESSEL_J_FUNCTION_TO_TEST  gsl_sf_bessel_Jnu
#define BESSEL_JN_FUNCTION_TO_TEST  gsl_sf_bessel_Jn
#define BESSEL_JS_FUNCTION_TO_TEST  gsl_bessel_js
//#define BESSEL_JP_FUNCTION_TO_TEST boost::math::cyl_bessel_j_prime
//#define BESSEL_JPN_FUNCTION_TO_TEST boost::math::cyl_bessel_j_prime
//#define BESSEL_JPS_FUNCTION_TO_TEST boost::math::sph_bessel_prime
#define BESSEL_K_FUNCTION_TO_TEST  gsl_sf_bessel_Knu
#define BESSEL_KN_FUNCTION_TO_TEST gsl_sf_bessel_Kn
//#define BESSEL_KP_FUNCTION_TO_TEST boost::math::cyl_bessel_k_prime
//#define BESSEL_KPN_FUNCTION_TO_TEST boost::math::cyl_bessel_k_prime
#define BESSEL_Y_FUNCTION_TO_TEST gsl_sf_bessel_Ynu
#define BESSEL_YN_FUNCTION_TO_TEST gsl_sf_bessel_Yn
#define BESSEL_YS_FUNCTION_TO_TEST gsl_bessel_ys
//#define BESSEL_YP_FUNCTION_TO_TEST boost::math::cyl_neumann_prime
//#define BESSEL_YNP_FUNCTION_TO_TEST boost::math::cyl_neumann_prime
//#define BESSEL_YSP_FUNCTION_TO_TEST boost::math::sph_neumann_prime

#define BETA_FUNCTION_TO_TEST gsl_sf_beta
//#define BINOMIAL_FUNCTION_TO_TEST boost::math::binomial_coefficient<T>

inline double RC(double a, double b)
{
   return gsl_sf_ellint_RC(a, b, GSL_PREC_DOUBLE);
}
inline double RD(double a, double b, double c)
{
   return gsl_sf_ellint_RD(a, b, c, GSL_PREC_DOUBLE);
}
inline double RF(double a, double b, double c)
{
   return gsl_sf_ellint_RF(a, b, c, GSL_PREC_DOUBLE);
}
inline double RJ(double a, double b, double c, double d)
{
   return gsl_sf_ellint_RJ(a, b, c, d, GSL_PREC_DOUBLE);
}

#define ELLINT_RC_FUNCTION_TO_TEST RC
#define ELLINT_RD_FUNCTION_TO_TEST RD
#define ELLINT_RF_FUNCTION_TO_TEST RF
//#define ELLINT_RG_FUNCTION_TO_TEST boost::math::ellint_rg
#define ELLINT_RJ_FUNCTION_TO_TEST RJ

#define DIGAMMA_FUNCTION_TO_TEST  gsl_sf_psi

inline double ellintK(double a) { return gsl_sf_ellint_Kcomp(a, GSL_PREC_DOUBLE); }
inline double ellintE(double a) { return gsl_sf_ellint_Ecomp(a, GSL_PREC_DOUBLE); }
inline double ellintP(double a, double b) { return gsl_sf_ellint_Pcomp(a, -b, GSL_PREC_DOUBLE); }

inline double ellintF(double a, double b) { return gsl_sf_ellint_F(b, a, GSL_PREC_DOUBLE); }
inline double ellintE2(double a, double b) { return gsl_sf_ellint_E(b, a, GSL_PREC_DOUBLE); }
inline double ellintP3(double a, double b, double c) { return gsl_sf_ellint_P(c, a, -b, GSL_PREC_DOUBLE); }
inline double ellintD2(double a, double b) { return gsl_sf_ellint_D(b, a, 0.0, GSL_PREC_DOUBLE); }

#define ELLINT_1_FUNCTION_TO_TEST ellintF
#define ELLINT_1C_FUNCTION_TO_TEST ellintK
#define ELLINT_2_FUNCTION_TO_TEST ellintE2
#define ELLINT_2C_FUNCTION_TO_TEST ellintE
#define ELLINT_3_FUNCTION_TO_TEST ellintP3
#define ELLINT_3C_FUNCTION_TO_TEST ellintP
#define ELLINT_D2_FUNCTION_TO_TEST ellintD2
//#define ELLINT_D1_FUNCTION_TO_TEST boost::math::ellint_d

#define EI_FUNCTION_TO_TEST gsl_sf_expint_Ei
#define EN_FUNCTION_TO_TEST  gsl_sf_expint_En

//#define HERMITE_FUNCTION_TO_TEST boost::math::hermite
//#define HEUMAN_LAMBDA_FUNCTION_TO_TEST boost::math::heuman_lambda

//#define BETA_INC_FUNCTION_TO_TEST boost::math::beta
//#define BETAC_INC_FUNCTION_TO_TEST boost::math::betac
#define IBETA_FUNCTION_TO_TEST gsl_sf_beta_inc
//#define IBETAC_FUNCTION_TO_TEST boost::math::ibetac
//#define IBETA_INV_FUNCTION_TO_TEST boost::math::ibeta_inv
//#define IBETAC_INV_FUNCTION_TO_TEST boost::math::ibetac_inv
//#define IBETA_INVA_FUNCTION_TO_TEST boost::math::ibeta_inva
//#define IBETAC_INVA_FUNCTION_TO_TEST boost::math::ibetac_inva
//#define IBETA_INVB_FUNCTION_TO_TEST boost::math::ibeta_invb
//#define IBETAC_INVB_FUNCTION_TO_TEST boost::math::ibetac_invb

#define IGAMMA_FUNCTION_TO_TEST gsl_sf_gamma_inc
//#define IGAMMAL_FUNCTION_TO_TEST boost::math::tgamma_lower
#define GAMMAP_FUNCTION_TO_TEST gsl_sf_gamma_inc_P
#define GAMMAQ_FUNCTION_TO_TEST gsl_sf_gamma_inc_Q
//#define GAMMAP_INV_FUNCTION_TO_TEST boost::math::gamma_p_inv
//#define GAMMAQ_INV_FUNCTION_TO_TEST boost::math::gamma_q_inv
//#define GAMMAP_INVA_FUNCTION_TO_TEST boost::math::gamma_p_inva
//#define GAMMAQ_INVA_FUNCTION_TO_TEST boost::math::gamma_q_inva

inline double sn(double k, double u)
{
   double s, c, d;
   gsl_sf_elljac_e(u, k * k, &s, &c, &d);
   return s;
}
inline double cn(double k, double u)
{
   double s, c, d;
   gsl_sf_elljac_e(u, k * k, &s, &c, &d);
   return c;
}
inline double dn(double k, double u)
{
   double s, c, d;
   gsl_sf_elljac_e(u, k * k, &s, &c, &d);
   return d;
}

#define SN_FUNCTION_TO_TEST sn
#define CN_FUNCTION_TO_TEST cn
#define DN_FUNCTION_TO_TEST dn
//#define JACOBI_ZETA_FUNCTION_TO_TEST boost::math::jacobi_zeta

inline double laguerre(unsigned n, unsigned m, double x){ return gsl_sf_laguerre_n(n, m, x); }
inline double laguerre_0(unsigned n, double x){ return gsl_sf_laguerre_n(n, 0, x); }

#define LAGUERRE_FUNCTION_TO_TEST laguerre_0
#define ASSOC_LAGUERRE_FUNCTION_TO_TEST laguerre

inline double legendre_q(unsigned n, double x) { return gsl_sf_legendre_Ql(n, x); }

#define LEGENDRE_P_FUNCTION_TO_TEST gsl_sf_legendre_Pl
#define LEGENDRE_Q_FUNCTION_TO_TEST  legendre_q
#define LEGENDRE_PA_FUNCTION_TO_TEST  gsl_sf_legendre_Plm

#define POLYGAMMA_FUNCTION_TO_TEST  gsl_sf_psi_n
//#define TGAMMA_RATIO_FUNCTION_TO_TEST boost::math::tgamma_ratio
//#define TGAMMA_DELTA_RATIO_FUNCTION_TO_TEST boost::math::tgamma_delta_ratio
//#define SIN_PI_RATIO_FUNCTION_TO_TEST boost::math::sin_pi
//#define COS_PI_RATIO_FUNCTION_TO_TEST boost::math::cos_pi
#define TRIGAMMA_RATIO_FUNCTION_TO_TEST gsl_sf_psi_1
#define ZETA_FUNCTION_TO_TEST gsl_sf_zeta

#define TYPE_TO_TEST double

#elif defined(TEST_RMATH)

#define MATHLIB_STANDALONE
#include <Rmath.h>

#undef trunc

#define TEST_LIBRARY_NAME "Rmath " R_VERSION_STRING

#define LOG1P_FUNCTION_TO_TEST log1p
#define EXPM1_FUNCTION_TO_TEST expm1

//#define CBRT_FUNCTION_TO_TEST boost::math::cbrt
//#define ERF_FUNCTION_TO_TEST boost::math::erf
//#define ERFC_FUNCTION_TO_TEST boost::math::erfc
//#define ERF_INV_FUNCTION_TO_TEST boost::math::erf_inv
//#define ERFC_INV_FUNCTION_TO_TEST boost::math::erfc_inv

#define LGAMMA_FUNCTION_TO_TEST lgammafn
#define TGAMMA_FUNCTION_TO_TEST gammafn
//#define TGAMMA1PM1_FUNCTION_TO_TEST boost::math::tgamma1pm1

inline double I(double n, double x) { return bessel_i(x, n, 1); }
inline double K(double n, double x) { return bessel_k(x, n, 1); }
inline double J(double n, double x) { return bessel_j(x, n); }
inline double Y(double n, double x) { return bessel_y(x, n); }

#define BESSEL_I_FUNCTION_TO_TEST I
#define BESSEL_IN_FUNCTION_TO_TEST I
//#define BESSEL_IP_FUNCTION_TO_TEST boost::math::cyl_bessel_i_prime
//#define BESSEL_IPN_FUNCTION_TO_TEST boost::math::cyl_bessel_i_prime
#define BESSEL_J_FUNCTION_TO_TEST J
#define BESSEL_JN_FUNCTION_TO_TEST J
//#define BESSEL_JS_FUNCTION_TO_TEST boost::math::sph_bessel
//#define BESSEL_JP_FUNCTION_TO_TEST boost::math::cyl_bessel_j_prime
//#define BESSEL_JPN_FUNCTION_TO_TEST boost::math::cyl_bessel_j_prime
//#define BESSEL_JPS_FUNCTION_TO_TEST boost::math::sph_bessel_prime
#define BESSEL_K_FUNCTION_TO_TEST K
#define BESSEL_KN_FUNCTION_TO_TEST K
//#define BESSEL_KP_FUNCTION_TO_TEST boost::math::cyl_bessel_k_prime
//#define BESSEL_KPN_FUNCTION_TO_TEST boost::math::cyl_bessel_k_prime
#define BESSEL_Y_FUNCTION_TO_TEST Y
#define BESSEL_YN_FUNCTION_TO_TEST Y
//#define BESSEL_YS_FUNCTION_TO_TEST boost::math::sph_neumann
//#define BESSEL_YP_FUNCTION_TO_TEST boost::math::cyl_neumann_prime
//#define BESSEL_YNP_FUNCTION_TO_TEST boost::math::cyl_neumann_prime
//#define BESSEL_YSP_FUNCTION_TO_TEST boost::math::sph_neumann_prime

#define BETA_FUNCTION_TO_TEST beta
//#define BINOMIAL_FUNCTION_TO_TEST boost::math::binomial_coefficient<T>

//#define ELLINT_RC_FUNCTION_TO_TEST boost::math::ellint_rc
//#define ELLINT_RD_FUNCTION_TO_TEST boost::math::ellint_rd
//#define ELLINT_RF_FUNCTION_TO_TEST boost::math::ellint_rf
//#define ELLINT_RG_FUNCTION_TO_TEST boost::math::ellint_rg
//#define ELLINT_RJ_FUNCTION_TO_TEST boost::math::ellint_rj

#define DIGAMMA_FUNCTION_TO_TEST digamma

//#define ELLINT_1_FUNCTION_TO_TEST boost::math::ellint_1
//#define ELLINT_1C_FUNCTION_TO_TEST boost::math::ellint_1
//#define ELLINT_2_FUNCTION_TO_TEST boost::math::ellint_2
//#define ELLINT_2C_FUNCTION_TO_TEST boost::math::ellint_2
//#define ELLINT_3_FUNCTION_TO_TEST boost::math::ellint_3
//#define ELLINT_3C_FUNCTION_TO_TEST boost::math::ellint_3
//#define ELLINT_D2_FUNCTION_TO_TEST boost::math::ellint_d
//#define ELLINT_D1_FUNCTION_TO_TEST boost::math::ellint_d

//#define EI_FUNCTION_TO_TEST boost::math::expint
//#define EN_FUNCTION_TO_TEST boost::math::expint

//#define HERMITE_FUNCTION_TO_TEST boost::math::hermite
//#define HEUMAN_LAMBDA_FUNCTION_TO_TEST boost::math::heuman_lambda

inline double ibeta(double a, double b, double x) { return pbeta(x, a, b, 1, 0); }
inline double ibetac(double a, double b, double x) { return pbeta(x, a, b, 0, 0); }
inline double ibeta_inv(double a, double b, double x) { return qbeta(x, a, b, 1, 0); }
inline double ibetac_inv(double a, double b, double x) { return qbeta(x, a, b, 0, 0); }

//#define BETA_INC_FUNCTION_TO_TEST boost::math::beta
//#define BETAC_INC_FUNCTION_TO_TEST boost::math::betac
#define IBETA_FUNCTION_TO_TEST ibeta
#define IBETAC_FUNCTION_TO_TEST ibetac
#define IBETA_INV_FUNCTION_TO_TEST ibeta_inv
#define IBETAC_INV_FUNCTION_TO_TEST ibetac_inv
//#define IBETA_INVA_FUNCTION_TO_TEST boost::math::ibeta_inva
//#define IBETAC_INVA_FUNCTION_TO_TEST boost::math::ibetac_inva
//#define IBETA_INVB_FUNCTION_TO_TEST boost::math::ibeta_invb
//#define IBETAC_INVB_FUNCTION_TO_TEST boost::math::ibetac_invb

inline double gamma_p(double a, double x) { return pgamma(x, a, 1.0, 1, 0); }
inline double gamma_q(double a, double x) { return pgamma(x, a, 1.0, 0, 0); }
inline double gamma_p_inv(double a, double x) { return qgamma(x, a, 1.0, 1, 0); }
inline double gamma_q_inv(double a, double x) { return qgamma(x, a, 1.0, 0, 0); }

//#define IGAMMA_FUNCTION_TO_TEST boost::math::tgamma
//#define IGAMMAL_FUNCTION_TO_TEST boost::math::tgamma_lower
#define GAMMAP_FUNCTION_TO_TEST gamma_p
#define GAMMAQ_FUNCTION_TO_TEST gamma_q
#define GAMMAP_INV_FUNCTION_TO_TEST gamma_p_inv
#define GAMMAQ_INV_FUNCTION_TO_TEST gamma_q_inv
//#define GAMMAP_INVA_FUNCTION_TO_TEST boost::math::gamma_p_inva
//#define GAMMAQ_INVA_FUNCTION_TO_TEST boost::math::gamma_q_inva

//#define SN_FUNCTION_TO_TEST boost::math::jacobi_sn
//#define CN_FUNCTION_TO_TEST boost::math::jacobi_cn
//#define DN_FUNCTION_TO_TEST boost::math::jacobi_dn
//#define JACOBI_ZETA_FUNCTION_TO_TEST boost::math::jacobi_zeta

//#define LAGUERRE_FUNCTION_TO_TEST boost::math::laguerre
//#define ASSOC_LAGUERRE_FUNCTION_TO_TEST boost::math::laguerre

//#define LEGENDRE_P_FUNCTION_TO_TEST boost::math::legendre_p
//#define LEGENDRE_Q_FUNCTION_TO_TEST boost::math::legendre_q
//#define LEGENDRE_PA_FUNCTION_TO_TEST boost::math::legendre_p

inline double polygamma(int n, double x) { return psigamma(x, n); }

#define POLYGAMMA_FUNCTION_TO_TEST polygamma
//#define TGAMMA_RATIO_FUNCTION_TO_TEST boost::math::tgamma_ratio
//#define TGAMMA_DELTA_RATIO_FUNCTION_TO_TEST boost::math::tgamma_delta_ratio
//#define SIN_PI_RATIO_FUNCTION_TO_TEST sinpi
//#define COS_PI_RATIO_FUNCTION_TO_TEST cospi
#define TRIGAMMA_RATIO_FUNCTION_TO_TEST trigamma
//#define ZETA_FUNCTION_TO_TEST boost::math::zeta

//#define SQRT1PM1_FUNCTION_TO_TEST boost::math::sqrt1pm1
//#define POWM1_FUNCTION_TO_TEST boost::math::powm1
//#define OWENS_T_FUNCTION_TO_TEST boost::math::owens_t
//#define SPHERICAL_HARMONIC_R_FUNCTION_TO_TEST boost::math::spherical_harmonic_r
//#define SPHERICAL_HARMONIC_I_FUNCTION_TO_TEST boost::math::spherical_harmonic_i

template <class T> T do_nc_beta_cdf(T a, T b, T nc, T x){ return pnbeta(x, a, b, nc, 1, 0); }
template <class T> T do_nc_beta_ccdf(T a, T b, T nc, T x){ return pnbeta(x, a, b, nc, 0, 0); }
template <class T> T do_nc_chi_squared_cdf(T df, T nc, T x){ return pnchisq(x, df, nc, 1, 0); }
template <class T> T do_nc_chi_squared_ccdf(T df, T nc, T x){ return pnchisq(x, df, nc, 0, 0); }
template <class T> T do_nc_t_cdf(T df, T nc, T x){ return pnt(x, df, nc, 1, 0); }
template <class T> T do_nc_t_ccdf(T df, T nc, T x){ return pnt(x, df, nc, 0, 0); }

#define NC_BETA_CDF_FUNCTION_TO_TEST do_nc_beta_cdf
#define NC_BETA_CCDF_FUNCTION_TO_TEST do_nc_beta_ccdf
#define NC_CHI_SQUARED_CDF_FUNCTION_TO_TEST do_nc_chi_squared_cdf
#define NC_CHI_SQUARED_CCDF_FUNCTION_TO_TEST do_nc_chi_squared_ccdf
#define NC_T_CDF_FUNCTION_TO_TEST do_nc_t_cdf
#define NC_T_CCDF_FUNCTION_TO_TEST do_nc_t_ccdf

#define TYPE_TO_TEST double

#elif defined(TEST_CEPHES)

#define TEST_LIBRARY_NAME "Cephes"
#define TYPE_TO_TEST double

extern "C" {

   double log1p(double) throw();
   double expm1(double) throw();
   double cbrt(double) throw();
   double erf(double) throw();
   double erfc(double) throw();
   double gamma(double) throw();
   double lgam(double) throw();

   double iv(double, double) throw();
   double jv(double, double) throw();
   double jn(int, double) throw();
   double kn(int, double) throw();
   double yn(int, double) throw();

   double beta(double, double)throw();
   double psi(double);

   double ellik(double, double);
   double ellpk(double);
   double ellie(double, double);
   double ellpe(double);

   double ei(double);
   // Can't get any sensible values from Cephes expn???
   //double expn(double, double);

   double incbet(double, double, double);
   double incbi(double, double, double);

   double igam(double, double);
   double igamc(double, double);
   double igami(double, double);

   double ellpj(double u, double m, double *sn, double *cn, double *dn, double *phi);

   double zetac(double);

}

inline double ellint_1(double k, double phi) { return ellik(phi, k * k); }
inline double ellint_2(double k, double phi) { return ellie(phi, k * k); }
inline double ellint_1(double k) { return ellpk(k * k); }
inline double ellint_2(double k) { return ellpe(k * k); }

inline double sn(double k, double u)
{
   double sn, cn, dn, phi;
   ellpj(u, k * k, &sn, &cn, &dn, &phi);
   return sn;
}
inline double cn(double k, double u)
{
   double sn, cn, dn, phi;
   ellpj(u, k * k, &sn, &cn, &dn, &phi);
   return cn;
}

inline double dn(double k, double u)
{
   double sn, cn, dn, phi;
   ellpj(u, k * k, &sn, &cn, &dn, &phi);
   return dn;
}

#define LOG1P_FUNCTION_TO_TEST log1p
#define EXPM1_FUNCTION_TO_TEST expm1

#define CBRT_FUNCTION_TO_TEST cbrt
#define ERF_FUNCTION_TO_TEST erf
#define ERFC_FUNCTION_TO_TEST erfc
//#define ERF_INV_FUNCTION_TO_TEST boost::math::erf_inv
//#define ERFC_INV_FUNCTION_TO_TEST boost::math::erfc_inv

#define LGAMMA_FUNCTION_TO_TEST lgam
#define TGAMMA_FUNCTION_TO_TEST gamma
//#define TGAMMA1PM1_FUNCTION_TO_TEST boost::math::tgamma1pm1

#define BESSEL_I_FUNCTION_TO_TEST iv
#define BESSEL_IN_FUNCTION_TO_TEST iv
//#define BESSEL_IP_FUNCTION_TO_TEST boost::math::cyl_bessel_i_prime
//#define BESSEL_IPN_FUNCTION_TO_TEST boost::math::cyl_bessel_i_prime
#define BESSEL_J_FUNCTION_TO_TEST jv
#define BESSEL_JN_FUNCTION_TO_TEST jn
//#define BESSEL_JS_FUNCTION_TO_TEST boost::math::sph_bessel
//#define BESSEL_JP_FUNCTION_TO_TEST boost::math::cyl_bessel_j_prime
//#define BESSEL_JPN_FUNCTION_TO_TEST boost::math::cyl_bessel_j_prime
//#define BESSEL_JPS_FUNCTION_TO_TEST boost::math::sph_bessel_prime
//#define BESSEL_K_FUNCTION_TO_TEST boost::math::cyl_bessel_k
#define BESSEL_KN_FUNCTION_TO_TEST kn
//#define BESSEL_KP_FUNCTION_TO_TEST boost::math::cyl_bessel_k_prime
//#define BESSEL_KPN_FUNCTION_TO_TEST boost::math::cyl_bessel_k_prime
//#define BESSEL_Y_FUNCTION_TO_TEST boost::math::cyl_neumann
#define BESSEL_YN_FUNCTION_TO_TEST yn
//#define BESSEL_YS_FUNCTION_TO_TEST boost::math::sph_neumann
//#define BESSEL_YP_FUNCTION_TO_TEST boost::math::cyl_neumann_prime
//#define BESSEL_YNP_FUNCTION_TO_TEST boost::math::cyl_neumann_prime
//#define BESSEL_YSP_FUNCTION_TO_TEST boost::math::sph_neumann_prime

#define BETA_FUNCTION_TO_TEST beta
//#define BINOMIAL_FUNCTION_TO_TEST boost::math::binomial_coefficient<T>

//#define ELLINT_RC_FUNCTION_TO_TEST boost::math::ellint_rc
//#define ELLINT_RD_FUNCTION_TO_TEST boost::math::ellint_rd
//#define ELLINT_RF_FUNCTION_TO_TEST boost::math::ellint_rf
//#define ELLINT_RG_FUNCTION_TO_TEST boost::math::ellint_rg
//#define ELLINT_RJ_FUNCTION_TO_TEST boost::math::ellint_rj

#define DIGAMMA_FUNCTION_TO_TEST psi

#define ELLINT_1_FUNCTION_TO_TEST ellint_1
// Can't seem to get sensible answers from Cephes complete elliptic integrals???
//#define ELLINT_1C_FUNCTION_TO_TEST ellint_1
#define ELLINT_2_FUNCTION_TO_TEST ellint_2
//#define ELLINT_2C_FUNCTION_TO_TEST ellint_2
//#define ELLINT_3_FUNCTION_TO_TEST boost::math::ellint_3
//#define ELLINT_3C_FUNCTION_TO_TEST boost::math::ellint_3
//#define ELLINT_D2_FUNCTION_TO_TEST boost::math::ellint_d
//#define ELLINT_D1_FUNCTION_TO_TEST boost::math::ellint_d

#define EI_FUNCTION_TO_TEST ei
//#define EN_FUNCTION_TO_TEST expn

//#define HERMITE_FUNCTION_TO_TEST boost::math::hermite
//#define HEUMAN_LAMBDA_FUNCTION_TO_TEST boost::math::heuman_lambda

//#define BETA_INC_FUNCTION_TO_TEST incbet
//#define BETAC_INC_FUNCTION_TO_TEST boost::math::betac
#define IBETA_FUNCTION_TO_TEST incbet
//#define IBETAC_FUNCTION_TO_TEST boost::math::ibetac
#define IBETA_INV_FUNCTION_TO_TEST incbi
//#define IBETAC_INV_FUNCTION_TO_TEST boost::math::ibetac_inv
//#define IBETA_INVA_FUNCTION_TO_TEST boost::math::ibeta_inva
//#define IBETAC_INVA_FUNCTION_TO_TEST boost::math::ibetac_inva
//#define IBETA_INVB_FUNCTION_TO_TEST boost::math::ibeta_invb
//#define IBETAC_INVB_FUNCTION_TO_TEST boost::math::ibetac_invb

//#define IGAMMA_FUNCTION_TO_TEST boost::math::tgamma
//#define IGAMMAL_FUNCTION_TO_TEST boost::math::tgamma_lower
#define GAMMAP_FUNCTION_TO_TEST igam
#define GAMMAQ_FUNCTION_TO_TEST igamc
//#define GAMMAP_INV_FUNCTION_TO_TEST boost::math::gamma_p_inv
#define GAMMAQ_INV_FUNCTION_TO_TEST igami
//#define GAMMAP_INVA_FUNCTION_TO_TEST boost::math::gamma_p_inva
//#define GAMMAQ_INVA_FUNCTION_TO_TEST boost::math::gamma_q_inva

#define SN_FUNCTION_TO_TEST sn
#define CN_FUNCTION_TO_TEST cn
#define DN_FUNCTION_TO_TEST dn

#define ZETA_FUNCTION_TO_TEST zetac

#else

#include <boost/math/distributions/non_central_beta.hpp>
#include <boost/math/distributions/non_central_chi_squared.hpp>
#include <boost/math/distributions/non_central_t.hpp>

#define TEST_LIBRARY_NAME "boost"

#define LOG1P_FUNCTION_TO_TEST boost::math::log1p
#define EXPM1_FUNCTION_TO_TEST boost::math::expm1

#define CBRT_FUNCTION_TO_TEST boost::math::cbrt
#define ERF_FUNCTION_TO_TEST boost::math::erf
#define ERFC_FUNCTION_TO_TEST boost::math::erfc
#define ERF_INV_FUNCTION_TO_TEST boost::math::erf_inv
#define ERFC_INV_FUNCTION_TO_TEST boost::math::erfc_inv

#define LGAMMA_FUNCTION_TO_TEST boost::math::lgamma
#define TGAMMA_FUNCTION_TO_TEST boost::math::tgamma
#define TGAMMA1PM1_FUNCTION_TO_TEST boost::math::tgamma1pm1

#define BESSEL_I_FUNCTION_TO_TEST boost::math::cyl_bessel_i
#define BESSEL_IN_FUNCTION_TO_TEST boost::math::cyl_bessel_i
#define BESSEL_IP_FUNCTION_TO_TEST boost::math::cyl_bessel_i_prime
#define BESSEL_IPN_FUNCTION_TO_TEST boost::math::cyl_bessel_i_prime
#define BESSEL_J_FUNCTION_TO_TEST boost::math::cyl_bessel_j
#define BESSEL_JN_FUNCTION_TO_TEST boost::math::cyl_bessel_j
#define BESSEL_JS_FUNCTION_TO_TEST boost::math::sph_bessel
#define BESSEL_JP_FUNCTION_TO_TEST boost::math::cyl_bessel_j_prime
#define BESSEL_JPN_FUNCTION_TO_TEST boost::math::cyl_bessel_j_prime
#define BESSEL_JPS_FUNCTION_TO_TEST boost::math::sph_bessel_prime
#define BESSEL_K_FUNCTION_TO_TEST boost::math::cyl_bessel_k
#define BESSEL_KN_FUNCTION_TO_TEST boost::math::cyl_bessel_k
#define BESSEL_KP_FUNCTION_TO_TEST boost::math::cyl_bessel_k_prime
#define BESSEL_KPN_FUNCTION_TO_TEST boost::math::cyl_bessel_k_prime
#define BESSEL_Y_FUNCTION_TO_TEST boost::math::cyl_neumann
#define BESSEL_YN_FUNCTION_TO_TEST boost::math::cyl_neumann
#define BESSEL_YS_FUNCTION_TO_TEST boost::math::sph_neumann
#define BESSEL_YP_FUNCTION_TO_TEST boost::math::cyl_neumann_prime
#define BESSEL_YNP_FUNCTION_TO_TEST boost::math::cyl_neumann_prime
#define BESSEL_YSP_FUNCTION_TO_TEST boost::math::sph_neumann_prime

#define BETA_FUNCTION_TO_TEST boost::math::beta
#define BINOMIAL_FUNCTION_TO_TEST boost::math::binomial_coefficient<T>

#define ELLINT_RC_FUNCTION_TO_TEST boost::math::ellint_rc
#define ELLINT_RD_FUNCTION_TO_TEST boost::math::ellint_rd
#define ELLINT_RF_FUNCTION_TO_TEST boost::math::ellint_rf
#define ELLINT_RG_FUNCTION_TO_TEST boost::math::ellint_rg
#define ELLINT_RJ_FUNCTION_TO_TEST boost::math::ellint_rj

#define DIGAMMA_FUNCTION_TO_TEST boost::math::digamma

#define ELLINT_1_FUNCTION_TO_TEST boost::math::ellint_1
#define ELLINT_1C_FUNCTION_TO_TEST boost::math::ellint_1
#define ELLINT_2_FUNCTION_TO_TEST boost::math::ellint_2
#define ELLINT_2C_FUNCTION_TO_TEST boost::math::ellint_2
#define ELLINT_3_FUNCTION_TO_TEST boost::math::ellint_3
#define ELLINT_3C_FUNCTION_TO_TEST boost::math::ellint_3
#define ELLINT_D2_FUNCTION_TO_TEST boost::math::ellint_d
#define ELLINT_D1_FUNCTION_TO_TEST boost::math::ellint_d

#define EI_FUNCTION_TO_TEST boost::math::expint
#define EN_FUNCTION_TO_TEST boost::math::expint

#define HERMITE_FUNCTION_TO_TEST boost::math::hermite
#define HEUMAN_LAMBDA_FUNCTION_TO_TEST boost::math::heuman_lambda

#define BETA_INC_FUNCTION_TO_TEST boost::math::beta
#define BETAC_INC_FUNCTION_TO_TEST boost::math::betac
#define IBETA_FUNCTION_TO_TEST boost::math::ibeta
#define IBETAC_FUNCTION_TO_TEST boost::math::ibetac
#define IBETA_INV_FUNCTION_TO_TEST boost::math::ibeta_inv
#define IBETAC_INV_FUNCTION_TO_TEST boost::math::ibetac_inv
#define IBETA_INVA_FUNCTION_TO_TEST boost::math::ibeta_inva
#define IBETAC_INVA_FUNCTION_TO_TEST boost::math::ibetac_inva
#define IBETA_INVB_FUNCTION_TO_TEST boost::math::ibeta_invb
#define IBETAC_INVB_FUNCTION_TO_TEST boost::math::ibetac_invb

#define IGAMMA_FUNCTION_TO_TEST boost::math::tgamma
#define IGAMMAL_FUNCTION_TO_TEST boost::math::tgamma_lower
#define GAMMAP_FUNCTION_TO_TEST boost::math::gamma_p
#define GAMMAQ_FUNCTION_TO_TEST boost::math::gamma_q
#define GAMMAP_INV_FUNCTION_TO_TEST boost::math::gamma_p_inv
#define GAMMAQ_INV_FUNCTION_TO_TEST boost::math::gamma_q_inv
#define GAMMAP_INVA_FUNCTION_TO_TEST boost::math::gamma_p_inva
#define GAMMAQ_INVA_FUNCTION_TO_TEST boost::math::gamma_q_inva

#define SN_FUNCTION_TO_TEST boost::math::jacobi_sn
#define CN_FUNCTION_TO_TEST boost::math::jacobi_cn
#define DN_FUNCTION_TO_TEST boost::math::jacobi_dn
#define JACOBI_ZETA_FUNCTION_TO_TEST boost::math::jacobi_zeta

#define LAGUERRE_FUNCTION_TO_TEST boost::math::laguerre
#define ASSOC_LAGUERRE_FUNCTION_TO_TEST boost::math::laguerre

#define LEGENDRE_P_FUNCTION_TO_TEST boost::math::legendre_p
#define LEGENDRE_Q_FUNCTION_TO_TEST boost::math::legendre_q
#define LEGENDRE_PA_FUNCTION_TO_TEST boost::math::legendre_p

#define POLYGAMMA_FUNCTION_TO_TEST boost::math::polygamma
#define TGAMMA_RATIO_FUNCTION_TO_TEST boost::math::tgamma_ratio
#define TGAMMA_DELTA_RATIO_FUNCTION_TO_TEST boost::math::tgamma_delta_ratio
#define SIN_PI_RATIO_FUNCTION_TO_TEST boost::math::sin_pi
#define COS_PI_RATIO_FUNCTION_TO_TEST boost::math::cos_pi
#define TRIGAMMA_RATIO_FUNCTION_TO_TEST boost::math::trigamma
#define ZETA_FUNCTION_TO_TEST boost::math::zeta

#define SQRT1PM1_FUNCTION_TO_TEST boost::math::sqrt1pm1
#define POWM1_FUNCTION_TO_TEST boost::math::powm1
#define OWENS_T_FUNCTION_TO_TEST boost::math::owens_t
#define SPHERICAL_HARMONIC_R_FUNCTION_TO_TEST boost::math::spherical_harmonic_r
#define SPHERICAL_HARMONIC_I_FUNCTION_TO_TEST boost::math::spherical_harmonic_i

template <class T> T do_nc_beta_cdf(T a, T b, T nc, T x){ return cdf(boost::math::non_central_beta_distribution<T>(a, b, nc), x); }
template <class T> T do_nc_beta_ccdf(T a, T b, T nc, T x){ return cdf(complement(boost::math::non_central_beta_distribution<T>(a, b, nc), x)); }
template <class T> T do_nc_chi_squared_cdf(T df, T nc, T x){ return cdf(boost::math::non_central_chi_squared_distribution<T>(df, nc), x); }
template <class T> T do_nc_chi_squared_ccdf(T df, T nc, T x){ return cdf(complement(boost::math::non_central_chi_squared_distribution<T>(df, nc), x)); }
template <class T> T do_nc_t_cdf(T df, T nc, T x){ return cdf(boost::math::non_central_t_distribution<T>(df, nc), x); }
template <class T> T do_nc_t_ccdf(T df, T nc, T x){ return cdf(complement(boost::math::non_central_t_distribution<T>(df, nc), x)); }

#define NC_BETA_CDF_FUNCTION_TO_TEST do_nc_beta_cdf
#define NC_BETA_CCDF_FUNCTION_TO_TEST do_nc_beta_ccdf
#define NC_CHI_SQUARED_CDF_FUNCTION_TO_TEST do_nc_chi_squared_cdf
#define NC_CHI_SQUARED_CCDF_FUNCTION_TO_TEST do_nc_chi_squared_ccdf
#define NC_T_CDF_FUNCTION_TO_TEST do_nc_t_cdf
#define NC_T_CCDF_FUNCTION_TO_TEST do_nc_t_ccdf

#endif

#if defined(TYPE_TO_TEST) && !defined(NAME_OF_TYPE_TO_TEST)
#define NAME_OF_TYPE_TO_TEST BOOST_STRINGIZE(TYPE_TO_TEST)
#endif

//
// This include has to come at the end after all the setup is done:
//
#include "handle_test_result.hpp"

#endif

ext: hpp

max_stars_repo_name: ZCube/boost-cmake

max_issues_repo_name: ZCube/boost-cmake

max_forks_repo_name: ZCube/boost-cmake


text:
#ifndef CHORD_APPLICATION_HPP
#define CHORD_APPLICATION_HPP

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

#include <boost/noncopyable.hpp>
#include <chord/foundation/chord_foundation.h>
#include <chord/foundation/types.h>

namespace chord {

class application
    : private boost::noncopyable
{
public:
    application() {}
    application(int argc, char* argv[])
    {
    }

protected:
    void set_name(const std::string& name) { _name = name; }
    inline const std::string& name() { return _name; }
    virtual int run() { return 0; }

private:
    std::string _name;
};

} // namespace chord

#endif

max_stars_repo_name: AngryPowman/chord

max_issues_repo_name: AngryPowman/chord

max_forks_repo_name: AngryPowman/chord


text:
// Copyright (c) 2011-2015 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <interfaces/node.h>
#include <qt/trafficgraphwidget.h>
#include <qt/clientmodel.h>
#include <qt/guiutil.h>

#include <boost/bind.hpp>

#include <QPainter>
#include <QPainterPath>
#include <QColor>
#include <QTimer>

#include <cmath>

#define XMARGIN                 10
#define YMARGIN                 10

#define DEFAULT_SAMPLE_HEIGHT    1.1f

TrafficGraphWidget::TrafficGraphWidget(QWidget *parent) :
    QWidget(parent),
    timer(0),
    fMax(DEFAULT_SAMPLE_HEIGHT),
    nMins(0),
    clientModel(0),
    trafficGraphData(TrafficGraphData::Range_30m)
{
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), SLOT(updateRates()));
    timer->setInterval(TrafficGraphData::SMALLEST_SAMPLE_PERIOD);
    timer->start();
}

void TrafficGraphWidget::setClientModel(ClientModel *model)
{
    clientModel = model;
    if(model) {
        trafficGraphData.setLastBytes(model->node().getTotalBytesRecv(), model->node().getTotalBytesSent());
    }
}

int TrafficGraphWidget::getGraphRangeMins() const
{
    return nMins;
}

void TrafficGraphWidget::paintPath(QPainterPath &path, const TrafficGraphData::SampleQueue &queue, SampleChooser chooser)
{
    int sampleCount = queue.size();
    if(sampleCount > 0) {
        int h = height() - YMARGIN * 2, w = width() - XMARGIN * 2;
        int x = XMARGIN + w;
        path.moveTo(x, YMARGIN + h);
        for(int i = 0; i < sampleCount; ++i) {
            x = XMARGIN + w - w * i / TrafficGraphData::DESIRED_DATA_SAMPLES;
            int y = YMARGIN + h - (int)(h * chooser(queue.at(i)) / fMax);
            path.lineTo(x, y);
        }
        path.lineTo(x, YMARGIN + h);
    }
}

namespace
{
    float chooseIn(const TrafficSample& sample)
    {
        return sample.in;
    }
    float chooseOut(const TrafficSample& sample)
    {
        return sample.out;
    }
}

void TrafficGraphWidget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QRect drawRect = rect();
    // First draw the border
    painter.fillRect(drawRect, GUIUtil::getThemedQColor(GUIUtil::ThemedColor::BORDER_WIDGET));
    painter.fillRect(drawRect.adjusted(1, 1, -1, -1), GUIUtil::getThemedQColor(GUIUtil::ThemedColor::BACKGROUND_WIDGET));

    if(fMax <= 0.0f) return;

    QColor green = GUIUtil::getThemedQColor(GUIUtil::ThemedColor::GREEN);
    QColor red = GUIUtil::getThemedQColor(GUIUtil::ThemedColor::RED);
    QColor axisCol(GUIUtil::getThemedQColor(GUIUtil::ThemedColor::DEFAULT));
    QColor axisCol2;
    int h = height() - YMARGIN * 2;
    painter.setPen(axisCol);
    painter.drawLine(XMARGIN, YMARGIN + h, width() - XMARGIN, YMARGIN + h);

    // decide what order of magnitude we are
    int base = floor(log10(fMax));
    float val = pow(10.0f, base);
    float val2 = val;

    const QString units     = tr("KB/s");
    const float yMarginText = 2.0;

    // draw lines
    painter.setPen(axisCol);
    for(float y = val; y < fMax; y += val) {
        int yy = YMARGIN + h - h * y / fMax;
        painter.drawLine(XMARGIN, yy, width() - XMARGIN, yy);
    }
    // if we drew 3 or fewer lines, break them up at the next lower order of magnitude
    if(fMax / val <= 3.0f) {
        axisCol2 = axisCol.darker();
        val2 = pow(10.0f, base - 1);
        painter.setPen(axisCol2);
        int count = 1;
        for(float y = val2; y < fMax; y += val2, count++) {
            // don't overwrite lines drawn above
            if(count % 10 == 0)
                continue;
            int yy = YMARGIN + h - h * y / fMax;
            painter.drawLine(XMARGIN, yy, width() - XMARGIN, yy);
        }
    }

    const TrafficGraphData::SampleQueue& queue = trafficGraphData.getCurrentRangeQueueWithAverageBandwidth();

    if(!queue.empty()) {
        QPainterPath pIn;
        QColor lucentGreen = green;
        lucentGreen.setAlpha(128);

        paintPath(pIn, queue, boost::bind(chooseIn,_1));
        painter.fillPath(pIn, lucentGreen);
        painter.setPen(green);
        painter.drawPath(pIn);

        QPainterPath pOut;
        QColor lucentRed = red;
        lucentRed.setAlpha(128);

        paintPath(pOut, queue, boost::bind(chooseOut,_1));
        painter.fillPath(pOut, lucentRed);
        painter.setPen(red);
        painter.drawPath(pOut);
    }

    // draw text
    QRect textRect = painter.boundingRect(QRect(XMARGIN, YMARGIN + h - (h * val / fMax) - yMarginText, 0, 0), Qt::AlignLeft, QString("%1 %2").arg(val).arg(units));
    textRect.translate(0, -textRect.height());
    painter.fillRect(textRect, GUIUtil::getThemedQColor(GUIUtil::ThemedColor::BACKGROUND_WIDGET));
    painter.setPen(axisCol);
    painter.drawText(textRect, Qt::AlignLeft, QString("%1 %2").arg(val).arg(units));
    if(fMax / val <= 3.0f) {
        QRect textRect2 = painter.boundingRect(QRect(XMARGIN, YMARGIN + h - (h * val2 / fMax) - yMarginText, 0, 0), Qt::AlignLeft, QString("%1 %2").arg(val2).arg(units));
        textRect2.translate(0, -textRect2.height());
        painter.fillRect(textRect2, GUIUtil::getThemedQColor(GUIUtil::ThemedColor::BACKGROUND_WIDGET));
        painter.setPen(axisCol2);
        painter.drawText(textRect2, Qt::AlignLeft, QString("%1 %2").arg(val2).arg(units));
    }

    // Draw statistic rect on top of everything else
    const int nPadding = 5;
    const int nMarginStats = 20;
    const QString strTotal = tr("Total");
    const QString strReceived = tr("Received");
    const QString strSent = tr("Sent");
    // Get a bold font for the title and a normal one for the rest
    QFont fontTotal = GUIUtil::getFont(GUIUtil::FontWeight::Bold, false, 16);
    QFont fontInOut = GUIUtil::getFont(GUIUtil::FontWeight::Normal, false, 12);
    // Use font metrics to determine minimum rect sizes depending on the font scale
    QFontMetrics fmTotal(fontTotal);
    QFontMetrics fmInOut(fontInOut);
    const int nSizeMark = fmInOut.height() + 2 * nPadding;
    const int nWidthText = fmInOut.width(strReceived) + 2 * nPadding;
    const int nWidthBytes = fmInOut.width("1000 GB") + 2 * nPadding;
    const int nHeightTotals = fmTotal.height() + 2 * nPadding;
    const int nHeightInOut = fmInOut.height() + 2 * nPadding;
    const int nWidthStats = nSizeMark + nWidthText + nWidthBytes + 2 * nPadding;
    const int nHeightStats = nHeightTotals + 2 * nHeightInOut + 2 * nPadding;
    auto addPadding = [&](QRect& rect, int nPadding) {
        rect.adjust(nPadding, nPadding, -nPadding, -nPadding);
    };
    // Create top-level rects
    QRect rectOuter = QRect(drawRect.width() - nWidthStats - nMarginStats, nMarginStats, nWidthStats, nHeightStats);
    QRect rectContent = rectOuter;
    QRect rectContentPadded = rectContent;
    addPadding(rectContentPadded, nPadding);
    QRect rectTotals(rectContentPadded.topLeft(), QSize(rectContentPadded.width(), nHeightTotals));
    QRect rectIn(rectTotals.bottomLeft(), QSize(rectContentPadded.width(), nHeightInOut));
    QRect rectOut(rectIn.bottomLeft(), QSize(rectContentPadded.width(), nHeightInOut));
    // Create subrects for received
    QRect rectInMark(rectIn.topLeft(), QSize(nSizeMark, nSizeMark));
    QRect rectInText(rectInMark.topRight(), QSize(nWidthText, nHeightInOut));
    QRect rectInBytes(rectInText.topRight(), QSize(nWidthBytes, nHeightInOut));
    // Create subrects for sent
    QRect rectOutMark(rectOut.topLeft(), QSize(nSizeMark, nSizeMark));
    QRect rectOutText(rectOutMark.topRight(), QSize(nWidthText, nHeightInOut));
    QRect rectOutBytes(rectOutText.topRight(), QSize(nWidthBytes, nHeightInOut));
    // Add padding where required
    addPadding(rectTotals, nPadding);
    addPadding(rectInMark, 1.6 * nPadding);
    addPadding(rectInText, nPadding);
    addPadding(rectInBytes, nPadding);
    addPadding(rectOutMark, 1.6 * nPadding);
    addPadding(rectOutText, nPadding);
    addPadding(rectOutBytes, nPadding);
    // Finally draw it all
    painter.setPen(QPen(GUIUtil::getThemedQColor(GUIUtil::ThemedColor::BORDER_NETSTATS), 1));
    painter.drawRect(rectOuter);
    painter.fillRect(rectContent, GUIUtil::getThemedQColor(GUIUtil::ThemedColor::BACKGROUND_NETSTATS));
    painter.setPen(axisCol);
    painter.setFont(fontTotal);
    painter.drawText(rectTotals, Qt::AlignLeft, strTotal);
    painter.setFont(fontInOut);
    painter.drawText(rectInText, Qt::AlignLeft, strReceived);
    painter.drawText(rectInBytes, Qt::AlignRight, GUIUtil::formatBytes(trafficGraphData.getLastBytesIn()));
    painter.drawText(rectOutText, Qt::AlignLeft, strSent);
    painter.drawText(rectOutBytes, Qt::AlignRight, GUIUtil::formatBytes(trafficGraphData.getLastBytesOut()));
    painter.setPen(green);
    painter.setBrush(green);
    painter.drawEllipse(rectInMark);
    painter.setPen(red);
    painter.setBrush(red);
    painter.drawEllipse(rectOutMark);
}

void TrafficGraphWidget::updateRates()
{
    if(!clientModel) return;

    bool updated = trafficGraphData.update(clientModel->node().getTotalBytesRecv(),clientModel->node().getTotalBytesSent());

    if (updated){
        float tmax = DEFAULT_SAMPLE_HEIGHT;
        for (const TrafficSample& sample : trafficGraphData.getCurrentRangeQueueWithAverageBandwidth()) {
            if(sample.in > tmax) tmax = sample.in;
            if(sample.out > tmax) tmax = sample.out;
        }
        fMax = tmax;
        update();
    }
}

void TrafficGraphWidget::setGraphRangeMins(int value)
{
    trafficGraphData.switchRange(static_cast<TrafficGraphData::GraphRange>(value));
    update();
}

void TrafficGraphWidget::clear()
{
    trafficGraphData.clear();
    fMax = DEFAULT_SAMPLE_HEIGHT;
    if(clientModel) {
        trafficGraphData.setLastBytes(clientModel->node().getTotalBytesRecv(), clientModel->node().getTotalBytesSent());
    }
    update();
}

max_stars_repo_name: PaulieD/dash

max_issues_repo_name: PaulieD/dash

max_forks_repo_name: PaulieD/dash


text:
#include "stdafx.h"

#define BOOST_USE_POSTGRES_DATABASE

#include <boost/database.hpp>
#include <boost/foreach.hpp>
#include <iostream>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/lexical_cast.hpp>

BOOST_AUTO_TEST_CASE( test_postgres_insert )
{
	boost::database::ConnectionAttributes attr;

	attr.port = 5433;
	attr.db_name = "credentials_tbl";
	attr.password = "password";

	boost::database::Database db(attr);

	db.launch();

	for (int i = 0; i < 10; i++)
	{
		std::string sql;

		boost::uuids::uuid id = boost::uuids::random_generator()();

		sql = "INSERT INTO credentials_tbl(id, email, name, password) ";
		sql += "VALUES('";
		sql += boost::lexical_cast<std::string>(id);
		sql += "', 'example";
		sql += boost::lexical_cast<std::string>(i);
		sql += "@email.org', 'max";
		sql += boost::lexical_cast<std::string>(i);
		sql += "', 'pw'); ";

		BOOST_CHECK(db.insert(sql));
	}

}


text:
/*
 * solver.cpp
 *
 * Purpose: utility of solver class
 * Created by: Keisuke Okumura <okumura.k@coord.c.titech.ac.jp>
 */

#include "solver.h"
#include <random>
#include "../util/util.h"
#include <typeinfo>

#include <iostream>
#include <fstream>
#include <boost/algorithm/string.hpp>
#include <set>

class CSVReader
{
    std::string fileName;
    std::string delimeter;
public:
    CSVReader(std::string filename, std::string delm = " ") :
            fileName(filename), delimeter(delm)
    { }
    // Function to fetch data from a CSV File
    std::vector<std::vector<std::string> > getData();
};
/*
* Parses through csv file line by line and returns the data
* in vector of vector of strings.
*/
std::vector<std::vector<std::string> > CSVReader::getData()
{
    std::ifstream file(fileName);
    std::vector<std::vector<std::string> > dataList;
    std::string line = "";
    // Iterate through each line and split the content using delimeter
    while (getline(file, line))
    {
        std::vector<std::string> vec;
        boost::algorithm::split(vec, line, boost::is_any_of(delimeter));
        dataList.push_back(vec);
    }
    // Close the File
    file.close();
    return dataList;
}

Solver::Solver(Problem* _P) : P(_P) {
  std::random_device seed_gen;
  MT = new std::mt19937(seed_gen());
  init();
}
Solver::Solver(Problem* _P, std::mt19937* _MT) : P(_P), MT(_MT) {

  init();

}

Solver::~Solver() {}

void Solver::init() {
  G = P->getG();
  A = P->getA();
  int nodeNum = G->getNodesNum();
  for (int i = 0; i < nodeNum; ++i)
  {
    is_visit.push_back(false);
    /* code */
  }
  dists = Eigen::MatrixXi::Zero(nodeNum, nodeNum);
  new_dists = Eigen::MatrixXi::Ones(nodeNum, nodeNum)*10000;
}

void Solver::setDirectory(std::string folder_name){
  std::string cost = "cost";
  folder_name.replace(2,3,cost);
  folder_name.replace(folder_name.size()-4,4,"/");
  directory_name = folder_name;
  return;
}

void Solver::solveStart() {
  startT = std::chrono::high_resolution_clock::now();
}

void Solver::solveEnd() {
  endT = std::chrono::high_resolution_clock::now();
  elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>
    (endT-startT).count();
}

void Solver::WarshallFloyd(std::string flieName) {
  int nodeNum = G->getNodesNum();
  Nodes neighbor;
  int INF = 100000;
  dists = Eigen::MatrixXi::Ones(nodeNum, nodeNum) * INF;

  // initialize weight
  for (int i = 0; i < nodeNum; ++i) {
    neighbor = G->neighbor(G->getNodeFromIndex(i));
    for (auto v : neighbor) {
      dists(i, v->getIndex()) = 1;
    }
    dists(i, i) = 0;
  }

  //std::cout<<"Node num "<<nodeNum<<" shuru\n";

  // // main loop
  for (int k = 0; k < nodeNum; ++k) {
    for (int i = 0; i < nodeNum; ++i) {
      for (int j = 0; j < nodeNum; ++j) {
        if (dists(i, j) > dists(i, k) + dists(k, j)) {
          dists(i, j) = dists(i, k) + dists(k, j);
        }
      }
    }
  }
}

int Solver::getMaxLengthPaths(Paths& paths) {
  if (paths.empty()) return 0;
  auto itr = std::max_element(paths.begin(), paths.end(),
                              [] (Nodes p1, Nodes p2) {
                                return p1.size() < p2.size(); });
  return itr->size();
}

void Solver::formalizePath(Paths& paths) {
  int maxLength = getMaxLengthPaths(paths);
  Node* g;
  for (int i = 0; i < paths.size(); ++i) {
    g = paths[i][paths[i].size() - 1];
    while (paths[i].size() != maxLength) paths[i].push_back(g);
  }
}

int Solver::pathDist(Node* s, Node* g) {
  // same place?
  if (s == g) return 0;

  // has already explored?
  int s_index = G->getNodeIndex(s);
  int g_index = G->getNodeIndex(g);
  int dist = dists(s_index, g_index);
  if (dist != 0) return dist;

  // new
  Nodes path = G->getPath(s, g);

  dist = path.size() - 1;  // without start node
  int index, d, cost;
  bool directed = G->isDirected();

  cost = dist;
  for (auto v : path) {
    index = G->getNodeIndex(v);
    d = dists(index, g_index);
    if ((index != g_index) && (d == 0)) {
      dists(index, g_index) = cost;
      // if not directed graph
      if (!directed) dists(g_index, index) = cost;
      --cost;
    } else if (d == cost) {
      break;
    } else {
      std::cout << "error@Solver::pathDist, "
                << s->getId() << " -> " << g->getId() << ", "
                << s->getPos() << " -> " << g->getPos() << ", "
                << "not optimal path is obtained" << "\n";
      std::exit(1);
    }
  }

  return dist;
}

int Solver::pathDist(Node* s, Node* g, Nodes &prohibited) {
  // same place?
  if (s == g) return 0;

  return G->getPath(s, g, prohibited).size() - 1;
}

std::string Solver::getKey(int t, Node* v) {
  std::string key = "";
  key += std::to_string(t);
  key += "-";
  key += std::to_string(v->getId());
  return key;
}

std::string Solver::getKey(AN* n) {
  return getKey(n->g, n->v);
}

std::string Solver::logStr() {
  std::string str;

  str += "[solver] solved:" + std::to_string(P->isSolved()) + "\n";
  str += "elapsed: " + std::to_string((int)elapsedTime) + "\n";
  str += "makespan: " + std::to_string(P->getTerminationTime()) + "\n";
  std::cout<<str;
  str += P->logStr();

  return str;
}

void Solver::SaveDataToFile(std::string folder_name) {
    //std::cout<<"asche\n";
    std::string cost = "cost";
    folder_name.replace(2,3,cost);
    folder_name.replace(folder_name.size()-4,4,"/");
    directory_name = folder_name;

    int nodeNum = G->getNodesNum();
    for (int i = 0; i < nodeNum ; ++i)
    {
      std::string cost_data = dijkstra(i);
      //std::cout<<"counting for : "<<i<<"\n";
      std::string filename = folder_name+"node_"+std::to_string(i);
      std::ofstream file;
      file.open (filename);
      file << cost_data;
      file.close();
    }
}

bool Solver::djikstra_source_to_goal(Agent *a, Node *s, Node *g){

    int SIZE = G->getNodesNum();

    int dista [SIZE];
    bool vis [SIZE];
    std::memset(vis, false , sizeof vis);
    std::memset(dista,10000,sizeof dista);
    int src_id = s->getId();
    dista[src_id] = 0;
    std::multiset < std::pair < int , int > > m_set;

    m_set.insert({0 , src_id});
    int cnt = 0;
    while(!m_set.empty()){
        cnt++;
        std::pair <int , int> p = *m_set.begin();
        m_set.erase(*m_set.begin());

        int x = p.second; int wei = p.first;
        if(g->getId() == x) return true;
        if( vis[x] ) continue;
        vis[x] = true;
        Nodes neighbor;
        neighbor = G->neighbor(G->getNode(x));
        for (auto v : neighbor) {
          int e = v->getId();
          int w = 1;
          if(dista[x] + w < dista[e]  ){
                dista[e] = dista[x] + w;
                m_set.insert({dista[e],  e} );
          }
        }
    }

    //std::string shortest_path = ""+std::to_string(dista[0]);
    // for (int i = 0; i < SIZE; ++i)
    // {
    //   new_dists(src_node,i) = dista[i];
    //   //shortest_path = shortest_path + " " + std::to_string(dista[i]);
    // }
    // //shortest_path = shortest_path + "\n";
    // is_visit[src_node] = true;
    // return "";

    return false;
}

std::string Solver::dijkstra(int src_node){
    if (is_visit[src_node]){
      return " ";
    }

    int SIZE = G->getNodesNum();

    int dista [SIZE];
    bool vis [SIZE];
    std::memset(vis, false , sizeof vis);
    std::memset(dista,10000,sizeof dista);
    dista[src_node] = 0;
    std::multiset < std::pair < int , int > > s;

    s.insert({0 , src_node});
    int cnt = 0;
    while(!s.empty()){
        cnt++;
        std::pair <int , int> p = *s.begin();
        s.erase(s.begin());

        int x = p.second; int wei = p.first;
        if( vis[x] ) continue;
        vis[x] = true;
        Nodes neighbor;
        neighbor = G->neighbor(G->getNodeFromIndex(x));
        for (auto v : neighbor) {
          int e = v->getIndex();
          int w = 1;
          if(dista[x] + w < dista[e]  ){
                dista[e] = dista[x] + w;
                s.insert({dista[e],  e} );
          }
        }
    }

    //std::string shortest_path = ""+std::to_string(dista[0]);
    for (int i = 0; i < SIZE; ++i)
    {
      new_dists(src_node,i) = dista[i];
      //shortest_path = shortest_path + " " + std::to_string(dista[i]);
    }
    //shortest_path = shortest_path + "\n";
    is_visit[src_node] = true;
    return "";
}

void Solver::collectCost(int src_node){
  std::string flieName = directory_name+"node_"+std::to_string(src_node);
  // std::cout<<"collectCost e file name : "<<flieName<<"\n";
  // std::vector<std::vector<std::string> > dataList;
  CSVReader reader(flieName);
//     // Get the data from CSV File
  dataList = reader.getData();
  int nodeNum = G->getNodesNum();
  // std::cout<<"dataList size : "<<dataList.size()<<"\n";
  // std::cout<<"dataList er vitore size : "<<dataList[0].size()<<"\n";
  shortest_path_cost[src_node] = dataList[0];
}