text:
//=========================================================================
//  Copyright (c) Kitware, Inc.
//  All rights reserved.
//  See LICENSE.txt for details.
//
//  This software is distributed WITHOUT ANY WARRANTY; without even
//  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
//  PURPOSE.  See the above copyright notice for more information.
//=========================================================================

#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/Definition.h"
#include "smtk/attribute/FileItem.h"
#include "smtk/attribute/IntItem.h"
#include "smtk/attribute/PythonRule.h"
#include "smtk/attribute/Resource.h"
#include "smtk/attribute/ResourceItem.h"
#include "smtk/attribute/StringItem.h"
#include "smtk/attribute/StringItemDefinition.h"
#include "smtk/attribute/json/jsonResource.h"
#include "smtk/attribute/operators/Read.h"
#include "smtk/attribute/operators/Write.h"
#include "smtk/common/UUID.h"
#include "smtk/io/AttributeReader.h"
#include "smtk/io/AttributeWriter.h"
#include "smtk/io/Logger.h"
#include "smtk/mesh/core/Resource.h"
#include "smtk/mesh/utility/Create.h"

//force to use filesystem version 3
#define BOOST_FILESYSTEM_VERSION 3
#include <boost/filesystem.hpp>
using namespace boost::filesystem;

#include <algorithm>
#include <fstream>
#include <iostream>

namespace
{
std::string write_root = SMTK_SCRATCH_DIR;

void cleanup(const std::string& file_path)
{
  //first verify the file exists
  ::boost::filesystem::path path(file_path);
  if (::boost::filesystem::is_regular_file(path))
  {
    //remove the file_path if it exists.
    ::boost::filesystem::remove(path);
  }
}

int testAssociationRule(const smtk::attribute::AttributePtr& attribute)
{
  // Test if the attribute instance with a custom association rule can be
  // associated with itself (it should not).
  if (attribute->canBeAssociated(attribute))
  {
    std::cerr << "Custom Python rule should reject attribute components\n";
    std::cerr << smtk::io::Logger::instance().convertToString();
    return -2;
  }

  // Test if the attribute instance with a custom association rule can be
  // associated with a mesh component (it should).
  {
    // Create a new mesh mesh resource
    smtk::mesh::ResourcePtr meshResource = smtk::mesh::Resource::create();

    // Construct a uniform grid
    std::array<std::size_t, 3> discretization = { { 2, 2, 2 } };
    std::function<std::array<double, 3>(std::array<double, 3>)> transform =
      [](std::array<double, 3> x) { return x; };
    auto meshes = smtk::mesh::utility::createUniformGrid(meshResource, discretization, transform);
    auto meshComponent = smtk::mesh::Component::create(meshes[0]);

    // Test whether the attribute resource can be associated to the newly
    // created mesh component.
    if (!attribute->canBeAssociated(meshComponent))
    {
      std::cerr << "Custom Python rule should accept mesh components\n";
      std::cerr << smtk::io::Logger::instance().convertToString();
      return -2;
    }
  }

  return 0;
}

const char* testPy = R"python(
import smtk.mesh

def mySpecialAssociationRule(object, attribute):
    meshComponent = smtk.mesh.Component.CastTo(object)
    return meshComponent != None
)python";

const char* testInput = R"xml(
<?xml version="1.0" encoding="utf-8" ?>
<SMTK_AttributeResource Version="4">
  <Definitions>
    <AttDef Type="att1" BaseType="">
      <AssociationRule Name="myPythonRule"/>
      <ItemDefinitions>
        <String Name="normalString" Extensible="0"
               NumberOfRequiredValues="1">
         <DefaultValue>normal</DefaultValue>
        </String>
      </ItemDefinitions>
    </AttDef>
  </Definitions>
  <AssociationRules>
    <PythonRule Name="myPythonRule">
      <SourceFiles>
        <SourceFile>myPythonSource.py</SourceFile>
      </SourceFiles>
      <![CDATA[
def canBeAssociated(attribute, object):
    import myPythonSource
    return myPythonSource.mySpecialAssociationRule(object, attribute)
      ]]>
    </PythonRule>
  </AssociationRules>
  <Attributes>
    <Att Name="att" Type="att1"/>
  </Attributes>
</SMTK_AttributeResource>)xml";
} // namespace

int unitAssociationRulesTest(int argc, char* argv[])
{
  (void)argc;
  (void)argv;

  // Construct an attribute resource from the test input, test its association
  // properties, and write it to disk.
  std::string pyFileName;
  std::string sbiFileName;
  std::string smtkFileName;
  {
    {
      pyFileName = write_root + "/myPythonSource.py";
      std::ofstream outfile(pyFileName.c_str(), std::ios::out);
      outfile << testPy;
      outfile.close();
    }

    // Construct a new attribute resource
    smtk::attribute::ResourcePtr resource = smtk::attribute::Resource::create();

    // Associate the smtk::attribute::PythonRule association type to it, and give
    // it the alias "PythonRule".
    resource->associationRules()
      .associationRuleFactory()
      .registerType<smtk::attribute::PythonRule>();
    resource->associationRules().associationRuleFactory().addAlias<smtk::attribute::PythonRule>(
      "PythonRule");

    // Read the input xml to construct an attribute instance.
    smtk::io::Logger logger;
    smtk::io::AttributeReader reader;
    std::string input = testInput;
    input.replace(input.find("myPythonSource.py"), 17, pyFileName);
    if (reader.readContents(resource, input, logger))
    {
      std::cerr << "Encountered Errors while reading input data\n";
      std::cerr << logger.convertToString();
      return -2;
    }

    // Access the newly created attribute instance.
    std::vector<smtk::attribute::AttributePtr> atts;
    resource->attributes(atts);
    if (atts.size() != 1)
    {
      std::cerr << "Unexpected number of attributes: " << atts.size() << "\n";
      std::cerr << logger.convertToString();
      return -2;
    }
    smtk::attribute::AttributePtr att = atts[0];

    // Test the custom association rule.
    int testValue = testAssociationRule(att);
    if (testValue)
    {
      return testValue;
    }

    // Write the resource out to a .sbi file
    {
      sbiFileName = write_root + "/" + smtk::common::UUID::random().toString() + ".sbi";

      smtk::io::AttributeWriter writer;
      if (writer.write(resource, sbiFileName, logger))
      {
        std::cerr << "Encountered Errors while writing output data\n";
        std::cerr << logger.convertToString();
        return -2;
      }
    }

    // Write the resource out to a .smtk file
    {
      smtkFileName = write_root + "/" + smtk::common::UUID::random().toString() + ".json";
      resource->setLocation(smtkFileName);

      smtk::attribute::Write::Ptr writeOp = smtk::attribute::Write::create();
      writeOp->parameters()->associate(resource);
      auto result = writeOp->operate();

      if (
        result->findInt("outcome")->value() !=
        static_cast<int>(smtk::operation::Operation::Outcome::SUCCEEDED))
      {
        std::cerr << "Write operation failed\n";
        std::cerr << writeOp->log().convertToString();
        return -2;
      }
    }
  }

  {
    // Read the .sbi file into a new resource
    smtk::attribute::Resource::Ptr resource = smtk::attribute::Resource::create();
    resource->associationRules()
      .associationRuleFactory()
      .registerType<smtk::attribute::PythonRule>();
    resource->associationRules().associationRuleFactory().addAlias<smtk::attribute::PythonRule>(
      "PythonRule");

    smtk::io::AttributeReader reader;

    std::ifstream file(smtkFileName);
    nlohmann::json j = nlohmann::json::parse(file);
    smtk::attribute::from_json(j, resource);
    resource->setLocation(smtkFileName);

    std::vector<smtk::attribute::AttributePtr> atts;
    resource->attributes(atts);
    if (atts.size() != 1)
    {
      std::cerr << "Unexpected number of attributes: " << atts.size() << "\n";
      return -2;
    }
    smtk::attribute::AttributePtr att = atts[0];

    // Test the custom association rule.
    int testValue = testAssociationRule(att);
    if (testValue)
    {
      return testValue;
    }
  }

  {
    // Read the .smtk file into a new resource
    smtk::attribute::Resource::Ptr resource = smtk::attribute::Resource::create();
    resource->associationRules()
      .associationRuleFactory()
      .registerType<smtk::attribute::PythonRule>();
    resource->associationRules().associationRuleFactory().addAlias<smtk::attribute::PythonRule>(
      "PythonRule");

    // Read the generated sbi file to construct an attribute instance.
    smtk::io::Logger logger;
    smtk::io::AttributeReader reader;
    if (reader.read(resource, sbiFileName, logger))
    {
      std::cerr << "Encountered Errors while reading input data\n";
      std::cerr << logger.convertToString();
      return -2;
    }

    // Access the newly created attribute instance.
    std::vector<smtk::attribute::AttributePtr> atts;
    resource->attributes(atts);
    if (atts.size() != 1)
    {
      std::cerr << "Unexpected number of attributes: " << atts.size() << "\n";
      std::cerr << logger.convertToString();
      return -2;
    }
    smtk::attribute::AttributePtr att = atts[0];

    // Test the custom association rule.
    int testValue = testAssociationRule(att);
    if (testValue)
    {
      return testValue;
    }
  }

  cleanup(smtkFileName);
  cleanup(sbiFileName);
  cleanup(pyFileName);

  return 0;
}

ext: cxx

max_stars_repo_name: jcfr/SMTK

max_issues_repo_name: jcfr/SMTK

max_forks_repo_name: jcfr/SMTK


text:
#include "stdafx.h"

#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>

ext: cpp

max_stars_repo_name: boost-gil/gil-contributions

max_issues_repo_name: boost-gil/gil-contributions-archive

max_forks_repo_name: boost-gil/gil-contributions-archive


text: #include <boost/metaparse/v1/get_prev_char.hpp>

ext: hpp

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino


text:
//
// Created by yiak on 2020/7/22.
//

#include <gflags/gflags.h>

#include <memory>
#include <string>
#include <unordered_map>
using std::pair;
using std::unordered_map;
#include <vector>
using std::vector;
// if is linux system
#include <sys/time.h>

#include <algorithm>
#include <chrono>
#include <ctime>
#include <iomanip>
#include <stdlib.h>
#include <sstream>

// == Boost Utilities

// filesystem
#include <boost/filesystem.hpp>

// string and STL algorithms
#include <boost/algorithm/string.hpp>
#include <boost/optional.hpp>

// logging utilities
#include <glog/logging.h>
#include "base/logging.h"

#include <iostream>

// TensorFlow Inference Engine
#include "engine.h"
#include "env_config.h"

// SFE
#include "sfe.h"

#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>

#include "base/parallel_tasking_sched/task.h"
#include "base/io/sensors/img.h"

using namespace svso::system;
using namespace svso::models;
using namespace svso::base::logging;
using namespace svso::base::pts;
using namespace svso::base::io;

// Parsing comandline inputs
DEFINE_string(image_name, format(
        "%s/tum/rgbd_dataset_freiburg1_xyz/rgb/1305031102.175304.png", env_config::DATA_DIR.c_str()
),
        "image name");
DEFINE_string(model_dir, format(
        "%s/models/coco", env_config::DATA_DIR.c_str()
),
              "The path of saved model graph definition");

void Parse_args(int argc, char* argv[]) {
    gflags::ParseCommandLineFlags(&argc, &argv, true);
}

using tfe = TensorFlowEngine;
namespace tf = tensorflow;

int main(int argc, const char** argv) {
    Parse_args(argc, (char**)argv);
    Init_GLog(argc, argv);

    ThreadPool pool(3);

    // read img, note cv::imread is too slow when you are digesting a bunch of images (> 1TB)
    /* cv::Mat img = cv::imread(FLAGS_image_name, cv::IMREAD_COLOR); */
    Task<std::function<cv::Mat()>>::Ptr read_img(
            new Task<std::function<cv::Mat()>>( [&] {
                reader::RawImageConstPtr raw_image_data = reader::open_with_mmap(FLAGS_image_name); // read the large block of data using mmap, it will take few milli seconds to build mapping
                reader::Img img;
                img.set_data(raw_image_data->data());
                cv::Mat ret = img.mat<int>();
                return ret;
            } )
            );

    auto read_img_fut = read_img->get_future();
    // execute the task and do something else immediately
    pool.enqueue([&] {
        (*read_img)();
    });

    TF_MRCNN_SemanticFeatureExtractor::Ptr sfe(new TF_MRCNN_SemanticFeatureExtractor);

    // wait for the image is ready
    read_img_fut.wait();
    cv::Mat img = std::move( read_img_fut.get() );

    if (img.empty()) {
        LOG(FATAL) << format("could not read the image %s", FLAGS_image_name.c_str());
    }

    tfe::InputTensors inputs;
    tfe::OutputTensors outputs;
    std::vector<TF_MRCNN_SemanticFeatureExtractor::DetectronResult> results;

    // infer !
    tfe::FutureType fut = sfe->detect(img, &inputs, &outputs, results);

    // do something else

    // fetch result
    fut.wait();

    tf::Status status = fut.get();
    if (status.ok()) {
        LOG(INFO) << format("%d objects detected.", results[0].rois.rows());
    }
    return 0;
}


text:
#pragma once
//=====================================================================//
/*! @file
	@brief  BMC コア関係
	@author 平松邦仁 (hira@rvf-rc45.net)
*/
//=====================================================================//
#include <bitset>
#include <boost/format.hpp>
#include "utils/string_utils.hpp"
#include "utils/bit_array.hpp"
#include "img_io/img_files.hpp"
#include "img_io/img_utils.hpp"
#include "img_io/img_rgba8.hpp"
#include "img_io/bdf_io.hpp"
#include "utils/arith.hpp"
#include "utils/format.hpp"

#include "script_img.hpp"

namespace app {

	//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
	/*!
		@brief  BMC コア・クラス
	*/
	//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
	class bmc_core {
	public:

		struct option {
			enum type {
				preview,	///< プレビューを有効
				verbose,	///< 詳細なメッセージ出力
				header,		///< サイズヘッダー出力
				text,		///< テキストベース出力
				c_style,	///< C スタイルのテキスト出力
				offset,		///< オフセット
				size,		///< サイズ
				bdf,		///< BDF ファイル入力
				append,		///< 追加出力
				inverse,	///< 画像反転
				dither,		///< ディザリング
				compress4,	///< RLE4 圧縮フォーマット
				script,		///< 描画スクリプトファイル

				limit_
			};
		};

	private:
		static const uint32_t bdf_prev_x_ = 32;
		static const uint32_t bdf_prev_y_ = 32;

		std::bitset<option::limit_>	option_;
		std::string	inp_fname_;
		std::string out_fname_;
		uint32_t	header_size_;
		std::string	symbol_;
		vtx::srect	clip_;

		float		version_;

		img::img_rgba8	src_img_;
		img::img_rgba8	dst_img_;

		utils::bit_array	bits_;

		uint32_t		bdf_num_;
		uint32_t		bdf_pages_;
		vtx::spos		bdf_fsize_;

		void bitmap_convert_()
		{
			if(src_img_.empty()) return;

			if(option_[option::header] && header_size_) {
				bits_.put_bits(src_img_.get_size().x, header_size_);
				bits_.put_bits(src_img_.get_size().y, header_size_);
			}

			dst_img_.create(src_img_.get_size(), true);

			if(option_[option::dither]) {
				struct float_img {
					std::vector<float>	img_;
					vtx::spos	size_;

					bool clip_(const vtx::spos& p) const {
						if(static_cast<uint16_t>(p.x) >= static_cast<uint16_t>(size_.x)) {
							return false;
						}
						if(static_cast<uint16_t>(p.y) >= static_cast<uint16_t>(size_.y)) {
							return false;
						}
						return true;
					}

					void create(const vtx::spos& size) {
						size_ = size; img_.resize(size_.x * size_.y);
					}

					void put(const vtx::spos& pos, float v) {
						if(clip_(pos)) img_[pos.y * size_.x + pos.x] = v;
					}

					void add(const vtx::spos& pos, float v) {
						if(clip_(pos)) img_[pos.y * size_.x + pos.x] += v;
					}

					float get(const vtx::spos& pos) const {
						if(clip_(pos)) return img_[pos.y * size_.x + pos.x];
						else return 0.0f;
					}
				} gray;

				gray.create(src_img_.get_size());
				// Ditherring weight:
				// (Floyd-Steinberg)
				//       curr, 7/16
				// 3/16, 5/16, 1/16
				vtx::spos pos;
				for(pos.y = 0; pos.y < src_img_.get_size().y; ++pos.y) {
					for(pos.x = 0; pos.x < src_img_.get_size().x; ++pos.x) {
						img::rgba8 c;
						src_img_.get_pixel(pos, c);
						gray.put(pos, static_cast<float>(c.getY()));
					}
				}
				for(pos.y = 0; pos.y < src_img_.get_size().y; ++pos.y) {
					for(pos.x = 0; pos.x < src_img_.get_size().x; ++pos.x) {
						float g = gray.get(pos);
						bool f = false;
						float e;
						if(g > 127.0f) {
							gray.put(pos, 255.0f);
							e = g - 255.0f;
							f = true;
						} else {
							gray.put(pos, 0.0f);
							e = g;
						}
						gray.add(vtx::spos(pos.x + 1, pos.y + 0), e * (7.0f/16.0f));
						gray.add(vtx::spos(pos.x - 1, pos.y + 1), e * (3.0f/16.0f));
						gray.add(vtx::spos(pos.x + 0, pos.y + 1), e * (5.0f/16.0f));
						gray.add(vtx::spos(pos.x + 1, pos.y + 1), e * (1.0f/16.0f));

						if(option_[option::inverse]) f = !f;
						bits_.put_bit(f);
						img::rgba8 c;
						if(f) c.set(255, 255, 255, 255);
						else c.set(0, 0, 0, 255);
						dst_img_.put_pixel(pos, c);
					}
				}
			} else {
				vtx::spos pos;
				for(pos.y = 0; pos.y < src_img_.get_size().y; ++pos.y) {
					for(pos.x = 0; pos.x < src_img_.get_size().x; ++pos.x) {
						img::rgba8 c;
						src_img_.get_pixel(pos, c);
						bool f = (c.getY() >= 128);
						if(option_[option::inverse]) f = !f;
						bits_.put_bit(f);
						if(f) c.set(255, 255, 255, 255);
						else c.set(0, 0, 0, 255);
						dst_img_.put_pixel(pos, c);
					}
				}
			}
		}

		void bitmap_convert_(img::bdf_io& bdf)
		{
			if(option_[option::header]) {
				bits_.put_bits(bdf.get_width(), header_size_);
				bits_.put_bits(bdf.get_height(), header_size_);
			}

			// sjis に並んだものをそのまま出力
			for(uint32_t i = 0; i < bdf.size(); ++i) {
				bits_.put_bits(bdf.get_byte(i), 8);
			}

			// 最大ページ数を求めておく
			bdf_num_ = bdf.size() / bdf.byte_size();	// 全フォント数
			bdf_pages_ = bdf_num_ / (bdf_prev_x_ * bdf_prev_y_);
			if(bdf_num_ % (bdf_prev_x_ * bdf_prev_y_)) ++bdf_pages_;

			bdf_fsize_.set(bdf.get_width(), bdf.get_height());

			create_bdf_image(0);
		}

		uint32_t save_file_()
		{
			if(out_fname_.empty()) {
				return 0;
			}

			std::string mode;
			if(option_[option::append]) mode = "ab";
			else mode = "wb";

			utils::file_io fio;
			if(!fio.open(out_fname_, mode)) {
				std::cerr << "Can't write open file: '" << out_fname_ << "'" << std::endl;
				return 0;
			}

			uint32_t n = 0;
			if(option_[option::text]) {
				utils::strings ss = utils::split_text(symbol_, ",");
				std::string label;
				if(option_[option::c_style]) {
					if(ss.size() == 1) {
						label = "static const uint8_t " + ss[0] + "[] = {\n";
					} else if(ss.size() == 2) {
						label = "static const uint8_t " + ss[0] + "[] " + ss[1] + " = {\n";
					}
					fio.put(label);
				}
				for(uint32_t i = 0; i < bits_.byte_size(); ++i) {
					if((i % 16) == 0) {
						fio.put("    ");
					}
					fio.put(
						(boost::format("0x%02x") % static_cast<uint32_t>(bits_.get_byte(i))).str()
					);
					fio.put(",");
					if((i % 16) == 15) {
						fio.put("\n");
					}
				}
				if(option_[option::c_style]) {
					fio.put(" };");
				}
				fio.put("\n");
				n = fio.tell();
			} else {
				n = bits_.save_file(fio);
			}
			fio.close();
			return n;
		}

		static bool scan_pos_(const std::string& str, vtx::spos& pos)
		{
			utils::strings ss = utils::split_text(str, ",");
			if(ss.size() == 2) {
				for(int i = 0; i < 2; ++i) {
					utils::arith a;
 					if(!a.analize(ss[i])) {
						return false;
					}
					if(i == 0) pos.x = a.get_integer();
					else pos.y = a.get_integer();
				}
			} else {
				return false;
			}
			return true;
		}

	public:
		//-----------------------------------------------------------------//
		/*!
			@brief  コンストラクター
		*/
		//-----------------------------------------------------------------//
		bmc_core() :
			header_size_(0), clip_(0),
			version_(0.90f), bdf_num_(0), bdf_pages_(0), bdf_fsize_(0) { }

		//-----------------------------------------------------------------//
		/*!
			@brief  help 表示
			@param[in]	cmd	コマンド文字列
		*/
		//-----------------------------------------------------------------//
		void help(const char* cmd) const
		{
			using namespace std;

			utils::format("BitMap Converter\n");
			utils::format("Copyright (C) 2013/2020, Hiramatsu Kunihito\n");
			utils::format("Version %3.2f\n") % version_;
			utils::format("usage:\n");
			auto c = utils::get_file_base(cmd);
			cout << "    " << c << " [options] in-file [out-file]" << endl;
			cout << "    -preview,-pre     preview image (OpenGL)" << endl;
			cout << "    -header bits      output width,height" << endl;
			cout << "    -text             text base output" << endl;
			cout << "    -c_style symbol   C style table output" << endl;
			cout << "    -offset x,y       offset location" << endl;
			cout << "    -size x,y         clipping size" << endl;
			cout << "    -bdf              BDF file input" << endl;
			cout << "    -append           append file" << endl;
			cout << "    -inverse          inverse mono color" << endl;
			cout << "    -dither           ditherring" << endl;
			cout << "    -compress4        RLE4 compress" << endl;
			cout << "    -script           render SCRIPT file input" << endl;
			cout << "    -verbose          verbose" << endl;
			cout << endl;
		}

		//-----------------------------------------------------------------//
		/*!
			@brief  コマンドライン解析
			@return エラーが無ければ「true」
		*/
		//-----------------------------------------------------------------//
		bool analize(int argc, char** argv)
		{
			using namespace std;

			bool no_err = true;
			bool header = false;
			bool symbol = false;
			bool offset = false;
			bool size = false;
			for(int i = 1; i < argc; ++i) {
				string s = argv[i];
				if(s[0] == '-') {
					if(s == "-preview") option_.set(option::preview);
					else if(s == "-pre") option_.set(option::preview);
					else if(s == "-verbose") option_.set(option::verbose);
					else if(s == "-header") { option_.set(option::header); header = true; }
					else if(s == "-text") option_.set(option::text);
					else if(s == "-c_style") { option_.set(option::c_style); symbol = true; }
					else if(s == "-offset") { option_.set(option::offset); offset = true; }
					else if(s == "-size") { option_.set(option::size); size = true; }
					else if(s == "-bdf") option_.set(option::bdf);
					else if(s == "-append") option_.set(option::append);
					else if(s == "-inverse") option_.set(option::inverse);
					else if(s == "-dither") option_.set(option::dither);
					else if(s == "-compress4") option_.set(option::compress4);
					else if(s == "-script") option_.set(option::script);
					else {
						no_err = false;
						cerr << "Option error: '" << s << "'" << endl;
					}
				} else {
					if(header) {
						utils::arith a;
 						if(!a.analize(s)) {
							cerr << "Option header error: '" << s << "'" << endl;
							return false;
						}
						header_size_ = a.get_integer();
						header = false;
					} else if(offset) {
						if(!scan_pos_(s, clip_.org)) {
							cerr << "Option offset error: '" << s << "'" << endl;
						}
						offset = false;
					} else if(size) {
						if(!scan_pos_(s, clip_.size)) {
							cerr << "Option size error: '" << s << "'" << endl;
						}
						size = false;
					} else if(symbol) {
						symbol_ = s;
						symbol = false;
					} else {
						inp_fname_ = out_fname_;
						out_fname_ = s;
					}
				}
			}

			if(inp_fname_.empty()) {
				inp_fname_ = out_fname_;
				out_fname_.clear();
			}

			if(!no_err) {
				cerr << endl;
			}
			return no_err;
		}

		//-----------------------------------------------------------------//
		/*!
			@brief  実行
			@return エラーが無ければ「true」
		*/
		//-----------------------------------------------------------------//
		bool execute()
		{
			using namespace std;

			if(option_[option::verbose]) {
				cout << "Input File:  '" << inp_fname_ << "'" << endl;
				cout << "Output File: '" << out_fname_ << "'" << endl;
			}

			if(inp_fname_.empty()) {
				cerr << "Input file empty..." << endl;
				return false;
			}

			if(option_[option::bdf]) { // BDF ファイルの場合
				img::bdf_io bdf;

				bdf.initialize();

				if(!bdf.load(inp_fname_)) {
					cerr << "Can't decode BDF file: '" << inp_fname_ << "'" << endl;
					return false;
				}

				bitmap_convert_(bdf);

			} else if(option_[option::script]) { // スクリプト・ファイルの場合
				script::image simg;

				if(!simg.open(inp_fname_)) {
					cerr << "Can't decode SCRIPT file: '" << inp_fname_ << "'" << endl;
					return false;
				}

				simg.create();

				if(!simg.save(out_fname_)) {
					cerr << "Can't save SCRIPT/output file: '" << out_fname_ << "'" << endl;
					return false;
				}

				return true;

			} else { // 通常の画像ファイル
				img::img_files	imfs;

				if(!imfs.load(inp_fname_)) {
					cerr << "Can't load source image: " << inp_fname_ << "'" << endl;
					return false;
				}

				// ソース画像をコピー
				vtx::srect sr(vtx::spos(0), imfs.get_image()->get_size());
				if(option_[option::offset]) {
					sr.org = clip_.org;
				}
				if(option_[option::size]) {
					sr.size = clip_.size;
				}
				src_img_.create(sr.size, true);
				img::copy_to_rgba8(imfs.get_image().get(), sr, src_img_, vtx::spos(0));

				// モノクロ変換
				bitmap_convert_();
			}

			// ファイル出力
			uint32_t n = save_file_();

			if(option_[option::verbose]) {
				cout << "Source image size: " << src_img_.get_size().x << ", "
					<< src_img_.get_size().y << endl;
				if(option_[option::header]) {
					cout << "Output size header: " << header_size_ << endl;
				}
				if(option_[option::text]) {
					cout << "Text base output" << endl;
				}
				if(option_[option::c_style]) {
					cout << "C-Style output symbol: '" << symbol_ << "'" << endl;
				}
				if(option_[option::offset]) {
					cout << "Offset: " << static_cast<int>(clip_.org.x) << " ,"
						<< static_cast<int>(clip_.org.y) << endl;
				}
				if(option_[option::size]) {
					cout << "Size: " << static_cast<int>(clip_.size.x) << " ,"
						<< static_cast<int>(clip_.size.y) << endl;
				}
				if(option_[option::bdf]) {
					cout << "BDF file input" << endl;
					cout << "BDF font size: " << static_cast<int>(bdf_fsize_.x)
						<< ", " << static_cast<int>(bdf_fsize_.y) << endl;
					cout << "BDF font num: " << bdf_num_ << endl;
				}
				if(option_[option::append]) {
					cout << "Append file" << endl;
				}
				if(option_[option::dither]) {
					cout << "Ditherring" << endl;
				}
				cout << "Output size: " << n << " bytes" << endl;
			}

			return true;
		}

		//-----------------------------------------------------------------//
		/*!
			@brief  オプションの取得
			@param[in]	t	オプション・タイプ
			@return 状態
		*/
		//-----------------------------------------------------------------//
		bool get_option(option::type t) const { return option_[t]; }

		//-----------------------------------------------------------------//
		/*!
			@brief  入力ファイルの取得
			@return 入力ファイル名
		*/
		//-----------------------------------------------------------------//
		const std::string& get_inp_file() const { return inp_fname_; }

		//-----------------------------------------------------------------//
		/*!
			@brief  出力ファイルの取得
			@return 出力ファイル名
		*/
		//-----------------------------------------------------------------//
		const std::string& get_out_file() const { return out_fname_; }

		//-----------------------------------------------------------------//
		/*!
			@brief  ソース画像の参照を取得
			@return ソース画像の参照
		*/
		//-----------------------------------------------------------------//
		const img::img_rgba8& get_src_image() const { return src_img_; }

		//-----------------------------------------------------------------//
		/*!
			@brief  ソース画像の参照を取得
			@return ソース画像の参照
		*/
		//-----------------------------------------------------------------//
		const img::img_rgba8& get_dst_image() const { return dst_img_; }

		//-----------------------------------------------------------------//
		/*!
			@brief  BDF の画像のページ数を取得
			@return 最大ページ数
		*/
		//-----------------------------------------------------------------//
		uint32_t get_bdf_pages() const { return bdf_pages_; }

		//-----------------------------------------------------------------//
		/*!
			@brief  BDF の画像を生成
			@param[in]	page	ページ
		*/
		//-----------------------------------------------------------------//
		void create_bdf_image(uint32_t page)
		{
			if(page >= bdf_pages_) {
				return;
			}

			uint32_t ofs = 0;
			// ヘッダーの分を seek
			if(option_[option::header]) {
				ofs = header_size_ * 2;
			}

			uint32_t fb = (((bdf_fsize_.x * bdf_fsize_.y) + 7) >> 3) << 3;
			ofs += bdf_prev_x_ * bdf_prev_y_ * page * fb;
			bits_.set_pos(ofs); // seek

			vtx::spos ssz(bdf_fsize_.x * bdf_prev_x_, bdf_fsize_.y * bdf_prev_y_);
			dst_img_.create(ssz, true);
			for(uint32_t y = 0; y < ssz.y; y += bdf_fsize_.y) {
				for(uint32_t x = 0; x < ssz.x; x += bdf_fsize_.x) {
					for(uint32_t j = 0; j < bdf_fsize_.y; ++j) {
						for(uint32_t i = 0; i < bdf_fsize_.x; ++i) {
							bool f = bits_.get_bit();
							img::rgba8 c;
							if(f) c.set(255, 255, 255, 255);
							else c.set(0, 0, 0, 255);
							dst_img_.put_pixel(vtx::spos(x + i, y + j), c);
						}
					}
				}
			}
		}
	};
}


text:
#include <iostream>
#include <boost/test/unit_test.hpp>

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>

namespace pt = boost::property_tree;

#include "config_reader.h"

BOOST_AUTO_TEST_CASE(configuration_can_be_empty_object) {
  std::stringstream input("{}");

  jak::AppConfig config = jak::config::reader::read(input);

  BOOST_CHECK_EQUAL(config.has_sources(), false);
}

BOOST_AUTO_TEST_CASE(configuration_can_contain_single_source) {
  std::stringstream input("{\"sources\": [{\"source\": \"github\", \"token\": \"atoken\"}]}");

  jak::AppConfig config = jak::config::reader::read(input);

  BOOST_CHECK_EQUAL(config.has_sources(), true);
  bool called = false;

  auto handler = [&](jak::source src) {
      BOOST_CHECK_EQUAL(src.source_system, "github");
      BOOST_CHECK_EQUAL(src.token, "atoken");
      called = true;
  };

  config.each_source(handler);

  BOOST_CHECK(called);
}

max_stars_repo_name: grahambrooks/jak

max_issues_repo_name: grahambrooks/jak

max_forks_repo_name: grahambrooks/jak


text:
#ifndef GAME_CORE_WORLD_ENTITY_TYPES_HPP
#define GAME_CORE_WORLD_ENTITY_TYPES_HPP

#include <type_traits>

#include <boost/hana/first.hpp>
#include <boost/hana/pair.hpp>
#include <boost/hana/second.hpp>
#include <boost/hana/size.hpp>
#include <boost/hana/tuple.hpp>
#include <boost/hana/type.hpp>

#include "world/entity/Ball.hpp"
#include "world/entity/EntityId.hpp"
#include "world/entity/Player.hpp"
#include "world/entity/Wall.hpp"

#include "util/EnumCast.hpp"

namespace hana = boost::hana;

namespace World {
namespace Entity {

#define MAKE_ENTITY_PAIR(Identifier, Type) hana::make_pair(hana::int_c<enum_cast(Identifier)>, hana::type_c<Type>)

#define GAME_CORE_ENTITY_COUNT 3
constexpr auto entityIdentifierMap =                 //
  hana::make_tuple(MAKE_ENTITY_PAIR(Id::Wall, Wall), //
                   MAKE_ENTITY_PAIR(Id::Ball, Ball), //
                   MAKE_ENTITY_PAIR(Id::Player, Player));

static_assert(decltype(hana::size(entityIdentifierMap))::value == GAME_CORE_ENTITY_COUNT,
              "Map size must be equal to the entity count.");

template <size_t i>
constexpr auto
  id = static_cast<Id>(std::decay<decltype(hana::first(entityIdentifierMap[hana::int_c<i>]))>::type::value);

template <size_t i>
using Type = typename std::decay<decltype(hana::second(entityIdentifierMap[hana::int_c<i>]))>::type::type;

} /* namespace Entity */
} /* namespace World */

#endif


text:
/*
 * Copyright (C) 2012-2015 Open Source Robotics Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
*/
#ifdef _WIN32
  #include <Windows.h>
#endif

#include <cstdlib>

#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>

#include <gazebo/gazebo_config.h>
#include <gazebo/common/ffmpeg_inc.h>

#include "gazebo/common/CommonIface.hh"
#include "gazebo/common/Exception.hh"
#include "gazebo/common/SystemPaths.hh"

using namespace gazebo;

/////////////////////////////////////////////////
void common::load()
{
#ifdef HAVE_FFMPEG
  static bool first = true;
  if (first)
  {
    first = false;
    avcodec_register_all();
    av_register_all();
  }
#endif
}

/////////////////////////////////////////////////
void common::add_search_path_suffix(const std::string &_suffix)
{
  common::SystemPaths::Instance()->AddSearchPathSuffix(_suffix);
}

/////////////////////////////////////////////////
std::string common::find_file(const std::string &_file)
{
  return common::SystemPaths::Instance()->FindFile(_file, true);
}

/////////////////////////////////////////////////
std::string common::find_file(const std::string &_file, bool _searchLocalPath)
{
  return common::SystemPaths::Instance()->FindFile(_file, _searchLocalPath);
}

/////////////////////////////////////////////////
std::string common::find_file_path(const std::string &_file)
{
  std::string filepath = common::find_file(_file);

  boost::filesystem::path path(filepath);
  if (boost::filesystem::is_directory(path))
  {
    return filepath;
  }
  else
  {
    int index = filepath.find_last_of("/");
    return filepath.substr(0, index);
  }
}

/////////////////////////////////////////////////
const char *common::getEnv(const char *_name)
{
#ifdef _WIN32
  const DWORD buffSize = 65535;
  static char buffer[buffSize];
  if (GetEnvironmentVariable(_name, buffer, buffSize))
    return buffer;
  else
    return NULL;
#else
  return getenv(_name);
#endif
}

ext: cc

max_stars_repo_name: harderthan/gazebo

max_issues_repo_name: harderthan/gazebo

max_forks_repo_name: harderthan/gazebo


text:
/*
Copyright 2020 Glen Joseph Fernandes
(glenjofe@gmail.com)

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

#ifndef BOOST_TT_DISJUNCTION_HPP_INCLUDED
#define BOOST_TT_DISJUNCTION_HPP_INCLUDED

#include <boost/type_traits/conditional.hpp>
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#include <boost/type_traits/integral_constant.hpp>
#endif

namespace boost {

#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template<class...>
struct disjunction
    : false_type { };

template<class T>
struct disjunction<T>
    : T { };

template<class T, class... U>
struct disjunction<T, U...>
    : conditional<bool(T::value), T, disjunction<U...> >::type { };
#else
template<class T, class U>
struct disjunction
    : conditional<bool(T::value), T, U>::type { };
#endif

} /* boost */

#endif

max_stars_repo_name: kindlychung/mediasoup-sfu-cpp

max_issues_repo_name: kindlychung/mediasoup-sfu-cpp

max_forks_repo_name: kindlychung/mediasoup-sfu-cpp


text:
#include <boost/test/unit_test.hpp>

#include <scorum/chain/services/withdraw_scorumpower.hpp>
#include <scorum/chain/services/dev_pool.hpp>

#include <scorum/chain/evaluators/withdraw_scorumpower_evaluator.hpp>

#include <scorum/chain/schema/withdraw_scorumpower_objects.hpp>
#include <scorum/chain/schema/dev_committee_object.hpp>

#include "withdraw_scorumpower_check_common.hpp"

using namespace database_fixture;

BOOST_AUTO_TEST_SUITE(withdraw_scorumpower_route_from_dev_pool_to_dev_pool_tests)

struct withdraw_scorumpower_route_from_dev_pool_to_dev_pool_tests_fixture : public withdraw_scorumpower_check_fixture
{
    withdraw_scorumpower_route_from_dev_pool_to_dev_pool_tests_fixture()
    {
        pool_to_withdraw_sp = ASSET_SP(1e+4) * SCORUM_VESTING_WITHDRAW_INTERVALS;
        pool_to_withdraw_scr = asset(pool_to_withdraw_sp.amount, SCORUM_SYMBOL);
        set_dev_pool_balance(pool_to_withdraw_sp);
    }

    asset pool_to_withdraw_sp;
    asset pool_to_withdraw_scr;
};

BOOST_FIXTURE_TEST_CASE(withdraw_all_check, withdraw_scorumpower_route_from_dev_pool_to_dev_pool_tests_fixture)
{
    const auto& pool = pool_service.get();

    db_plugin->debug_update(
        [&](database&) {
            withdraw_scorumpower_dev_pool_task create_withdraw;
            withdraw_scorumpower_context ctx(db, pool_to_withdraw_sp);
            create_withdraw.apply(ctx);
        },
        get_skip_flags());

    fc::time_point_sec start_time = db.head_block_time();

    auto next_withdrawal = db.head_block_time() + SCORUM_VESTING_WITHDRAW_INTERVAL_SECONDS;

    generate_blocks(next_withdrawal + (SCORUM_BLOCK_INTERVAL / 2), true);

    BOOST_CHECK_EQUAL(pool.scr_balance, pool_to_withdraw_scr / SCORUM_VESTING_WITHDRAW_INTERVALS);

    BOOST_REQUIRE(withdraw_scorumpower_service.is_exists(pool.id));

    for (uint32_t ci = 1; ci < SCORUM_VESTING_WITHDRAW_INTERVALS; ++ci)
    {
        next_withdrawal = db.head_block_time() + SCORUM_VESTING_WITHDRAW_INTERVAL_SECONDS;
        generate_blocks(next_withdrawal + (SCORUM_BLOCK_INTERVAL / 2), true);
    }

    BOOST_REQUIRE(!withdraw_scorumpower_service.is_exists(pool.id));

    BOOST_CHECK_EQUAL(pool.scr_balance, pool_to_withdraw_scr);

    fc::time_point_sec end_time = db.head_block_time();

    BOOST_CHECK_EQUAL((end_time - start_time).to_seconds(),
                      SCORUM_VESTING_WITHDRAW_INTERVAL_SECONDS * SCORUM_VESTING_WITHDRAW_INTERVALS);
}

BOOST_AUTO_TEST_SUITE_END()

max_stars_repo_name: scorum/scorum

max_issues_repo_name: Scorum/Scorum

max_forks_repo_name: Scorum/Scorum


text:
// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
//
// 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_APPLICATION_DETAIL_PROCESS_ID_HPP
#define BOOST_APPLICATION_DETAIL_PROCESS_ID_HPP

#include <boost/application/config.hpp>
#include <boost/application/detail/csbl.hpp>
#include <boost/application/system_error.hpp>

#include <boost/detail/winapi/basic_types.hpp>
#include <boost/detail/winapi/process.hpp>

#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif

namespace boost { namespace application { namespace detail {

   class  process_id_impl {

   public:
      typedef boost::detail::winapi::DWORD_ native_pid_t;

      process_id_impl()
         : pid_ (0)
      {}

      process_id_impl(native_pid_t pid)
         : pid_ (pid)
      {}

      native_pid_t pid() BOOST_NOEXCEPT {
         if(pid_)
            return pid_;

         pid_ = boost::detail::winapi::GetCurrentProcessId();
         return pid_;
      }

   private:
      native_pid_t pid_;
   };

}}} // namespace boost::application::detail

#endif // BOOST_APPLICATION_DETAIL_WINDOWS_PATH_FROM_ME_HPP


text:
//==================================================================================================
/*!

  Copyright 2015 NumScale SAS

  Distributed under the Boost Software License, Version 1.0.
  (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
//==================================================================================================
#include <boost/simd/function/scalar/rol.hpp>
#include <simd_test.hpp>
#include <boost/dispatch/meta/as_integer.hpp>
#include <boost/simd/function/bitwise_cast.hpp>

STF_CASE_TPL (" rol integer", STF_INTEGRAL_TYPES)
{
  namespace bs = boost::simd;
  namespace bd = boost::dispatch;
  using bs::rol;
  STF_EXPR_IS( rol(T(), T()), T);

  T w = sizeof(T)*CHAR_BIT;

  for(T i=0;i<w;++i)
  {
    std::cout << int(i) << " -> ";
    STF_EQUAL(rol(T(1),T(i)), T(T(1)<<i) );
  }

/*
  STF_ASSERT(rol(T(1),T(-1)));
  STF_ASSERT(rol(T(1),T(w+1)));
*/
}

STF_CASE_TPL (" rolreal", STF_IEEE_TYPES)
{
  namespace bs = boost::simd;
  namespace bd = boost::dispatch;
  using bs::rol;
  using bs::bitwise_cast;
  using iT = bd::as_integer_t<T> ;

  STF_EXPR_IS( rol(T(), iT()), T);

  iT w = sizeof(T)*CHAR_BIT;

  for(iT i=0;i<w;++i)
    STF_EQUAL( rol(bitwise_cast<T>(iT(1)),iT(i))
                  , bitwise_cast<T>(iT(1)<<i)
                  );
/*
  STF_ASSERT(rol(T(1),iT(-1)));
  STF_ASSERT(rol(T(1),iT(w+1)));
*/
}


text:
#include "ReadFile.hpp"
#include <algorithm>
#include <fstream>
#include <sstream>
#include <boost/locale/encoding.hpp>

namespace sdo {
struct Latin1Char
{
   bool operator()( const char c ) const
   {
      return   c == '\xC4' || // Ä
               c == '\xD6' || // Ö
               c == '\xDC' || // Ü
               c == '\xE4' || // ä
               c == '\xF6' || // ö
               c == '\xFC' || // ü
               c == '\xDF';   // ß
   }
};

std::string read_file( const std::string &file )
{
   std::string out;
   //read file into string
   std::ifstream in;
   in.exceptions( std::ifstream::failbit | std::ifstream::badbit);
   in.open(file, std::ios::in | std::ios::binary);
   in.seekg(0, std::ios::end);
   out.resize(in.tellg());
   in.seekg(0, std::ios::beg);
   in.read(&out[0], out.size());
   in.close();

   //Convert to utf-8 if necessary
   if( std::find_if( out.begin(), out.end(), Latin1Char() ) != out.end() )
      return boost::locale::conv::to_utf<char>(out,"Latin1");

   return out;
}

}

max_stars_repo_name: rgottwald/libsdo

max_issues_repo_name: rgottwald/libsdo

max_forks_repo_name: rgottwald/libsdo


text:
//
// Created by Hamza El-Kebir on 6/18/21.
//

#ifndef LODESTAR_BUTCHERTABLEAU_HPP
#define LODESTAR_BUTCHERTABLEAU_HPP

#include <type_traits>
#include <tuple>
#include <array>
#include <string>
#include <string_view>
#include <functional>
#include "Lodestar/aux/Indices.hpp"
#include "Lodestar/aux/Conjunction.hpp"
#include <iostream>
#include <Eigen/Dense>

namespace ls {
    namespace primitives {
        namespace detail {
            /**
             * @brief A Butcher tableau row.
             *
             * @details There exist two partial specializations for this type: one for a regular row, which includes
             * a node and several Runge-Kutta coefficients (the exact number being depending on \c (TStage + 1)); the
             * other is a weight row, which only includes an array of \c TStages for the weights.
             *
             * @tparam TScalarType Type of the scalar coefficients.
             * @tparam TStages Number of stages in the integration scheme.
             * @tparam TStage Index of the current stage.
             * @tparam TIsWeights If true, the current row is a weight row.
             */
            template<typename TScalarType, size_t TStages, size_t TStage, bool TIsWeights>
            struct ButcherRowImpl {
            };

            /**
             * @brief Butcher tableau specialization for regular row.
             *
             * @sa ButcherRowImpl
             *
             * @tparam TScalarType Type of the scalar coefficients.
             * @tparam TStages Number of stages in the integration scheme.
             * @tparam TStage Index of the current stage.
             */
            template<typename TScalarType, size_t TStages, size_t TStage>
            struct ButcherRowImpl<TScalarType, TStages, TStage, false> {
                static_assert(TStage >= 0, "Butcher tableau row number must be non-negative.");
                static_assert(TStage < (TStages - 1),
                              "Butcher tableau row number must be smaller than the number of stages minus one.");

                TScalarType node;
                std::array<TScalarType, TStage + 1> rkCoefficients;
            };

            /**
             * @brief Butcher tableau specialization for weight row.
             *
             * @sa ButcherRowImpl
             *
             * @tparam TScalarType Type of the scalar coefficients.
             * @tparam TStages Number of stages in the integration scheme.
             * @tparam TStage Index of the current stage.
             */
            template<typename TScalarType, size_t TStages, size_t TStage>
            struct ButcherRowImpl<TScalarType, TStages, TStage, true> {
                std::array<TScalarType, TStages> weights;
            };
        }

        /**
         * @brief Implements a compile-time structure for simple/extended Butcher tableaus.
         *
         * @details Explicit methods in the Runge-Kutta family of numerical integrators can be described by the
         * following coefficient:
         * <ul>
         *      <li> Runge-Kutta coefficients \c a_ij;
         *      <li> Weights \c b_i;
         *      <li> Nodes \c c_i.
         * </ul>
         *
         *
         * @tparam TStages Number of stages in the integration scheme.
         * @tparam TExtended If true, an extended Butcher tableau is given.
         * @tparam TScalarType Type of the scalar coefficients.
         */
        template<size_t TStages, bool TExtended = true, typename TScalarType = double>
        class ButcherTableau {
            static_assert(TStages > 1, "Butcher tableau must have more than one stage.");
        };

        template<size_t TStages, typename TScalarType>
        class ButcherTableau<TStages, false, TScalarType> {
        public:
            static_assert(TStages > 1, "Butcher tableau must have more than one stage.");

            static const size_t stages = TStages; //! Number of stages.
            using type = TScalarType; //! Coefficient type.

            /**
             * @brief Alias template for \c ButcherRow.
             *
             * @tparam TStage Index of the current stage.
             * @tparam TIsWeights If true, the current row is a weight row.
             */
            template<size_t TStage, bool TIsWeights = (TStage >= (TStages - 1))>
            using ButcherRow = detail::ButcherRowImpl<TScalarType, TStages, TStage, TIsWeights>;

            /**
             * @brief Returns the Runge-Kutta coefficient for the given row number and coefficient index.
             *
             * @tparam TRow Row number (related to stage number).
             * @tparam TCoeffIdx Index of the Runge-Kutta coefficient.
             *
             * @return Runge-Kutta coefficient at (\c TRow, \c TCoeffIdx).
             */
            template<size_t TRow, size_t TCoeffIdx>
            typename std::enable_if<(TRow < (TStages - 1)) && (TCoeffIdx < (TRow + 1)), TScalarType>::type
            inline getCoefficient()
            {
                return std::get<TCoeffIdx>(std::get<TRow>(rows_).rkCoefficients);
            }

            /**
             * @brief Degenerate Runge-Kutta coefficient getter.
             *
             * @tparam TRow Row number (related to stage number).
             * @tparam TCoeffIdx Index of the Runge-Kutta coefficient.
             *
             * @return Runge-Kutta coefficient at (\c TRow, \c TCoeffIdx).
             */
            template<size_t TRow, size_t TCoeffIdx>
            typename std::enable_if<!((TRow < (TStages - 1)) && (TCoeffIdx < (TRow + 1))), TScalarType>::type
            inline getCoefficient()
            {
                static_assert(TRow < (TStages - 1),
                              "Row index must be smaller than the number of stages minus one to access coefficients.");
                static_assert(TCoeffIdx < (TRow + 1), "Coefficient index must be less than or equal to the row index.");

                return TScalarType{};
            }

            /**
             * @brief Sets the Runge-Kutta coefficient at the given row number and coefficient index.
             *
             * @tparam TRow Row number (related to stage number).
             * @tparam TCoeffIdx Index of the Runge-Kutta coefficient.
             *
             * @param coeff Coefficient value to be set.
             */
            template<size_t TRow, size_t TCoeffIdx>
            typename std::enable_if<(TRow < (TStages - 1)) && (TCoeffIdx < (TRow + 1)), void>::type
            inline setCoefficient(TScalarType coeff)
            {
                std::get<TCoeffIdx>(std::get<TRow>(rows_).rkCoefficients) = coeff;
            }

            /**
             * @brief Degenerate Runge-Kutta coefficient setter.
             *
             * @tparam TRow Row number (related to stage number).
             * @tparam TCoeffIdx Index of the Runge-Kutta coefficient.
             *
             * @param coeff Coefficient value to be set.
             */
            template<size_t TRow, size_t TCoeffIdx>
            typename std::enable_if<!((TRow < (TStages - 1)) && (TCoeffIdx < (TRow + 1))), void>::type
            inline setCoefficient(TScalarType coeff)
            {
                static_assert(TRow < (TStages - 1),
                              "Row index must be smaller than the number of stages minus one to access coefficients.");
                static_assert(TCoeffIdx < (TRow + 1), "Coefficient index must be less than or equal to the row index.");
            }

            /**
             * @brief Returns the node value for the given row number.
             *
             * @tparam TRow Row number (related to stage number).
             *
             * @return Node value of \c TRow.
             */
            template<size_t TRow>
            typename std::enable_if<TRow < (TStages - 1), TScalarType>::type
            inline getNode()
            {
                return std::get<TRow>(rows_).node;
            }

            /**
             * @brief Degenerate node getter.
             *
             * @tparam TRow Row number (related to stage number).
             *
             * @return Node value of \c TRow.
             */
            template<size_t TRow>
            typename std::enable_if<TRow >= (TStages - 1), TScalarType>::type
            inline getNode()
            {
                static_assert(TRow < (TStages - 1),
                              "Row index must be smaller than the number of stages minus one to access coefficients.");

                return TScalarType{};
            }

            /**
             * @brief Sets the node value for the given row number.
             *
             * @tparam TRow  Row number (related to stage number).
             *
             * @param node Node value to be set.
             */
            template<size_t TRow>
            typename std::enable_if<TRow < (TStages - 1), void>::type
            inline setNode(TScalarType node)
            {
                std::get<TRow>(rows_).node = node;
            }

            /**
             * @brief Degenerate node setter.
             *
             * @tparam TRow  Row number (related to stage number).
             *
             * @param node Node value to be set.
             */
            template<size_t TRow>
            typename std::enable_if<TRow >= (TStages - 1), void>::type
            inline setNode(TScalarType node)
            {
                static_assert(TRow < (TStages - 1),
                              "Row index must be smaller than the number of stages minus one to access coefficients.");
            }

            /**
             * @brief Returns the weight value at the given index.
             *
             * @tparam TIdx Weight index.
             *
             * @return Weight value at \c TIdx.
             */
            template<size_t TIdx>
            typename std::enable_if<TIdx < TStages, TScalarType>::type
            inline getWeight()
            {
                return std::get<TIdx>(std::get<TStages - 1>(rows_).weights);
            }

            /**
             * @brief Degenerate weight getter.
             *
             * @tparam TIdx Weight index.
             *
             * @return Weight value at \c TIdx.
             */
            template<size_t TIdx>
            typename std::enable_if<TIdx >= TStages, TScalarType>::type
            inline getWeight()
            {
                static_assert(TIdx < TStages, "Weight index must be smaller than the number of stages.");

                return TScalarType{};
            }

            /**
             * @brief Sets the weight value for the given index.
             *
             * @tparam TIdx Weight index.
             *
             * @param weight Weight value to be set.
             */
            template<size_t TIdx>
            typename std::enable_if<TIdx < TStages, void>::type
            inline setWeight(TScalarType weight)
            {
                std::get<TIdx>(std::get<TStages - 1>(rows_).weights) = weight;
            }

            /**
             * @brief Degenerate weight setter.
             *
             * @tparam TIdx Weight index.
             *
             * @param weight Weight value to be set.
             */
            template<size_t TIdx>
            typename std::enable_if<TIdx >= TStages, void>::type
            inline setWeight(TScalarType weight)
            {
                static_assert(TIdx < TStages, "Weight index must be smaller than the number of stages.");
            }

            /**
             * @brief Executes the explicit Runge-Kutta scheme defined in the Butcher tableau.
             *
             * @details The integration scheme integrates y'(t) = f(t, y(t)) from \c t to \c (t + h), where \c y(t) = y.
             *
             * This particular function is the entry point to run a single iteration of the Runge-Kutta scheme
             * encoded in the Butcher tableau.
             *
             * @tparam TType State type.
             * @tparam TStage Index of the current stage.
             *
             * @param f Function to be integrated.
             * @param y Initial state.
             * @param t Initial time.
             * @param h Integration step.
             *
             * @return Integrated state.
             */
            template<typename TType, size_t TStage = 0>
            typename std::enable_if<TStage == 0, TType>::type
            inline execute(const std::function<TType(TScalarType, TType)> &f, const TType &y, const TScalarType t,
                    const TScalarType h)
            {
//                TType kCurr;
//                std::cout << "f(t,y) in Butcher tableau: " << f(t, y) << std::endl;
//                kCurr = f(t, y);
                auto kCurr = f(t,y);

                return execute<TType, TStage + 1>(f, y, t, h, kCurr);
            }

            /**
             * @brief Executes the explicit Runge-Kutta scheme defined in the Butcher tableau.
             *
             * @details The integration scheme integrates y'(t) = f(t, y(t)) from \c t to \c (t + h), where \c y(t) = y.
             *
             * This particular function deals with the regular stages of the integration scheme.
             *
             * @tparam TType State type.
             * @tparam TStage Index of the current stage.
             *
             * @param f Function to be integrated.
             * @param y Initial state.
             * @param t Initial time.
             * @param h Integration step.
             *
             * @return Integrated state.
             */
            template<typename TType, size_t TStage = 0, typename... TArgs>
            typename std::enable_if<(TStage > 0) && (TStage < TStages) &&
                                    (Conjunction<std::is_convertible<TArgs, TType>...>::value), TType>::type
            inline execute(const std::function<TType(TScalarType, TType)> &f, const TType &y, const TScalarType t,
                           const TScalarType h,
                           TArgs... vars)
            {
                TType kCurr{}, yCurr = y;

                yCurr += h * sumCoefficients<TType, TStage>(vars...);
                TScalarType tCurr = t + getNode<TStage - 1>() * h;

                kCurr = f(tCurr, yCurr);

                return execute<TType, TStage + 1>(f, y, t, h, vars..., kCurr);
//                return execute<TType, TStage + 1>(f, y, t, h, vars..., f(t + getNode<TStage - 1>() * h, y + h * sumCoefficients<TType, TStage>(vars...)));
            }

            /**
             * @brief Executes the explicit Runge-Kutta scheme defined in the Butcher tableau.
             *
             * @details The integration scheme integrates y'(t) = f(t, y(t)) from \c t to \c (t + h), where \c y(t) = y.
             *
             * This particular function deals with the final stage of the integration scheme.
             *
             * @tparam TType State type.
             * @tparam TStage Index of the current stage.
             *
             * @param f Function to be integrated.
             * @param y Initial state.
             * @param t Initial time.
             * @param h Integration step.
             *
             * @return Integrated state.
             */
            template<typename TType, size_t TStage = 0, typename... TArgs>
            typename std::enable_if<(TStage > 0) && (TStage == TStages) &&
                                    (Conjunction<std::is_convertible<TArgs, TType>...>::value), TType>::type
            inline execute(const std::function<TType(TScalarType, TType)> &f, const TType &y, const TScalarType t,
                           const TScalarType h,
                           TArgs... vars)
            {
                TType yFinal = y;
                yFinal += h * sumWeights<TType>(vars...);

                return yFinal;
            }

        protected:
            /**
             * Helper struct that will define a tuple of specialized Butcher rows.
             *
             * @sa Repeat
             * @sa Indices
             *
             * @tparam TTimes Number of times the generator must be ran.
             * @tparam TIndices An \c IndexSequence type.
             */
            template<int TTimes, typename TIndices = typename Indices<TTimes>::type>
            struct Rows;

            /**
             * @brief Partial specialization of the \c Rows struct, which defines a tuple of specialized Butcher rows.
             *
             * @tparam TTimes Number of times the generator must be ran.
             * @tparam TIndices Template pack of integers (from 0 to TTimes - 1 by default).
             */
            template<int TTimes, int... TIndices>
            struct Rows<TTimes, IndexSequence<TIndices...>> {
                using type = std::tuple<ButcherRow<TIndices>...>;
            };

            typename Rows<TStages>::type rows_; //! Rows of the Butcher tableau.

            /**
             * @brief Sums Runge-Kutta coefficients multiplied with results from previous stages.
             *
             * @details This function computes sum_(j=0)^i a_ij * k_i, where i is \c TStage.
             *
             * @tparam TType State type.
             * @tparam TStage Index of the current stage.
             * @tparam TArgs Parameter pack of argument (previous stage result) types.
             * @tparam TIndex Typename of the \c Indices object.
             *
             * @param vars Variadic argument list of results of previous stages.
             *
             * @return Sum.
             */
            template<typename TType, size_t TStage = 0, typename... TArgs, typename TIndex = typename Indices<sizeof...(TArgs)>::type>
            typename std::enable_if<
                    (TStage > 0) && (TStage < TStages) &&
                    (Conjunction<std::is_convertible<TArgs, TType>...>::value), TType>::type
            inline sumCoefficients(TArgs... vars)
            {
                return sumCoefficientsImpl<TType, TStage - 1>(TIndex{}, vars...);
            }

            /**
             * @brief Implementation of \c sumCoefficients.
             *
             * @note This separate implementation is required to extract the list of indices at compile time.
             *
             * @tparam TType State type.
             * @tparam TStage Index of the current stage.
             * @tparam TArgs Parameter pack of argument (previous stage result) types.
             * @tparam TIndices Parameter pack of indices.
             *
             * @param vars Variadic argument list of results of previous stages.
             *
             * @return Sum.
             */
            template<typename TType, size_t TStage = 0, typename... TArgs, int... TIndices>
            TType
            inline sumCoefficientsImpl(IndexSequence<TIndices...>, TArgs... vars)
            {
                return sum<TType>((getCoefficient<TStage, (size_t) TIndices>() * vars)...);
            }

            /**
             * @brief Sums weight coefficients multiplied with results from previous stages.
             *
             * @tparam TType State type.
             * @tparam TArgs Parameter pack of argument (previous stage result) types
             * @tparam TIndex TIndex Typename of the \c Indices object.
             *
             * @param vars Variadic argument list of results of previous stages.
             *
             * @return Sum.
             */
            template<typename TType, typename... TArgs, typename TIndex = typename Indices<sizeof...(TArgs)>::type>
            typename std::enable_if<(Conjunction<std::is_convertible<TArgs, TType>...>::value), TType>::type
            inline sumWeights(TArgs... vars)
            {
                return sumWeightsImpl<TType>(TIndex{}, vars...);
            }

            /**
             * @brief Implementation of \c sumWeights.
             *
             * @note This separate implementation is required to extract the list of indices at compile time.
             *
             * @tparam TType State type.
             * @tparam TArgs Parameter pack of argument (previous stage result) types.
             * @tparam TIndices Parameter pack of indices.
             *
             * @param vars Variadic argument list of results of previous stages.
             *
             * @return Sum.
             */
            template<typename TType, typename... TArgs, int... TIndices>
            TType
            inline sumWeightsImpl(IndexSequence<TIndices...>, TArgs... vars)
            {
                return sum<TType>((getWeight<(size_t) TIndices>() * vars)...);
            }

            /**
             * @brief Helper function that sums arguments.
             *
             * @details This particular function is the base case, which simply returns the value that it was given.
             *
             * @tparam TType State type.
             * @tparam TArg Argument type.
             *
             * @param var Argument.
             *
             * @return Argument.
             */
            template<typename TType, typename TArg>
            typename std::enable_if<std::is_convertible<TArg, TType>::value, TType>::type
            inline sum(TArg var)
            {
                return var;
            }

            /**
             * @brief Degenerate case of helper function that sums arguments.
             *
             * @details This function checks convertibility of the argument type to \c TType.
             *
             * @tparam TType State type.
             * @tparam TArg Argument type.
             *
             * @param var Argument.
             */
            template<typename TType, typename TArg>
            typename std::enable_if<!std::is_convertible<TArg, TType>::value, TType>::type
            inline sum(TArg var)
            {
                static_assert(std::is_convertible<TArg, TType>::value, "Summed values must be convertible.");
                return var;
            }

            /**
             * @brief Helper function that sums arguments.
             *
             * @tparam TType State type.
             * @tparam TArg First argument type.
             * @tparam TArgs Template pack of variadic argument list typenames.
             *
             * @param var First argument.
             * @param vars Variadic arguments.
             *
             * @return Sum.
             */
            template<typename TType, typename TArg, typename... TArgs>
            typename std::enable_if<std::is_convertible<TArg, TType>::value &&
                    (Conjunction<std::is_convertible<TArgs, TType>...>::value), TType>::type
            inline sum(TArg var, TArgs... vars)
            {
                return var + sum<TType>(vars...);
            }

            /**
             * @brief Degenerate case of helper function that sums arguments.
             *
             * @tparam TType State type.
             * @tparam TArg First argument type.
             * @tparam TArgs Template pack of variadic argument list typenames.
             *
             * @param var First argument.
             * @param vars Variadic arguments.
             */
            template<typename TType, typename TArg, typename... TArgs>
            typename std::enable_if<!(std::is_convertible<TArg, TType>::value &&
                                      (Conjunction<std::is_convertible<TArgs, TType>...>::value)), TType>::type
            inline sum(TArg var, TArgs... vars)
            {
                static_assert(std::is_convertible<TArg, TType>::value &&
                              (Conjunction<std::is_convertible<TArgs, TType>...>::value),
                              "Summed values must be convertible.");

                return var + sum<TType>(vars...);
            }
        };

// --------------- Extended Butcher tableau -----------------------

        /**
         * @brief Implements a compile-time structure for extended Butcher tableaus.
         *
         * @details Explicit methods in the Runge-Kutta family of numerical integrators can be described by the
         * following coefficient:
         * <ul>
         *      <li> Runge-Kutta coefficients \c a_ij;
         *      <li> Weights \c b_i;
         *      <li> Nodes \c c_i.
         * </ul>
         *
         *
         * @tparam TStages Number of stages in the integration scheme.
         * @tparam TScalarType Type of the scalar coefficients.
         */
        template<size_t TStages, typename TScalarType>
        class ButcherTableau<TStages, true, TScalarType> {
        public:
            static_assert(TStages > 1, "Butcher tableau must have more than one stage.");

            static const size_t stages = TStages; //! Number of stages.
            using type = TScalarType; //! Coefficient type.

            /**
             * @brief Alias template for \c ButcherRow.
             *
             * @tparam TStage Index of the current stage.
             * @tparam TIsWeights If true, the current row is a weight row.
             */
            template<size_t TStage, bool TIsWeights = (TStage >= (TStages - 1))>
            using ButcherRow = detail::ButcherRowImpl<TScalarType, TStages, TStage, TIsWeights>;

            /**
             * @brief Returns the Runge-Kutta coefficient for the given row number and coefficient index.
             *
             * @tparam TRow Row number (related to stage number).
             * @tparam TCoeffIdx Index of the Runge-Kutta coefficient.
             *
             * @return Runge-Kutta coefficient at (\c TRow, \c TCoeffIdx).
             */
            template<size_t TRow, size_t TCoeffIdx>
            typename std::enable_if<(TRow < (TStages - 1)) && (TCoeffIdx < (TRow + 1)), TScalarType>::type
            inline getCoefficient()
            {
                return std::get<TCoeffIdx>(std::get<TRow>(rows_).rkCoefficients);
            }

            /**
             * @brief Degenerate Runge-Kutta coefficient getter.
             *
             * @tparam TRow Row number (related to stage number).
             * @tparam TCoeffIdx Index of the Runge-Kutta coefficient.
             *
             * @return Runge-Kutta coefficient at (\c TRow, \c TCoeffIdx).
             */
            template<size_t TRow, size_t TCoeffIdx>
            typename std::enable_if<!((TRow < (TStages - 1)) && (TCoeffIdx < (TRow + 1))), TScalarType>::type
            inline getCoefficient()
            {
                static_assert(TRow < (TStages - 1),
                              "Row index must be smaller than the number of stages minus one to access coefficients.");
                static_assert(TCoeffIdx < (TRow + 1), "Coefficient index must be less than or equal to the row index.");

                return TScalarType{};
            }

            /**
             * @brief Sets the Runge-Kutta coefficient at the given row number and coefficient index.
             *
             * @tparam TRow Row number (related to stage number).
             * @tparam TCoeffIdx Index of the Runge-Kutta coefficient.
             *
             * @param coeff Coefficient value to be set.
             */
            template<size_t TRow, size_t TCoeffIdx>
            typename std::enable_if<(TRow < (TStages - 1)) && (TCoeffIdx < (TRow + 1)), void>::type
            inline setCoefficient(TScalarType coeff)
            {
                std::get<TCoeffIdx>(std::get<TRow>(rows_).rkCoefficients) = coeff;
            }

            /**
             * @brief Degenerate Runge-Kutta coefficient setter.
             *
             * @tparam TRow Row number (related to stage number).
             * @tparam TCoeffIdx Index of the Runge-Kutta coefficient.
             *
             * @param coeff Coefficient value to be set.
             */
            template<size_t TRow, size_t TCoeffIdx>
            typename std::enable_if<!((TRow < (TStages - 1)) && (TCoeffIdx < (TRow + 1))), void>::type
            inline setCoefficient(TScalarType coeff)
            {
                static_assert(TRow < (TStages - 1),
                              "Row index must be smaller than the number of stages minus one to access coefficients.");
                static_assert(TCoeffIdx < (TRow + 1), "Coefficient index must be less than or equal to the row index.");
            }

            /**
             * @brief Returns the node value for the given row number.
             *
             * @tparam TRow Row number (related to stage number).
             *
             * @return Node value of \c TRow.
             */
            template<size_t TRow>
            typename std::enable_if<TRow < (TStages - 1), TScalarType>::type
            inline getNode()
            {
                return std::get<TRow>(rows_).node;
            }

            /**
             * @brief Degenerate node getter.
             *
             * @tparam TRow Row number (related to stage number).
             *
             * @return Node value of \c TRow.
             */
            template<size_t TRow>
            typename std::enable_if<TRow >= (TStages - 1), TScalarType>::type
            inline getNode()
            {
                static_assert(TRow < (TStages - 1),
                              "Row index must be smaller than the number of stages minus one to access coefficients.");

                return TScalarType{};
            }

            /**
             * @brief Sets the node value for the given row number.
             *
             * @tparam TRow  Row number (related to stage number).
             *
             * @param node Node value to be set.
             */
            template<size_t TRow>
            typename std::enable_if<TRow < (TStages - 1), void>::type
            inline setNode(TScalarType node)
            {
                std::get<TRow>(rows_).node = node;
            }

            /**
             * @brief Degenerate node setter.
             *
             * @tparam TRow  Row number (related to stage number).
             *
             * @param node Node value to be set.
             */
            template<size_t TRow>
            typename std::enable_if<TRow >= (TStages - 1), void>::type
            inline setNode(TScalarType node)
            {
                static_assert(TRow < (TStages - 1),
                              "Row index must be smaller than the number of stages minus one to access coefficients.");
            }

            /**
             * @brief Returns the weight value at the given index.
             *
             * @details This function gets the higher order weight.
             *
             * @tparam TIdx Weight index.
             * @tparam THigherOrder If true, the higher order weights are retrieved.
             *
             * @return Weight value at \c TIdx.
             */
            template<size_t TIdx, bool THigherOrder = true>
            typename std::enable_if<(TIdx < TStages) && THigherOrder, TScalarType>::type
            inline getWeight()
            {
                return std::get<TIdx>(std::get<TStages - 1>(rows_).weights);
            }

            /**
             * @brief Returns the weight value at the given index.
             *
             * @details This function gets the lower order weight.
             *
             * @tparam TIdx Weight index.
             * @tparam THigherOrder If true, the higher order weights are retrieved.
             *
             * @return Weight value at \c TIdx.
             */
            template<size_t TIdx, bool THigherOrder = true>
            typename std::enable_if<(TIdx < TStages) && !THigherOrder, TScalarType>::type
            inline getWeight()
            {
                return std::get<TIdx>(std::get<TStages>(rows_).weights);
            }

            /**
             * @brief Degenerate weight getter.
             *
             * @tparam TIdx Weight index.
             * @tparam THigherOrder If true, the higher order weights are retrieved.
             *
             * @return Weight value at \c TIdx.
             */
            template<size_t TIdx, bool THigherOrder = true>
            typename std::enable_if<TIdx >= TStages, TScalarType>::type
            inline getWeight()
            {
                static_assert(TIdx < TStages, "Weight index must be smaller than the number of stages.");

                return TScalarType{};
            }

            /**
             * @brief Sets the weight value for the given index.
             *
             * @details This function sets the higher order weight.
             *
             * @tparam TIdx Weight index.
             * @tparam THigherOrder If true, the higher order weights are changed.
             *
             * @param weight Weight value to be set.
             */
            template<size_t TIdx, bool THigherOrder = true>
            typename std::enable_if<(TIdx < TStages) && THigherOrder, void>::type
            inline setWeight(TScalarType weight)
            {
                std::get<TIdx>(std::get<TStages - 1>(rows_).weights) = weight;
            }

            /**
             * @brief Sets the weight value for the given index.
             *
             * @details This function sets the lower order weight.
             *
             * @tparam TIdx Weight index.
             * @tparam THigherOrder If true, the higher order weights are changed.
             *
             * @param weight Weight value to be set.
             */
            template<size_t TIdx, bool THigherOrder = true>
            typename std::enable_if<(TIdx < TStages) && !THigherOrder, void>::type
            inline setWeight(TScalarType weight)
            {
                std::get<TIdx>(std::get<TStages>(rows_).weights) = weight;
            }

            /**
             * @brief Degenerate weight setter.
             *
             * @tparam TIdx Weight index.
             * @tparam THigherOrder If true, the higher order weights are changed.
             *
             * @param weight Weight value to be set.
             */
            template<size_t TIdx, bool THigherOrder = true>
            typename std::enable_if<TIdx >= TStages, void>::type
            inline setWeight(TScalarType weight)
            {
                static_assert(TIdx < TStages, "Weight index must be smaller than the number of stages.");
            }

            /**
             * @brief Executes the explicit Runge-Kutta scheme defined in the Butcher tableau.
             *
             * @details The integration scheme integrates y'(t) = f(t, y(t)) from \c t to \c (t + h), where \c y(t) = y.
             *
             * This particular function is the entry point to run a single iteration of the Runge-Kutta scheme
             * encoded in the Butcher tableau.
             *
             * @tparam TType State type.
             * @tparam TStage Index of the current stage.
             * @tparam TIsEmbedded If true, the execution considers and embedded scheme.
             *
             * @param f Function to be integrated.
             * @param y Initial state.
             * @param t Initial time.
             * @param h Integration step.
             *
             * @return Integrated state.
             */
            template<typename TType, size_t TStage = 0, bool TIsEmbedded = false>
            typename std::enable_if<(TStage == 0) && !TIsEmbedded, TType>::type
            inline execute(const std::function<TType(TScalarType, TType)> &f, const TType &y, const TScalarType t,
                    const TScalarType h)
            {
                TType kCurr = f(t, y);

                return execute<TType, TStage + 1, TIsEmbedded>(f, y, t, h, kCurr);
            }

            /**
             * @brief Executes the explicit Runge-Kutta scheme defined in the Butcher tableau.
             *
             * @details The integration scheme integrates y'(t) = f(t, y(t)) from \c t to \c (t + h), where \c y(t) = y.
             *
             * This particular function is the entry point to run a single iteration of the Runge-Kutta scheme
             * encoded in the Butcher tableau.
             *
             * @tparam TType State type.
             * @tparam TStage Index of the current stage.
             * @tparam TIsEmbedded If true, the execution considers an embedded scheme.
             *
             * @param f Function to be integrated.
             * @param y Initial state.
             * @param t Initial time.
             * @param h Integration step.
             *
             * @return Pair of integrated state (with higher-order scheme) and error.
             */
            template<typename TType, size_t TStage = 0, bool TIsEmbedded = false>
            typename std::enable_if<(TStage == 0) && TIsEmbedded, std::pair<TType, TType>>::type
            inline execute(const std::function<TType(TScalarType, TType)> &f, const TType &y, const TScalarType t,
                    const TScalarType h)
            {
                TType kCurr = f(t, y);

                return execute<TType, TStage + 1, TIsEmbedded>(f, y, t, h, kCurr);
            }

            /**
             * @brief Executes the explicit Runge-Kutta scheme defined in the Butcher tableau.
             *
             * @details The integration scheme integrates y'(t) = f(t, y(t)) from \c t to \c (t + h), where \c y(t) = y.
             *
             * This particular function deals with the regular stages of the integration scheme.
             *
             * @tparam TType State type.
             * @tparam TStage Index of the current stage.
             * @tparam TIsEmbedded If true, the execution considers an embedded scheme.
             *
             * @param f Function to be integrated.
             * @param y Initial state.
             * @param t Initial time.
             * @param h Integration step.
             *
             * @return Integrated state.
             */
            template<typename TType, size_t TStage = 0, bool TIsEmbedded = false, typename... TArgs>
            typename std::enable_if<(TStage > 0) && (TStage < TStages) && !TIsEmbedded &&
                                    (Conjunction<std::is_convertible<TArgs, TType>...>::value), TType>::type
            inline execute(const std::function<TType(TScalarType, TType)> &f, const TType &y, const TScalarType t,
                    const TScalarType h,
                    TArgs... vars)
            {
                TType kCurr{}, yCurr = y;

                yCurr += h * sumCoefficients<TType, TStage>(vars...);
                TScalarType tCurr = t + getNode<TStage - 1>() * h;

                kCurr = f(tCurr, yCurr);

                return execute<TType, TStage + 1, TIsEmbedded>(f, y, t, h, vars..., kCurr);
            }

            /**
             * @brief Executes the explicit Runge-Kutta scheme defined in the Butcher tableau.
             *
             * @details The integration scheme integrates y'(t) = f(t, y(t)) from \c t to \c (t + h), where \c y(t) = y.
             *
             * This particular function deals with the regular stages of the integration scheme.
             *
             * @tparam TType State type.
             * @tparam TStage Index of the current stage.
             * @tparam TIsEmbedded If true, the execution considers an embedded scheme.
             *
             * @param f Function to be integrated.
             * @param y Initial state.
             * @param t Initial time.
             * @param h Integration step.
             *
             * @return Pair of integrated state (with higher-order scheme) and error.
             */
            template<typename TType, size_t TStage = 0, bool TIsEmbedded = false, typename... TArgs>
            typename std::enable_if<(TStage > 0) && (TStage < TStages) && TIsEmbedded &&
                                    (Conjunction<std::is_convertible<TArgs, TType>...>::value), std::pair<TType, TType>>::type
            inline execute(const std::function<TType(TScalarType, TType)> &f, const TType &y, const TScalarType t,
                           const TScalarType h,
                           TArgs... vars)
            {
                TType kCurr{}, yCurr = y;

                yCurr += h * sumCoefficients<TType, TStage>(vars...);
                TScalarType tCurr = t + getNode<TStage - 1>() * h;

                kCurr = f(tCurr, yCurr);

                return execute<TType, TStage + 1, TIsEmbedded>(f, y, t, h, vars..., kCurr);
            }

            /**
             * @brief Executes the explicit Runge-Kutta scheme defined in the Butcher tableau.
             *
             * @details The integration scheme integrates y'(t) = f(t, y(t)) from \c t to \c (t + h), where \c y(t) = y.
             *
             * This particular function deals with the final stage of the integration scheme.
             *
             * @tparam TType State type.
             * @tparam TStage Index of the current stage.
             * @tparam TIsEmbedded If true, the execution considers an embedded scheme.
             *
             * @param f Function to be integrated.
             * @param y Initial state.
             * @param t Initial time.
             * @param h Integration step.
             *
             * @return Integrated state.
             */
            template<typename TType, size_t TStage = 0, bool TIsEmbedded = false, typename... TArgs>
            typename std::enable_if<(TStage > 0) && (TStage == TStages) && !TIsEmbedded &&
                                    (Conjunction<std::is_convertible<TArgs, TType>...>::value), TType>::type
            inline execute(const std::function<TType(TScalarType, TType)> &f, const TType &y, const TScalarType t,
                           const TScalarType h,
                           TArgs... vars)
            {
                TType yFinal = y;
                yFinal += h * sumWeights<TType>(vars...);

                return yFinal;
            }

            /**
             * @brief Executes the explicit Runge-Kutta scheme defined in the Butcher tableau.
             *
             * @details The integration scheme integrates y'(t) = f(t, y(t)) from \c t to \c (t + h), where \c y(t) = y.
             *
             * This particular function deals with the final stage of the integration scheme.
             *
             * @tparam TType State type.
             * @tparam TStage Index of the current stage.
             * @tparam TIsEmbedded If true, the execution considers an embedded scheme.
             *
             * @param f Function to be integrated.
             * @param y Initial state.
             * @param t Initial time.
             * @param h Integration step.
             *
             * @return Pair of integrated state (with higher-order scheme) and error.
             */
            template<typename TType, size_t TStage = 0, bool TIsEmbedded = false, typename... TArgs>
            typename std::enable_if<(TStage > 0) && (TStage == TStages) && TIsEmbedded &&
                                    (Conjunction<std::is_convertible<TArgs, TType>...>::value), std::pair<TType, TType>>::type
            inline execute(const std::function<TType(TScalarType, TType)> &f, const TType &y, const TScalarType t,
                           const TScalarType h,
                           TArgs... vars)
            {
                TType yFinal = y;
                TType summedWeightsHigher = sumWeights<TType, true>(vars...);
                TType summedWeightsLower = sumWeights<TType, false>(vars...);
                yFinal += h * summedWeightsHigher;

                std::pair<TType, TType> pair{yFinal, h * (summedWeightsHigher - summedWeightsLower)};

                return pair;
            }

        protected:
            /**
             * Helper struct that will define a tuple of specialized Butcher rows.
             *
             * @sa Repeat
             * @sa Indices
             *
             * @tparam TTimes Number of times the generator must be ran.
             * @tparam TIndices An \c IndexSequence type.
             */
            template<int TTimes, typename TIndices = typename Indices<TTimes>::type>
            struct Rows;

            /**
             * @brief Partial specialization of the \c Rows struct, which defines a tuple of specialized Butcher rows.
             *
             * @tparam TTimes Number of times the generator must be ran.
             * @tparam TIndices Template pack of integers (from 0 to TTimes - 1 by default).
             */
            template<int TTimes, int... TIndices>
            struct Rows<TTimes, IndexSequence<TIndices...>> {
                using type = std::tuple<ButcherRow<TIndices>...>;
            };

            typename Rows<TStages + 1>::type rows_; //! Rows of the Butcher tableau.

            /**
             * @brief Sums Runge-Kutta coefficients multiplied with results from previous stages.
             *
             * @details This function computes sum_(j=0)^i a_ij * k_i, where i is \c TStage.
             *
             * @tparam TType State type.
             * @tparam TStage Index of the current stage.
             * @tparam TArgs Parameter pack of argument (previous stage result) types.
             * @tparam TIndex Typename of the \c Indices object.
             *
             * @param vars Variadic argument list of results of previous stages.
             *
             * @return Sum.
             */
            template<typename TType, size_t TStage = 0, typename... TArgs, typename TIndex = typename Indices<sizeof...(TArgs)>::type>
            typename std::enable_if<
                    (TStage > 0) && (TStage < TStages) &&
                    (Conjunction<std::is_convertible<TArgs, TType>...>::value), TType>::type
            inline sumCoefficients(TArgs... vars)
            {
                return sumCoefficientsImpl<TType, TStage - 1>(TIndex{}, vars...);
            }

            /**
             * @brief Implementation of \c sumCoefficients.
             *
             * @note This separate implementation is required to extract the list of indices at compile time.
             *
             * @tparam TType State type.
             * @tparam TStage Index of the current stage.
             * @tparam TArgs Parameter pack of argument (previous stage result) types.
             * @tparam TIndices Parameter pack of indices.
             *
             * @param vars Variadic argument list of results of previous stages.
             *
             * @return Sum.
             */
            template<typename TType, size_t TStage = 0, typename... TArgs, int... TIndices>
            TType
            inline sumCoefficientsImpl(IndexSequence<TIndices...>, TArgs... vars)
            {
                return sum<TType>((getCoefficient<TStage, (size_t) TIndices>() * vars)...);
            }

            /**
             * @brief Sums weight coefficients multiplied with results from previous stages.
             *
             * @tparam TType State type.
             * @tparam THigherOrder If true, higher order weights are used.
             * @tparam TArgs Parameter pack of argument (previous stage result) types
             * @tparam TIndex TIndex Typename of the \c Indices object.
             *
             * @param vars Variadic argument list of results of previous stages.
             *
             * @return Sum.
             */
            template<typename TType, bool THigherOrder = true, typename... TArgs, typename TIndex = typename Indices<sizeof...(TArgs)>::type>
            typename std::enable_if<(Conjunction<std::is_convertible<TArgs, TType>...>::value), TType>::type
            inline sumWeights(TArgs... vars)
            {
                return sumWeightsImpl<TType, THigherOrder>(TIndex{}, vars...);
            }

            /**
             * @brief Implementation of \c sumWeights.
             *
             * @note This separate implementation is required to extract the list of indices at compile time.
             *
             * @tparam TType State type.
             * @tparam THigherOrder If true, higher order weights are used.
             * @tparam TArgs Parameter pack of argument (previous stage result) types.
             * @tparam TIndices Parameter pack of indices.
             *
             * @param vars Variadic argument list of results of previous stages.
             *
             * @return Sum.
             */
            template<typename TType, bool THigherOrder, typename... TArgs, int... TIndices>
            typename std::enable_if<THigherOrder, TType>::type
            inline sumWeightsImpl(IndexSequence<TIndices...>, TArgs... vars)
            {
                return sum<TType>((getWeight<(size_t) TIndices, true>() * vars)...);
            }

            /**
             * @brief Implementation of \c sumWeights.
             *
             * @note This separate implementation is required to extract the list of indices at compile time.
             *
             * @tparam TType State type.
             * @tparam THigherOrder If true, higher order weights are used.
             * @tparam TArgs Parameter pack of argument (previous stage result) types.
             * @tparam TIndices Parameter pack of indices.
             *
             * @param vars Variadic argument list of results of previous stages.
             *
             * @return Sum.
             */
            template<typename TType, bool THigherOrder, typename... TArgs, int... TIndices>
            typename std::enable_if<!THigherOrder, TType>::type
            inline sumWeightsImpl(IndexSequence<TIndices...>, TArgs... vars)
            {
                return sum<TType>((getWeight<(size_t) TIndices, false>() * vars)...);
            }

            /**
             * @brief Helper function that sums arguments.
             *
             * @details This particular function is the base case, which simply returns the value that it was given.
             *
             * @tparam TType State type.
             * @tparam TArg Argument type.
             *
             * @param var Argument.
             *
             * @return Argument.
             */
            template<typename TType, typename TArg>
            typename std::enable_if<std::is_convertible<TArg, TType>::value, TType>::type
            inline sum(TArg var)
            {
                return var;
            }

            /**
             * @brief Degenerate case of helper function that sums arguments.
             *
             * @details This function checks convertibility of the argument type to \c TType.
             *
             * @tparam TType State type.
             * @tparam TArg Argument type.
             *
             * @param var Argument.
             */
            template<typename TType, typename TArg>
            typename std::enable_if<!std::is_convertible<TArg, TType>::value, TType>::type
            inline sum(TArg var)
            {
                static_assert(std::is_convertible<TArg, TType>::value, "Summed values must be convertible.");
                return var;
            }

            /**
             * @brief Helper function that sums arguments.
             *
             * @tparam TType State type.
             * @tparam TArg First argument type.
             * @tparam TArgs Template pack of variadic argument list typenames.
             *
             * @param var First argument.
             * @param vars Variadic arguments.
             *
             * @return Sum.
             */
            template<typename TType, typename TArg, typename... TArgs>
            typename std::enable_if<std::is_convertible<TArg, TType>::value &&
                    (Conjunction<std::is_convertible<TArgs, TType>...>::value), TType>::type
            inline sum(TArg var, TArgs... vars)
            {
                return var + sum<TType>(vars...);
            }

            /**
             * @brief Degenerate case of helper function that sums arguments.
             *
             * @tparam TType State type.
             * @tparam TArg First argument type.
             * @tparam TArgs Template pack of variadic argument list typenames.
             *
             * @param var First argument.
             * @param vars Variadic arguments.
             */
            template<typename TType, typename TArg, typename... TArgs>
            typename std::enable_if<!(std::is_convertible<TArg, TType>::value &&
                                      (Conjunction<std::is_convertible<TArgs, TType>...>::value)), TType>::type
            inline sum(TArg var, TArgs... vars)
            {
                static_assert(std::is_convertible<TArg, TType>::value &&
                              (Conjunction<std::is_convertible<TArgs, TType>...>::value),
                              "Summed values must be convertible.");

                return var + sum<TType>(vars...);
            }
        };
    }
}

#endif //LODESTAR_BUTCHERTABLEAU_HPP

max_stars_repo_name: helkebir/Lodestar

max_issues_repo_name: helkebir/Lodestar

max_forks_repo_name: helkebir/Lodestar


text:
//  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).

#include <boost/vmd/vmd.hpp>

int main() {

}

max_issues_repo_name: qingkouwei/mediaones


text:
#include <iostream>
#include <boost/shared_ptr.hpp>

#include "../dna/dna.h"
#include "../dna/simple_immutable_dna.h"
#include "../io/util.h"
#include "vertices_io.h"
#include "contigs_graph.h"

using namespace std;

ContigsGraph::ContigsGraph(istream & contigs_stream, istream & edges_stream)
{
    while (1)
    {
        SimpleImmutableDna contig = get_dna_from_fastq_stream(contigs_stream);

        if (!contigs_stream)
            break;

        vertices.push_back(boost::shared_ptr<Dna>(contig.clone()));
        vertices.push_back(boost::shared_ptr<Dna>(reverse_complement(contig)));
    }

    edges.resize(vertices.size());

    while (1)
    {
        size_t from = read_vertex(edges_stream);
        size_t to = read_vertex(edges_stream);
        double mean, error;
        edges_stream >> mean >> error;
        int weight;
        edges_stream >> weight;

        if (!edges_stream)
            break;

        edges[from][to] = EdgeInfo(mean, error, weight);
    }

}

max_stars_repo_name: ivartb/itmo-assembler

max_issues_repo_name: ivartb/itmo-assembler

max_forks_repo_name: ivartb/itmo-assembler


text:
/**********************************************************************
 *  Copyright (c) 2008-2013, Alliance for Sustainable Energy.
 *  All rights reserved.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 **********************************************************************/

#ifndef OPENSTUDIO_SCRIPTFOLDERLISTVIEW_H
#define OPENSTUDIO_SCRIPTFOLDERLISTVIEW_H

#include <openstudio_lib/OSCollapsibleItemList.hpp>

#include <ruleset/OSArgument.hpp>

#include <model/Model.hpp>
#include <model/ModelObject.hpp>

#include <utilities/core/Logger.hpp>

#include <QFileSystemWatcher>

#include <boost/optional.hpp>

class QVBoxLayout;

class QHBoxLayout;

namespace openstudio {

class ScriptsListView;

class ScriptFolderListView : public OSCollapsibleItemList {
  Q_OBJECT
 public:
  ScriptFolderListView(const openstudio::path &t_rootPath,
                       bool addScrollArea,
                       bool draggable,
                       bool removeable,
                       OSItem::Type headerType,
                       QWidget * parent = 0);

  virtual ~ScriptFolderListView();

  void addScriptFolder(const openstudio::path &t_path, const std::string& name);

  void addScriptToFolder(const openstudio::path &t_path, const openstudio::path& folder_name);
  void removeScript(const openstudio::path &t_path);

  void duplicateScript(const openstudio::path &t_path);
  void createEmptyScript(const openstudio::path &t_folder_name);

  openstudio::path rootPath() const;

  std::vector<openstudio::path> folders() const;

  openstudio::path selectedFolder() const;

  std::string folderName(const openstudio::path& folder) const;

  void saveOSArguments();

  std::vector<ruleset::UserScriptInfo> folderUserScripts(const openstudio::path& folder) const;

  boost::shared_ptr<QFileSystemWatcher> fsWatcher() const;

 signals:
  void scriptListChanged();

 private:
  REGISTER_LOGGER("openstudio.ScriptFolderListView");

  openstudio::path iterateFileName(const openstudio::path &t_path);

  openstudio::path m_rootPath;
  OSItem::Type m_headerType;
  std::map<openstudio::path, std::string> m_displayNames;
  std::map<openstudio::path, ScriptsListView *> m_scriptsListViews;

  bool m_draggable;
  bool m_removeable;

  boost::shared_ptr<QFileSystemWatcher> m_fswatcher;
};

} // openstudio

#endif // OPENSTUDIO_SCRIPTFOLDERLISTVIEW_H

max_stars_repo_name: bobzabcik/OpenStudio

max_issues_repo_name: bobzabcik/OpenStudio

max_forks_repo_name: bobzabcik/OpenStudio