text:
// __BEGIN_LICENSE__
//  Copyright (c) 2006-2013, United States Government as represented by the
//  Administrator of the National Aeronautics and Space Administration. All
//  rights reserved.
//
//  The NASA Vision Workbench is 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.
// __END_LICENSE__

/// Converts a plate file to a nested set of directories and tiles on
/// disk.

#include <sstream>
#include <vw/Plate/PlateFile.h>
#include <vw/Plate/TileManipulation.h>

using namespace vw;
using namespace vw::platefile;

#include <boost/shared_ptr.hpp>
#include <boost/program_options.hpp>
#include <boost/filesystem/operations.hpp>
namespace po = boost::program_options;
namespace fs = boost::filesystem;

// Erases a file suffix if one exists and returns the base string
static std::string prefix_from_filename(std::string const& filename) {
  std::string result = filename;
  size_t index = result.rfind(".");
  if (index != std::string::npos)
    result.erase(index, result.size());
  return result;
}
// ----------------------------------------------------------------------------
//                          save_toast_tile()
// ----------------------------------------------------------------------------

void save_toast_tile(std::string base_output_name, boost::shared_ptr<PlateFile> platefile,
                     int32 col, int32 row, int32 level, TransactionOrNeg transaction_id) {

  try {

    // Create the level directory (if it doesn't exist)
    std::ostringstream ostr;
    ostr << base_output_name << "/" << level;
    if ( !fs::exists(ostr.str()) )
      fs::create_directory(ostr.str());

    // Create the column directory (if it doesn't exist)
    ostr << "/" << col;
    if ( !fs::exists(ostr.str()) )
      fs::create_directory(ostr.str());

    // Create the file (with the row as the filename)
    ostr << "/" << row;

    // transaction_id = -1 returns the latest tile available
    platefile->read_to_file(ostr.str(), col, row, level, transaction_id);

  } catch (const TileNotFoundErr& e) {
    //    std::cout << "\t--> [ " << col << " " << row << " " << level << "] : Missing tile\n";
  }
}

// ----------------------------------------------------------------------------
//                          save_gigapan_tile()
// ----------------------------------------------------------------------------

void save_gigapan_tile(std::string base_output_name, boost::shared_ptr<PlateFile> platefile,
                       int32 col, int32 row, int32 level, TransactionOrNeg transaction_id) {

  try {
    std::stringstream filename_stream;
    std::stringstream directory_stream;

    directory_stream << base_output_name << '/';

    filename_stream << 'r';

    for (int32 l = level - 1; l >= 0; l--) {
      uint32 bit = 1 << l;
      int index = 0;
      if ( col & bit )
        index = 1;
      if ( row & bit )
        index += 2;

      filename_stream << index;
      }

    std::string filename = filename_stream.str();

    int size = boost::numeric_cast<int>(filename.size());
    while ( (size > 3) && filename.size() >= 3 ) {
      directory_stream << filename.substr(0, 3);
      filename.erase(0, 3);

      if ( !fs::exists(directory_stream.str()) )
        fs::create_directory( directory_stream.str() );

      directory_stream << '/';
    }

    filename = directory_stream.str() + filename_stream.str();

    // transaction_id = -1 returns the latest tile available
    platefile->read_to_file(filename, col, row, level, transaction_id);

  } catch (const TileNotFoundErr& e) {
    //    std::cout << "\t--> [ " << col << " " << row << " " << level << "] : Missing tile\n";
  }
}

// ----------------------------------------------------------------------------
//                                do_level()
// ----------------------------------------------------------------------------

void do_level(int level, BBox2i tile_region, boost::shared_ptr<PlateFile> platefile,
              std::string output_name, std::string output_format, int transaction_id) {

  //  std::cout << "\t--> Exporting tiles -- " << tile_region << " @ level " << level << ".\n";

  // Subdivide the bbox into smaller workunits if necessary.  This
  // helps to keep operations efficient.
  std::list<BBox2i> tile_workunits = bbox_tiles(tile_region, 1024, 1024);
  for ( std::list<BBox2i>::iterator region_iter = tile_workunits.begin();
        region_iter != tile_workunits.end(); ++region_iter) {

    // Fetch the list of valid tiles in this particular workunit.
    std::list<TileHeader> tile_records = platefile->search_by_region(level, *region_iter, TransactionRange(transaction_id));

    if (!tile_records.empty()) {
      VW_OUT() << "\t--> Exporting " << tile_records.size() << " tiles in " << *region_iter
               << " @ level " << level << "\n";
    }

    for ( std::list<TileHeader>::iterator header_iter = tile_records.begin();
          header_iter != tile_records.end(); ++header_iter) {
      if (output_format == "toast") {
        save_toast_tile(output_name, platefile,
                        header_iter->col(), header_iter->row(),
                        header_iter->level(), header_iter->transaction_id());
      } else if (output_format == "gigapan") {
        save_gigapan_tile(output_name, platefile,
                          header_iter->col(), header_iter->row(),
                          header_iter->level(), header_iter->transaction_id());
      } else {
        vw_throw( ArgumentErr() << "unknown ouput format: " << output_format );
      }
    }
  }
}

// ----------------------------------------------------------------------------
//                                do_all_levels()
// ----------------------------------------------------------------------------

void do_all_levels(std::string platefile_name, std::string output_name,
                   std::string output_format, int transaction_id) {

  // Open the plate file
  // XXX: platefile_name should be a url
  boost::shared_ptr<PlateFile> platefile(new PlateFile(Url(platefile_name)));
  std::cout << "Exporting " << platefile->num_levels() << " levels of tiles to " << output_name << "\n";

  // Create the output directory
  if ( !fs::exists(output_name) )
    fs::create_directory(output_name);

  // Iterate over the levels
  for (uint32 level = 0; level < platefile->num_levels(); ++level) {

    // The entire region contains 2^level tiles.
    uint32 region_size = 1 << level;
    uint32 subdivided_region_size = region_size / 16;
    if (subdivided_region_size < 1024) subdivided_region_size = 1024;
    BBox2i full_region(0,0,region_size,region_size);
    std::list<BBox2i> workunits = bbox_tiles(full_region,
                                             subdivided_region_size,
                                             subdivided_region_size);
    for ( std::list<BBox2i>::iterator region_iter = workunits.begin();
          region_iter != workunits.end(); ++region_iter) {
      do_level(level, *region_iter, platefile, output_name, output_format, transaction_id);
    }
  }
}

// ----------------------------------------------------------------------------
//                                    main()
// ----------------------------------------------------------------------------

int main( int argc, char *argv[] ) {

  std::string output_file_name;
  std::string output_format;
  std::string plate_file_name;
  int transaction_id;

  po::options_description general_options("Turns georeferenced image(s) into a TOAST quadtree.\n\nGeneral Options");
  general_options.add_options()
    ("output-format,f", po::value<std::string>(&output_format)->default_value("toast"),
     "Output tree format, one of [ toast, toast_dem, gigapan ] ")
    ("output-name,o", po::value<std::string>(&output_file_name),
     "Specify the base output directory")
    ("transaction-id,t", po::value<int>(&transaction_id)->default_value(-1),
     "Specify the transaction id to save.")
    ("help,h", "Display this help message");

  po::options_description hidden_options("");
  hidden_options.add_options()
    ("plate-file", po::value<std::string>(&plate_file_name));

  po::options_description options("Allowed Options");
  options.add(general_options).add(hidden_options);

  po::positional_options_description p;
  p.add("plate-file", -1);

  std::ostringstream usage;
  usage << "Usage: " << argv[0] << " [options] <filename>..." <<std::endl << std::endl;
  usage << general_options << std::endl;

  po::variables_map vm;
  try {
    po::store( po::command_line_parser( argc, argv ).options(options).positional(p).run(), vm );
    po::notify( vm );
  } catch (const po::error& e) {
    std::cout << "An error occurred while parsing command line arguments.\n\n";
    std::cout << usage.str();
    return 0;
  }

  if( vm.count("help") ) {
    std::cout << usage.str();
    return 0;
  }

  if( vm.count("plate-file") != 1 ) {
    VW_OUT(ErrorMessage) << "Error: must specify an input platefile!" << std::endl << std::endl;
    VW_OUT() << usage.str();
    return 1;
  }

  if( output_file_name == "" )
    output_file_name = prefix_from_filename(plate_file_name);

  // Spider across the platefile, saving all valid tiles.
  do_all_levels(plate_file_name, output_file_name, output_format, transaction_id);

  return 0;
}


text:
//==============================================================================
//         Copyright 2003 - 2011   LASMEA UMR 6602 CNRS/Univ. Clermont II
//         Copyright 2009 - 2011   LRI    UMR 8623 CNRS/Univ Paris Sud XI
//
//          Distributed under the Boost Software License, Version 1.0.
//                 See accompanying file LICENSE.txt or copy at
//                     http://www.boost.org/LICENSE_1_0.txt
//==============================================================================
#ifndef NT2_SDK_META_FUSION_HPP_INCLUDED
#define NT2_SDK_META_FUSION_HPP_INCLUDED

#include <nt2/sdk/meta/factory_of.hpp>
#include <nt2/sdk/meta/hierarchy_of.hpp>
#include <nt2/sdk/meta/primitive_of.hpp>
#include <boost/dispatch/meta/fusion.hpp>

namespace nt2 { namespace ext
{
  using boost::dispatch::meta::fusion_sequence_;
  using boost::dispatch::meta::array_;
} }

#endif

ext: hpp


text:
/**
 * This file is part of S-PTAM.
 *
 * Copyright (C) 2013-2017 Taihú Pire
 * Copyright (C) 2014-2017 Thomas Fischer
 * Copyright (C) 2016-2017 Gastón Castro
 * Copyright (C) 2017 Matias Nitsche
 * For more information see <https://github.com/lrse/sptam>
 *
 * S-PTAM is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * S-PTAM 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with S-PTAM. If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:  Taihú Pire
 *           Thomas Fischer
 *           Gastón Castro
 *           Matías Nitsche
 *
 * Laboratory of Robotics and Embedded Systems
 * Department of Computer Science
 * Faculty of Exact and Natural Sciences
 * University of Buenos Aires
 */

#ifndef __SMOOTH_ESTIMATE_PROPAGATOR_HPP__
#define __SMOOTH_ESTIMATE_PROPAGATOR_HPP__

#include <Eigen/Eigen>

// G2O
#include <g2o/config.h>
#include <g2o/types/slam3d/vertex_se3.h>
#include <g2o/types/slam3d/edge_se3.h>
#include <g2o/core/estimate_propagator.h>

/*
 * SmoothEstimatePropagator propagates edge information relaxing it while moving away of fixed vertices.
 * Uses an exponential function for this, so a vertex near fixed vertices will be moved all the way accordingly
 * with edge restriction meanwhile a vertex far away will remain in the same place.
 *
 * Note that this propagator only works with VertexSE3 and EdgeSE3.
 */
namespace g2o {
class SmoothEstimatePropagator : public g2o::EstimatePropagator
{
  public:

    SmoothEstimatePropagator(g2o::SparseOptimizer* g,
                             const double& maxDistance=std::numeric_limits<double>::max(),
                             const double& maxEdgeCost=std::numeric_limits<double>::max());

    void propagate(g2o::OptimizableGraph::Vertex* v);

  private:

    struct SmoothPropagateAction : g2o::EstimatePropagator::PropagateAction {
      public:
        SmoothPropagateAction(g2o::EstimatePropagator::AdjacencyMap* adj, const double& max_distance);

        void operator()(g2o::OptimizableGraph::Edge* e_, const g2o::OptimizableGraph::VertexSet& from_, g2o::OptimizableGraph::Vertex* to_) const;

      private:
        g2o::EstimatePropagator::AdjacencyMap* adjacency;
        double maxDistance;

        Eigen::Isometry3d exponencialInterpolation(const Eigen::Isometry3d& from, const Eigen::Isometry3d& to, double step) const;
    };

    SmoothPropagateAction _smoothAction;
    g2o::EstimatePropagator::PropagateCost _treeCost;
    double _maxDistance, _maxEdgeCost;
};
}
#endif //__SMOOTH_ESTIMATE_PROPAGATOR_HPP__


text:
/*!
@file
Defines `boost::hana::members`.

@copyright Louis Dionne 2013-2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
 */

#ifndef BOOST_HANA_MEMBERS_HPP
#define BOOST_HANA_MEMBERS_HPP

#include <boost/hana/fwd/members.hpp>

#include <boost/hana/accessors.hpp>
#include <boost/hana/concept/struct.hpp>
#include <boost/hana/config.hpp>
#include <boost/hana/core/dispatch.hpp>
#include <boost/hana/second.hpp>
#include <boost/hana/transform.hpp>

BOOST_HANA_NAMESPACE_BEGIN
    //! @cond
    template <typename Object>
    constexpr auto members_t::operator()(Object&& object) const {
        using S = typename hana::tag_of<Object>::type;
        using Members = BOOST_HANA_DISPATCH_IF(members_impl<S>,
            hana::Struct<S>::value
        );

        #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
            static_assert(hana::Struct<S>::value,
            "hana::members(object) requires 'object' to be a Struct");
        #endif

        return Members::apply(static_cast<Object&&>(object));
    }
    //! @endcond

    namespace struct_detail {
        template <typename Holder, typename Forward>
        struct members_helper {
            Holder object;
            template <typename Accessor>
            constexpr decltype(auto) operator()(Accessor&& accessor) const {
                return hana::second(static_cast<Accessor&&>(accessor))(
                    static_cast<Forward>(object)
                );
            }
        };
    }

    template <typename S, bool condition>
    struct members_impl<S, when<condition>> : default_ {
        template <typename Object>
        static constexpr auto apply(Object&& object) {
            return hana::transform(hana::accessors<S>(),
                struct_detail::members_helper<Object&, Object&&>{object}
            );
        }
    };
BOOST_HANA_NAMESPACE_END

#endif // !BOOST_HANA_MEMBERS_HPP


text:
#include "json.hpp"

#include <boost/test/unit_test.hpp>
#include <boost/algorithm/string/predicate.hpp>

#include "rocksy.hpp"
using namespace Crowd;

class RocksyT : public Rocksy
{
public:
    RocksyT(): Rocksy("usersdb") {}
};

BOOST_FIXTURE_TEST_SUITE(RocksyTests, RocksyT)

// use any protected methods inside your tests
BOOST_AUTO_TEST_CASE(PathTest)
{
    BOOST_CHECK(boost::algorithm::ends_with(usersdb_folder_path, ".config/onzehub/usersdb"));
}

BOOST_AUTO_TEST_CASE(Get)
{
    // BOOST_TEST_MESSAGE("Get: " << RocksyT::Get(1)); // ./build/tests --log_level=message
    std::string key = "1";
    BOOST_CHECK(RocksyT::Get(key) == "");
}

BOOST_AUTO_TEST_CASE(PutGetDelete)
{
    std::string key = "2";
    std::string value = "test2";
    BOOST_CHECK(RocksyT::Put(key, value) == true);
    BOOST_CHECK(RocksyT::Get(key) == "test2");
    BOOST_CHECK(RocksyT::Delete(key) == true);
    //BOOST_TEST_MESSAGE("Delete: " << RocksyT::Get("2"));
    BOOST_CHECK(RocksyT::Get(key) == "");
    RocksyT::Delete(key);
}

// BOOST_AUTO_TEST_CASE(FindChosenOne)
// {
//     std::string key1 = "1";
//     std::string key2 = "2";
//     std::string key3 = "3";
//     std::string value = "test2";
//     BOOST_CHECK(RocksyT::Put(key2, value) == true);
//     BOOST_CHECK(RocksyT::FindChosenOne(key1) == "2");
//     BOOST_CHECK(RocksyT::FindChosenOne(key2) == "2");
//     BOOST_CHECK(RocksyT::FindChosenOne(key3) == "2");
//     RocksyT::Delete(key2);
// }

BOOST_AUTO_TEST_CASE(FindNextPeer)
{
    std::string key1 = "1";
    std::string key2 = "2";
    std::string key3 = "3";
    std::string key5 = "5";
    std::string value2 = "test2";
    std::string value5 = "test5";
    BOOST_CHECK(RocksyT::Put(key2, value2) == true);
    BOOST_CHECK(RocksyT::Put(key5, value5) == true);
    BOOST_CHECK(RocksyT::FindNextPeer(key1) == "2");
    BOOST_CHECK(RocksyT::FindNextPeer(key3) == "5");
    RocksyT::Delete(key2);
    RocksyT::Delete(key5);
}

nlohmann::json j = nlohmann::json::parse("{ \"server\": true }");

BOOST_AUTO_TEST_CASE(FindServerPeer)
{
    std::string key1 = "1";
    std::string key2 = "2";
    std::string j_s = j.dump();
    BOOST_CHECK(RocksyT::Put(key2, j_s) == true);
    BOOST_CHECK(RocksyT::FindServerPeer(key1) == "2");
    BOOST_CHECK(RocksyT::FindServerPeer(key2) == "2");
    RocksyT::Delete(key2);
}

BOOST_AUTO_TEST_CASE(FindNextServerPeer)
{
    std::string key0 = "0";
    std::string key2 = "2";
    std::string key3 = "3";
    std::string j_s = j.dump();
    BOOST_CHECK(RocksyT::Put(key3, j_s) == true);
    BOOST_CHECK(RocksyT::FindNextServerPeer(key0) == "3");
    BOOST_CHECK(RocksyT::FindNextServerPeer(key2) == "3");
    RocksyT::Delete(key3);
}

BOOST_AUTO_TEST_CASE(CountPeersFromTo)
{
    std::string key0 = "0";
    std::string key1 = "1";
    std::string key2 = "2";
    std::string key3 = "3";
    std::string j_s = j.dump();
    RocksyT::Put(key0, j_s);
    RocksyT::Put(key1, j_s);
    RocksyT::Put(key2, j_s);
    RocksyT::Put(key3, j_s);
    //BOOST_TEST_MESSAGE("Count: " << RocksyT::CountPeersFromTo(key0, key0));
    BOOST_CHECK(RocksyT::CountPeersFromTo(key0, key3) == 3);
    BOOST_CHECK(RocksyT::CountPeersFromTo(key0, key0) == 4);
    RocksyT::Delete(key0);
    RocksyT::Delete(key1);
    RocksyT::Delete(key2);
    RocksyT::Delete(key3);
}

// TODO: reorder these tests --> after every test the entries should be deleted, which is not the caseder these tests --> after every test the entries should be deleted, which is not the case

BOOST_AUTO_TEST_SUITE_END()

ext: cpp

max_stars_repo_name: onzehub/onzecurrency

max_issues_repo_name: onzehub/onzecurrency

max_forks_repo_name: onzehub/onzecurrency


text:
//
// prefer_only.cpp
// ~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)

// Test that header file is self-contained.
#include <boost/asio/execution/prefer_only.hpp>

#include <boost/asio/execution/any_executor.hpp>
#include "../unit_test.hpp"

#if defined(BOOST_ASIO_HAS_BOOST_BIND)
# include <boost/bind/bind.hpp>
#else // defined(BOOST_ASIO_HAS_BOOST_BIND)
# include <functional>
#endif // defined(BOOST_ASIO_HAS_BOOST_BIND)

using namespace boost::asio;

#if defined(BOOST_ASIO_HAS_BOOST_BIND)
namespace bindns = boost;
#else // defined(BOOST_ASIO_HAS_BOOST_BIND)
namespace bindns = std;
#endif

static int possibly_blocking_count = 0;
static int never_blocking_count = 0;

struct possibly_blocking_executor
{
  template <typename F>
  void execute(const F&) const
  {
    ++possibly_blocking_count;
  }

  friend bool operator==(const possibly_blocking_executor&,
      const possibly_blocking_executor&) BOOST_ASIO_NOEXCEPT
  {
    return true;
  }

  friend bool operator!=(const possibly_blocking_executor&,
      const possibly_blocking_executor&) BOOST_ASIO_NOEXCEPT
  {
    return false;
  }
};

namespace boost {
namespace asio {
namespace traits {

#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)

template <typename F>
struct execute_member<possibly_blocking_executor, F>
{
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  typedef void result_type;
};

#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)

#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)

template <>
struct equality_comparable<possibly_blocking_executor>
{
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
};

#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)

} // namespace traits
} // namespace asio
} // namespace boost

struct never_blocking_executor
{
  static BOOST_ASIO_CONSTEXPR execution::blocking_t::never_t
    query(execution::blocking_t) BOOST_ASIO_NOEXCEPT
  {
    return execution::blocking_t::never_t();
  }

  template <typename F>
  void execute(const F&) const
  {
    ++never_blocking_count;
  }

  friend bool operator==(const never_blocking_executor&,
      const never_blocking_executor&) BOOST_ASIO_NOEXCEPT
  {
    return true;
  }

  friend bool operator!=(const never_blocking_executor&,
      const never_blocking_executor&) BOOST_ASIO_NOEXCEPT
  {
    return false;
  }
};

namespace boost {
namespace asio {
namespace traits {

#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)

template <typename F>
struct execute_member<never_blocking_executor, F>
{
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  typedef void result_type;
};

#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)

#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)

template <>
struct equality_comparable<never_blocking_executor>
{
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
};

#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)

#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)

template <typename Param>
struct query_static_constexpr_member<
  never_blocking_executor, Param,
  typename boost::asio::enable_if<
    boost::asio::is_convertible<Param, execution::blocking_t>::value
  >::type>
{
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);

  typedef execution::blocking_t::never_t result_type;

  static BOOST_ASIO_CONSTEXPR result_type value()
  {
    return result_type();
  }
};

#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)

} // namespace traits
} // namespace asio
} // namespace boost

struct either_blocking_executor
{
  execution::blocking_t blocking_;

  explicit either_blocking_executor(execution::blocking_t b)
    : blocking_(b)
  {
  }

  execution::blocking_t query(execution::blocking_t) const BOOST_ASIO_NOEXCEPT
  {
    return blocking_;
  }

  either_blocking_executor require(execution::blocking_t::possibly_t) const
  {
    return either_blocking_executor(execution::blocking.possibly);
  }

  either_blocking_executor require(execution::blocking_t::never_t) const
  {
    return either_blocking_executor(execution::blocking.never);
  }

  template <typename F>
  void execute(const F&) const
  {
    if (blocking_ == execution::blocking.never)
      ++never_blocking_count;
    else
      ++possibly_blocking_count;
  }

  friend bool operator==(const either_blocking_executor& a,
      const either_blocking_executor& b) BOOST_ASIO_NOEXCEPT
  {
    return a.blocking_ == b.blocking_;
  }

  friend bool operator!=(const either_blocking_executor& a,
      const either_blocking_executor& b) BOOST_ASIO_NOEXCEPT
  {
    return a.blocking_ != b.blocking_;
  }
};

namespace boost {
namespace asio {
namespace traits {

#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)

template <typename F>
struct execute_member<either_blocking_executor, F>
{
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  typedef void result_type;
};

#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)

#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)

template <>
struct equality_comparable<either_blocking_executor>
{
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
};

#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)

#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)

template <typename Param>
struct query_member<
  either_blocking_executor, Param,
  typename boost::asio::enable_if<
    boost::asio::is_convertible<Param, execution::blocking_t>::value
  >::type>
{
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);

  typedef execution::blocking_t result_type;
};

#if !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)

#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)

template <typename Param>
struct require_member<
  either_blocking_executor, Param,
  typename boost::asio::enable_if<
    boost::asio::is_convertible<Param, execution::blocking_t>::value
  >::type>
{
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);

  typedef either_blocking_executor result_type;
};

#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)

} // namespace traits
} // namespace asio
} // namespace boost

void prefer_only_executor_query_test()
{
  typedef execution::any_executor<
      execution::blocking_t,
      execution::prefer_only<execution::blocking_t::possibly_t>,
      execution::prefer_only<execution::blocking_t::never_t>
    > executor_type;

  executor_type ex1 = possibly_blocking_executor();

  BOOST_ASIO_CHECK(
      boost::asio::query(ex1, execution::blocking)
        == execution::blocking.possibly);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex1, execution::blocking.possibly)
        == execution::blocking.possibly);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex1, execution::blocking.never)
        == execution::blocking.possibly);

  executor_type ex2 = boost::asio::prefer(ex1, execution::blocking.possibly);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex2, execution::blocking)
        == execution::blocking.possibly);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex2, execution::blocking.possibly)
        == execution::blocking.possibly);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex2, execution::blocking.never)
        == execution::blocking.possibly);

  executor_type ex3 = boost::asio::prefer(ex1, execution::blocking.never);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex3, execution::blocking)
        == execution::blocking.possibly);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex3, execution::blocking.possibly)
        == execution::blocking.possibly);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex3, execution::blocking.never)
        == execution::blocking.possibly);

  executor_type ex4 = never_blocking_executor();

  BOOST_ASIO_CHECK(
      boost::asio::query(ex4, execution::blocking)
        == execution::blocking.never);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex4, execution::blocking.possibly)
        == execution::blocking.never);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex4, execution::blocking.never)
        == execution::blocking.never);

  executor_type ex5 = boost::asio::prefer(ex4, execution::blocking.possibly);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex5, execution::blocking)
        == execution::blocking.never);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex5, execution::blocking.possibly)
        == execution::blocking.never);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex5, execution::blocking.never)
        == execution::blocking.never);

  executor_type ex6 = boost::asio::prefer(ex4, execution::blocking.never);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex6, execution::blocking)
        == execution::blocking.never);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex6, execution::blocking.possibly)
        == execution::blocking.never);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex6, execution::blocking.never)
        == execution::blocking.never);

  executor_type ex7 = either_blocking_executor(execution::blocking.possibly);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex7, execution::blocking)
        == execution::blocking.possibly);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex7, execution::blocking.possibly)
        == execution::blocking.possibly);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex7, execution::blocking.never)
        == execution::blocking.possibly);

  executor_type ex8 = boost::asio::prefer(ex7, execution::blocking.possibly);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex8, execution::blocking)
        == execution::blocking.possibly);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex8, execution::blocking.possibly)
        == execution::blocking.possibly);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex8, execution::blocking.never)
        == execution::blocking.possibly);

  executor_type ex9 = boost::asio::prefer(ex7, execution::blocking.never);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex9, execution::blocking)
        == execution::blocking.never);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex9, execution::blocking.possibly)
        == execution::blocking.never);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex9, execution::blocking.never)
        == execution::blocking.never);

  executor_type ex10 = either_blocking_executor(execution::blocking.never);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex10, execution::blocking)
        == execution::blocking.never);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex10, execution::blocking.possibly)
        == execution::blocking.never);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex10, execution::blocking.never)
        == execution::blocking.never);

  executor_type ex11 = boost::asio::prefer(ex7, execution::blocking.possibly);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex11, execution::blocking)
        == execution::blocking.possibly);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex11, execution::blocking.possibly)
        == execution::blocking.possibly);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex11, execution::blocking.never)
        == execution::blocking.possibly);

  executor_type ex12 = boost::asio::prefer(ex7, execution::blocking.never);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex12, execution::blocking)
        == execution::blocking.never);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex12, execution::blocking.possibly)
        == execution::blocking.never);

  BOOST_ASIO_CHECK(
      boost::asio::query(ex12, execution::blocking.never)
        == execution::blocking.never);
}

void do_nothing()
{
}

void prefer_only_executor_execute_test()
{
  typedef execution::any_executor<
      execution::blocking_t,
      execution::prefer_only<execution::blocking_t::possibly_t>,
      execution::prefer_only<execution::blocking_t::never_t>
    > executor_type;

  executor_type ex1 = possibly_blocking_executor();

  execution::execute(ex1, &do_nothing);
  BOOST_ASIO_CHECK(possibly_blocking_count == 1);
  BOOST_ASIO_CHECK(never_blocking_count == 0);

  executor_type ex2 = boost::asio::prefer(ex1, execution::blocking.possibly);

  execution::execute(ex2, &do_nothing);
  BOOST_ASIO_CHECK(possibly_blocking_count == 2);
  BOOST_ASIO_CHECK(never_blocking_count == 0);

  executor_type ex3 = boost::asio::prefer(ex1, execution::blocking.never);

  execution::execute(ex3, &do_nothing);
  BOOST_ASIO_CHECK(possibly_blocking_count == 3);
  BOOST_ASIO_CHECK(never_blocking_count == 0);

  executor_type ex4 = never_blocking_executor();

  execution::execute(ex4, &do_nothing);
  BOOST_ASIO_CHECK(possibly_blocking_count == 3);
  BOOST_ASIO_CHECK(never_blocking_count == 1);

  executor_type ex5 = boost::asio::prefer(ex4, execution::blocking.possibly);

  execution::execute(ex5, &do_nothing);
  BOOST_ASIO_CHECK(possibly_blocking_count == 3);
  BOOST_ASIO_CHECK(never_blocking_count == 2);

  executor_type ex6 = boost::asio::prefer(ex4, execution::blocking.never);

  execution::execute(ex6, &do_nothing);
  BOOST_ASIO_CHECK(possibly_blocking_count == 3);
  BOOST_ASIO_CHECK(never_blocking_count == 3);

  executor_type ex7 = either_blocking_executor(execution::blocking.possibly);

  execution::execute(ex7, &do_nothing);
  BOOST_ASIO_CHECK(possibly_blocking_count == 4);
  BOOST_ASIO_CHECK(never_blocking_count == 3);

  executor_type ex8 = boost::asio::prefer(ex7, execution::blocking.possibly);

  execution::execute(ex8, &do_nothing);
  BOOST_ASIO_CHECK(possibly_blocking_count == 5);
  BOOST_ASIO_CHECK(never_blocking_count == 3);

  executor_type ex9 = boost::asio::prefer(ex7, execution::blocking.never);

  execution::execute(ex9, &do_nothing);
  BOOST_ASIO_CHECK(possibly_blocking_count == 5);
  BOOST_ASIO_CHECK(never_blocking_count == 4);

  executor_type ex10 = either_blocking_executor(execution::blocking.never);

  execution::execute(ex10, &do_nothing);
  BOOST_ASIO_CHECK(possibly_blocking_count == 5);
  BOOST_ASIO_CHECK(never_blocking_count == 5);

  executor_type ex11 = boost::asio::prefer(ex7, execution::blocking.possibly);

  execution::execute(ex11, &do_nothing);
  BOOST_ASIO_CHECK(possibly_blocking_count == 6);
  BOOST_ASIO_CHECK(never_blocking_count == 5);

  executor_type ex12 = boost::asio::prefer(ex7, execution::blocking.never);

  execution::execute(ex12, &do_nothing);
  BOOST_ASIO_CHECK(possibly_blocking_count == 6);
  BOOST_ASIO_CHECK(never_blocking_count == 6);
}

BOOST_ASIO_TEST_SUITE
(
  "prefer_only",
  BOOST_ASIO_TEST_CASE(prefer_only_executor_query_test)
  BOOST_ASIO_TEST_CASE(prefer_only_executor_execute_test)
)


text:
#include "WebSocket.h"

#include <boost/asio/placeholders.hpp>
#include <boost/bind.hpp>

void WebSocket::asyncConnect(tcp::resolver::iterator it)
{
	this->resetWS();
	boost::asio::async_connect(this->getWS()->next_layer(), it, boost::bind(&WebSocket::socketConnected, this, boost::placeholders::_1, boost::placeholders::_2));
}

void WebSocket::asyncHandshake(std::string host, std::string path, std::function<void(websocket::request_type&)> decorator)
{
	this->getWS()->async_handshake_ex(host, path, decorator, boost::bind(&WebSocket::handshakeCompleted, this, boost::placeholders::_1));
}

void WebSocket::asyncRead()
{
	this->getWS()->async_read(this->readBuffer, boost::bind(&WebSocket::onRead, this, boost::placeholders::_1, boost::placeholders::_2));
}

void WebSocket::asyncWrite(std::string message)
{
	this->getWS()->async_write(boost::asio::buffer(message), boost::bind(&WebSocket::onWrite, this, boost::placeholders::_1, boost::placeholders::_2));
}

void WebSocket::closeSocket()
{
	this->getWS()->lowest_layer().close();
}

void WebSocket::asyncCloseSocket()
{
	this->getWS()->async_close(websocket::close_code::none, boost::bind(&WebSocket::onDisconnected, this, boost::placeholders::_1));
}


text:
//
// Created by erik on 2/9/18.
//

#include <boost/test/unit_test.hpp>
#include "factory/factory.hpp"
#include "factory/builder_base.hpp"
#include "test_helpers.hpp"

struct TestBuilder : public factory::BuilderBase<int, float>
{
    TestBuilder() : BuilderBase("test") {
        args() << args::ArgumentSpec("arg").store(argument);
        args().description("description");
    }

    int create(float extra)
    {
        return 5 + (int)extra + argument;
    }

    int argument = -1;
};

BOOST_AUTO_TEST_SUITE(factory_tests)

    BOOST_AUTO_TEST_CASE(builder_base) {
        TestBuilder test;

        std::vector<std::string> tokens = {"arg", "6"};

        BOOST_CHECK_EQUAL(test.name(), "test");
        BOOST_CHECK_EQUAL(test(tokens, 3.0f), 14);
    }

    BOOST_AUTO_TEST_CASE(factory_double_add) {
        factory::Factory<TestBuilder> fac;
        fac.add_builder<TestBuilder>();
        BOOST_CHECK_EXCEPTION(fac.add_builder<TestBuilder>(), std::logic_error,
                              check_what("A builder for type 'test' is already registered."));
    }

    BOOST_AUTO_TEST_CASE(factory_test) {
        factory::Factory<TestBuilder> fac;
        BOOST_CHECK(fac.getTypes().empty());

        fac.add_builder<TestBuilder>();
        BOOST_CHECK(fac.getTypes() == std::vector<std::string>{"test"});

        // exception on non-existing builder.
        BOOST_CHECK_EXCEPTION(fac.get_builder("other"), std::runtime_error,
                              check_what("Unknown factory for type 'other' requested!"));
        BOOST_CHECK_EXCEPTION(fac.create("other", {"arg"}, 1.5f), std::runtime_error,
                              check_what("Unknown factory for type 'other' requested!"));
        BOOST_CHECK_EXCEPTION(fac.get_arguments("other"), std::runtime_error,
                              check_what("Unknown factory for type 'other' requested!"));
        BOOST_CHECK_EXCEPTION(fac.getHelp("other"), std::runtime_error,
                              check_what("Unknown factory for type 'other' requested!"));

        BOOST_CHECK_EQUAL(fac.get_arguments("test").name(), "test");

        std::string help_msg =  "test arg INTEGER\n"
                                "description\n"
                                "arg (Integer)\n";
        BOOST_CHECK_EQUAL(fac.getHelp("test"), help_msg);

        auto creation = fac.create("test", {"arg", "6"}, 1.f);
        BOOST_CHECK_EQUAL(creation, 12);
    }

BOOST_AUTO_TEST_SUITE_END()


text:
#ifndef __BOOST_PYTHON_STDCON_FORWARD_LIST_ARG_INCLUDED__
#define __BOOST_PYTHON_STDCON_FORWARD_LIST_ARG_INCLUDED__
#include <boost/python.hpp>
#include <forward_list>

namespace boost::python {
  namespace stdcon {
    template<typename C>
    struct forward_list_copied_from_python
    {
      typedef C result_type;
      typedef typename C::value_type value_type;

      typedef arg_from_python<value_type> element_converter_type;

      forward_list_copied_from_python(PyObject *pyobj) : m_pyobj(pyobj) {}

      bool convertible() const {
        // == true when m_pyobj is a Python list and all its elements
        // are convertible to value_type
        if (!PyList_Check(m_pyobj))
          return false;
        for (Py_ssize_t i = 0; i < PyList_Size(m_pyobj); ++i) {
          if (!element_converter_type(PyList_GetItem(m_pyobj, i)).convertible())
            return false;
        }
        return true;
      }

      result_type operator()() const {
        result_type flist;
        for (Py_ssize_t i = PyList_Size(m_pyobj); i != 0;) {
          --i;
          flist.push_front(element_converter_type(PyList_GetItem(m_pyobj, i))());
        }
        return flist;
      }
    private:
      PyObject *m_pyobj;
    };
  }

  template<typename T, typename A>
  struct arg_from_python<std::forward_list<T, A> const &> :
    stdcon::forward_list_copied_from_python<std::forward_list<T, A>>
  {
    typedef stdcon::forward_list_copied_from_python<std::forward_list<T, A>> base_type;
    arg_from_python(PyObject *pyobj) : base_type(pyobj) {}
  };
  template<typename T, typename A>
  struct arg_from_python<std::forward_list<T, A> &&> :
    stdcon::forward_list_copied_from_python<std::forward_list<T, A>>
  {
    typedef stdcon::forward_list_copied_from_python<std::forward_list<T, A>> base_type;
    arg_from_python(PyObject *pyobj) : base_type(pyobj) {}
  };
  template<typename T, typename A>
  struct arg_from_python<std::forward_list<T, A>> :
    stdcon::forward_list_copied_from_python<std::forward_list<T, A>>
  {
    typedef stdcon::forward_list_copied_from_python<std::forward_list<T, A>> base_type;
    arg_from_python(PyObject *pyobj) : base_type(pyobj) {}
  };

  namespace converter {
    template<typename T, typename A>
    struct expected_pytype_for_arg<std::forward_list<T, A> const&> : expecting_pylist {};
    template<typename T, typename A>
    struct expected_pytype_for_arg<std::forward_list<T, A> &&> : expecting_pylist {};
    template<typename T, typename A>
    struct expected_pytype_for_arg<std::forward_list<T, A>> : expecting_pylist {};
  }
}
#endif

max_stars_repo_name: yjwen/boost-python-stdcon

max_issues_repo_name: yjwen/boost-python-stdcon

max_forks_repo_name: yjwen/boost-python-stdcon


text: #include <boost/beast/core/read_size.hpp>

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino


text:
//  Copyright (c) 2021, Qualcomm Innovation Center, Inc. All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//  1. Redistributions of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//
//  2. Redistributions in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//
//  3. Neither the name of the copyright holder nor the names of its contributors
//     may be used to endorse or promote products derived from this software
//     without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
//  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
//  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
//  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
//  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
//  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
//  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
//  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
//  POSSIBILITY OF SUCH DAMAGE.
//
//  SPDX-License-Identifier: BSD-3-Clause

#define _GNU_SOURCE 1

#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <memory.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#include <sys/uio.h>

#include <iostream>
#include <chrono>

#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/count.hpp>
#include <boost/accumulators/statistics/max.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/accumulators/statistics/min.hpp>
#include <boost/accumulators/statistics/variance.hpp>
#include <boost/accumulators/statistics/stats.hpp>

#include "iodme/mover.hpp"

namespace bacc = boost::accumulators;

// Needed for older ubuntu that do not have memfd in the glibc
#ifndef MFD_HUGETLB
#define MFD_HUGETLB		0x0004U
#endif
int memfd_create(const char *name, unsigned int flags)
{
	return syscall(SYS_memfd_create, name, 0);
}

int main(int argc, char **argv)
{
	size_t buf_size = 1ULL * 1024 * 1024 * 1024;
	bool use_splice = false;
	bool use_memfd  = false;

	unsigned int mmap_flags = MAP_ANONYMOUS | MAP_PRIVATE;
	unsigned int open_flags = O_CREAT | O_TRUNC | O_WRONLY;

	std::string ofile("/disk/speed-test/vmsplice-out");

	for (int i=1; i < argc; i++) {
		std::string arg(argv[i]);

		if (arg == "use_memfd")  { use_memfd = true; continue; }
		if (arg == "use_splice") { use_splice = true; continue; }
		if (arg == "use_hugepages") { mmap_flags |= MAP_HUGETLB;   continue; }
		if (arg == "use_directio") { open_flags |= O_DIRECT;   continue; }
		if (arg == "1GB") { buf_size = 1ULL * 1024 * 1024 * 1024;  continue; }
		if (arg == "2GB") { buf_size = 2ULL * 1024 * 1024 * 1024;  continue; }

		ofile = arg;
	}

	// Allocate main buffer
	int buf_fd = -1;

	if (use_memfd) {
		buf_fd = memfd_create("file-write-tests.memfd", MFD_HUGETLB);
		if (buf_fd == -1) {
			std::cerr << "memfd open failed: " << strerror(errno) << '\n';
			exit(1);
		}

		if (ftruncate(buf_fd, buf_size) == -1) {
			std::cerr << "memfd open failed: " << strerror(errno) << '\n';
			exit(1);
		}
	}

	uint8_t *buf = (uint8_t *) mmap(NULL, buf_size, PROT_READ | PROT_WRITE, mmap_flags, buf_fd, 0);
	if (buf == MAP_FAILED) {
		std::cerr << "mmap failed: " << strerror(errno) << '\n';
		exit(1);
	}

        std::cout << "buffer size: " << buf_size << " bytes\n";

	iodme::mover s;
	if (s.failed())
		exit(1);

	bacc::accumulator_set< double, bacc::stats<
            bacc::tag::min,
            bacc::tag::max,
            bacc::tag::mean,
            bacc::tag::variance > > stats;

	for (unsigned int i=0; i < 20; i++) {
		int fd = open(ofile.c_str(), open_flags, 0666);
		if (fd < 0) {
			std::cerr << "open " << ofile << " failed: " << strerror(errno) << '\n';
			exit(1);
		}

		memset(buf, 0, buf_size);

		struct iovec iov;
		iov.iov_base = buf;
		iov.iov_len  = buf_size;

		auto start = std::chrono::high_resolution_clock::now();
		if (use_memfd) {
			bool r = s.do_write(fd, buf_fd, buf_size);
			if (!r) {
				std::cerr << "splice/write failed: " << strerror(s.last_errno()) << '\n';
				exit(1);
			}
		} else if (use_splice) {
			bool r = s.do_write(fd, &iov, 1);
			if (!r) {
				std::cerr << "splice/write failed: " << strerror(s.last_errno()) << '\n';
				exit(1);
			}
		} else {
			int r = writev(fd, &iov, 1);
			if (r < 0) {
				std::cerr << "write failed: " << strerror(errno) << '\n';
				exit(1);
			}
		}
        	auto end = std::chrono::high_resolution_clock::now();

        	std::chrono::duration<double> diff = end - start;
		stats(diff.count());

		fsync(fd);
		posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
		close(fd);
	}

        std::cout << "stats: "
	       	<< " min " << bacc::min(stats)
	       	<< " max " << bacc::max(stats)
	       	<< " avg " << bacc::mean(stats)
		<< " sec per write/splice\n";

	(void) munmap(buf, buf_size);
	close(buf_fd);
}

ext: cc

max_stars_repo_name: maxk-org/iodme

max_issues_repo_name: maxk-org/iodme

max_forks_repo_name: maxk-org/iodme


text:
/**
 * @author Eric Cousineau <eacousineau@gmail.com>, member of Dr. Aaron
 * Ames's AMBER Lab
 */
#ifndef EIGEN_UTILITIES_CONTAINER_UTILITIES_H
    #define EIGEN_UTILITIES_CONTAINER_UTILITIES_H

#include <Eigen/Dense>

#include <eigen_utilities/assert_size.hpp>

namespace eigen_utilities
{

template<typename DerivedA, typename DerivedB, typename Container>
void select_rows(const Eigen::MatrixBase<DerivedA> &in, const Container &indices, Eigen::MatrixBase<DerivedB> &out)
{
    assert_size(out, indices.size(), in.cols());
    for (int i = 0; i < indices.size(); ++i)
    {
        int ix = indices[i];
        common_assert_msg(ix >= 0 && ix < in.rows(), "ix: " << ix << ", in: " << in.rows());
        out.row(i) = in.row(ix);
    }
}

template<typename DerivedA, typename DerivedB, typename Container>
void select_rows_resize(const Eigen::MatrixBase<DerivedA> &in, const Container &indices, Eigen::MatrixBase<DerivedB> &out)
{
    out.derived().resize(indices.size(), in.cols());
    select_rows(in, indices, out);
}

template<typename DerivedA, typename DerivedB, typename Container>
void select_cols(const Eigen::MatrixBase<DerivedA> &in, const Container &indices, Eigen::MatrixBase<DerivedB> &out)
{
    assert_size(out, in.rows(), indices.size());
    for (int i = 0; i < indices.size(); ++i)
    {
        int ix = indices[i];
        common_assert_msg(ix >= 0 && ix < in.cols(), "ix: " << ix << ", in: " << in.cols());
        out.col(i) = in.col(ix);
    }
}

template<typename DerivedA, typename DerivedB, typename Container>
void select_cols_resize(const Eigen::MatrixBase<DerivedA> &in, const Container &indices, Eigen::MatrixBase<DerivedB> &out)
{
    out.derived().resize(in.rows(), indices.size());
    select_cols(in, indices, out);
}

template<typename DerivedA, typename DerivedB, typename ContainerA, typename ContainerB>
void select_grid(const Eigen::MatrixBase<DerivedA> &in, const ContainerA &rows, const ContainerB &cols, Eigen::MatrixBase<DerivedB> &out)
{
    assert_size(out, rows.size(), cols.size());
    for (int i = 0; i < rows.size(); ++i)
    {
        for (int j = 0; j < cols.size(); ++j)
            out(i, j) = in(rows[i], cols[j]);
    }
}

template<typename DerivedA, typename DerivedB, typename ContainerA, typename ContainerB>
void select_grid_resize(const Eigen::MatrixBase<DerivedA> &in, const ContainerA &rows, const ContainerB &cols, Eigen::MatrixBase<DerivedB> &out)
{
    out.derived().resize(rows.size(), cols.size());
    select_grid(in, rows, cols, out);
}

template<typename DerivedA, typename DerivedB, typename Container>
void select_rows_reverse(const Eigen::MatrixBase<DerivedA> &in, const Container &indices, Eigen::MatrixBase<DerivedB> &out)
{
    assert_size(in, indices.size(), in.cols());
    for (int i = 0; i < indices.size(); ++i)
    {
        int ox = indices[i];
        common_assert_msg(ox >= 0 && ox < out.rows(), "ox: " << ox << ", out: " << out.rows());
        out.row(ox) = in.row(i);
    }
}

template<typename DerivedA, typename DerivedB, typename Container>
void select_cols_reverse(const Eigen::MatrixBase<DerivedA> &in, const Container &indices, Eigen::MatrixBase<DerivedB> &out)
{
    assert_size(in, in.rows(), indices.size());
    for (int i = 0; i < indices.size(); ++i)
    {
        int ox = indices[i];
        common_assert_msg(ox >= 0 && ox < out.cols(), "ox: " << ox << ", out: " << out.cols());
        out.col() = in.col(i);
    }
}

template<typename DerivedA, typename DerivedB, typename ContainerA, typename ContainerB>
void select_rows(const Eigen::MatrixBase<DerivedA> &in, const ContainerA &in_indices, Eigen::MatrixBase<DerivedB> &out, const ContainerB &out_indices)
{
    assert_size_vector(out_indices, in_indices.size());
    for (int i = 0; i < in_indices.size(); ++i)
    {
        int ix = in_indices[i];
        int ox = out_indices[i];
        common_assert_msg(ix >= 0 && ix < in.rows(), "ix: " << ix << ", in: " << in.rows());
        common_assert_msg(ox >= 0 && ox < out.rows(), "ox: " << ox << ", out: " << out.rows());
        out.row(ox) = in.row(ix);
    }
}

template<typename DerivedA, typename DerivedB, typename ContainerA, typename ContainerB>
void select_cols(const Eigen::MatrixBase<DerivedA> &in, const ContainerA &in_indices, Eigen::MatrixBase<DerivedB> &out, const ContainerB &out_indices)
{
    assert_size_vector(out_indices, in_indices.size());
    for (int i = 0; i < in_indices.size(); ++i)
    {
        int ix = in_indices[i];
        int ox = out_indices[i];
        common_assert_msg(ix >= 0 && ix < in.cols(), "ix: " << ix << ", in: " << in.cols());
        common_assert_msg(ox >= 0 && ox < out.cols(), "ox: " << ox << ", out: " << out.cols());
        out.col(ox) = in.col(ix);
    }
}

}

#endif // EIGEN_UTILITIES_CONTAINER_UTILITIES_H


text:
#include "nvim/connection.h"

#include "nvim/exceptions.h"

#include <boost/asio/io_context.hpp>

using namespace boost;

namespace nvim {

types::connection connect_tcp(const std::string& path, int port)
{
    auto io_context{ std::make_unique<asio::io_context>() };
    std::unique_ptr<asio::ip::tcp::socket> socket{ new asio::ip::tcp::socket{
      *io_context } };
    asio::ip::tcp::endpoint endpoint{ asio::ip::address::from_string(path),
                                      static_cast<asio::ip::port_type>(port) };
    system::error_code ec;
    socket->connect(endpoint, ec);
    if (ec) {
        socket->close();
        throw nvim::exceptions::connection_error{ ec };
    }

    return types::connection{ std::move(socket), std::move(io_context) };
}
}

max_stars_repo_name: Furkanzmc/nvim-cpp

max_issues_repo_name: Furkanzmc/nvim-cpp

max_forks_repo_name: Furkanzmc/nvim-cpp


text:
/**
 * Copyright Soramitsu Co., Ltd. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0
 */
#ifndef IROHA_LAUNCHERS_HPP
#define IROHA_LAUNCHERS_HPP

#include <boost/process.hpp>
#include <chrono>
#include <string>
#include "backend/protobuf/queries/proto_query.hpp"
#include "backend/protobuf/transaction.hpp"
#include "cryptography/keypair.hpp"

namespace binary_test {

  /**
   * Specifies interface for running language-dependent generators of
   * transactions' and queries' binaries for test cases.
   */
  class Launcher {
   public:
    /**
     * Composes language-dependent command for launching a script for a certain
     * test case.
     *
     * @param test_case - name of test case
     * @return - string, a command to be executed
     */
    virtual std::string launchCommand(const std::string &test_case) = 0;

    /**
     * Runs external binaries generator for a specific test_case and consumes
     * its output. Initializes admin_key, transactions vector, and queries
     * vector fields.
     *
     * @param example - name of test_case scenario
     */
    void operator()(const std::string &example);

    /**
     * Asserts that amount of received transactions and queries equals to
     * expected values.
     *
     * @param transactions_expected - expected amount of transactions
     * @param queries_expected - expected amount of queries
     * @return - assertion result
     */
    bool initialized(const unsigned &transactions_expected = 0,
                     const unsigned &queries_expected = 0);

    boost::optional<shared_model::crypto::Keypair> admin_key;
    std::vector<shared_model::proto::Transaction> transactions;
    std::vector<shared_model::proto::Query> queries;

   protected:
    /**
     * Parses binaries generator output and initalizes class fields.
     *
     * @param stream - standard output of external binaries generator.
     *     It is expected that entities are divided by newline separator.
     *     The first entity is expected to be a binary of admin's keypair.
     *     The next lines are transactions' or queries' binaries.
     *     The first read transaction will be considered as genesis transaction.
     */
    void readBinaries(boost::process::ipstream &stream);
    void checkAsserts(const unsigned &transactions_expected,
                      const unsigned &queries_expected);
  };

  class PythonLauncher : public Launcher {
   public:
    std::string launchCommand(const std::string &example) override;
  };

  class JavaLauncher : public Launcher {
   public:
    std::string launchCommand(const std::string &example) override;
  };

}  // namespace binary_test

#endif  // IROHA_LAUNCHERS_HPP

max_stars_repo_name: truongnmt/iroha

max_issues_repo_name: truongnmt/iroha

max_forks_repo_name: truongnmt/iroha


text:
// NrField.cpp
// created by Kuangdai on 13-May-2016
// base class of nr integer field

#include "NrField.h"
#include "ConstNrField.h"
#include "EmpNrField.h"
#include "WisdomNrField.h"
#include "UserNrField.h"

#include "Parameters.h"
#include "XMPI.h"
#include <boost/algorithm/string.hpp>

void NrField::buildInparam(NrField *&nrf, const Parameters &par, int verbose) {
    if (nrf) {
        delete nrf;
    }

    std::string type = par.getValue<std::string>("NU_TYPE");
    bool useLucky = par.getValue<bool>("FFTW_LUCKY_NUMBER");

    if (boost::iequals(type, "constant")) {
        int nu = par.getValue<int>("NU_CONST");
        nrf = new ConstNrField(useLucky, nu);
    } else if (boost::iequals(type, "empirical")) {
        int nu_ref = par.getValue<int>("NU_EMP_REF");
        int nu_min = par.getValue<int>("NU_EMP_MIN");
        bool scaleS = par.getValue<bool>("NU_EMP_SCALE_AXIS");
        bool scaleT = par.getValue<bool>("NU_EMP_SCALE_THETA");
        bool scaleD = par.getValue<bool>("NU_EMP_SCALE_DEPTH");
        double powS = par.getValue<double>("NU_EMP_POW_AXIS");
        double factPI = par.getValue<double>("NU_EMP_FACTOR_PI");
        double startT = par.getValue<double>("NU_EMP_THETA_START") * degree;
        double powT = par.getValue<double>("NU_EMP_POW_THETA");
        double factD0 = par.getValue<double>("NU_EMP_FACTOR_SURF");
        double startD = par.getValue<double>("NU_EMP_DEPTH_START") * 1e3;
        double endD = par.getValue<double>("NU_EMP_DEPTH_END") * 1e3;
        nrf = new EmpNrField(useLucky, nu_ref, nu_min, scaleS, scaleT, scaleD,
            powS, factPI, startT, powT, factD0, startD, endD);
    } else if (boost::iequals(type, "wisdom")) {
        std::string fname = Parameters::sInputDirectory + "/" + par.getValue<std::string>("NU_WISDOM_REUSE_INPUT");
        double factor = par.getValue<double>("NU_WISDOM_REUSE_FACTOR");
        if (factor <= tinyDouble) {
            factor = 1.0;
        }
        nrf = new WisdomNrField(useLucky, fname, factor);
    } else if (boost::iequals(type, "user-defined")) {
        int nsize = par.getSize("NU_USER_PARAMETER_LIST");
        std::vector<double> params;
        for (int ipar = 0; ipar < nsize; ipar++) {
            double param = par.getValue<double>("NU_USER_PARAMETER_LIST", ipar);
            params.push_back(param);
        }
        nrf = new UserNrField(useLucky, params);
    } else {
        throw std::runtime_error("NrField::build || "
            "Invalid parameter, keyword = NU_TYPE.");
    }

    if (verbose) {
        XMPI::cout << nrf->verbose();
    }
}


text:
//
//=======================================================================
// Author: Jeremiah Willcock
//
// Copyright 2012, Trustees of Indiana University
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================
//

#include <boost/property_map/function_property_map.hpp>
#include <boost/concept_check.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/test/minimal.hpp>
#include <boost/static_assert.hpp>

template <typename T>
struct add1 {typedef T result_type; T operator()(const T& x) const {return x + 1;}};

template <typename T>
struct add1_val {typedef T result_type; T operator()(T x) const {return x + 1;}};

template <typename T>
struct return_fixed_ref {
  int* ptr;
  return_fixed_ref(int* ptr): ptr(ptr) {}
  typedef int& result_type;
  int& operator()(const T&) const {return *ptr;}
};

int test_main(int, char**) {
  using namespace boost;
  function_requires<ReadablePropertyMapConcept<function_property_map<add1<int>, int>, int> >();
  function_requires<ReadablePropertyMapConcept<function_property_map<add1<int>, int, double>, int> >();
  function_requires<ReadablePropertyMapConcept<function_property_map<add1_val<int>, int>, int> >();
  function_requires<ReadablePropertyMapConcept<function_property_map<add1_val<int>, int, double>, int> >();
  function_requires<ReadablePropertyMapConcept<function_property_map<return_fixed_ref<int>, int>, int> >();
  function_requires<WritablePropertyMapConcept<function_property_map<return_fixed_ref<int>, int>, int> >();
  function_requires<ReadWritePropertyMapConcept<function_property_map<return_fixed_ref<int>, int>, int> >();
  function_requires<LvaluePropertyMapConcept<function_property_map<return_fixed_ref<int>, int>, int> >();

  BOOST_STATIC_ASSERT((boost::is_same<boost::property_traits<function_property_map<add1<int>, int> >::category, boost::readable_property_map_tag>::value));
  BOOST_STATIC_ASSERT((boost::is_same<boost::property_traits<function_property_map<add1_val<int>, int> >::category, boost::readable_property_map_tag>::value));
  BOOST_STATIC_ASSERT((boost::is_same<boost::property_traits<function_property_map<return_fixed_ref<int>, int> >::category, boost::lvalue_property_map_tag>::value));

  BOOST_CHECK(get(function_property_map<add1<int>, int>(), 3) == 4);
  BOOST_CHECK(get(function_property_map<add1<int>, int>(add1<int>()), 4) == 5);
  BOOST_CHECK(get(make_function_property_map<int>(add1<int>()), 5) == 6);
  BOOST_CHECK(get(function_property_map<add1_val<int>, int>(), 3) == 4);
  BOOST_CHECK(get(function_property_map<add1_val<int>, int>(add1_val<int>()), 4) == 5);
  BOOST_CHECK(get(make_function_property_map<int>(add1_val<int>()), 5) == 6);
  int val;
  const function_property_map<return_fixed_ref<int>, int> pm = return_fixed_ref<int>((&val));
  put(pm, 1, 6);
  BOOST_CHECK(get(pm, 2) == 6);
  BOOST_CHECK((get(pm, 3) = 7) == 7);
  BOOST_CHECK(get(pm, 4) == 7);
  const function_property_map<return_fixed_ref<int>, int> pm2 = pm; // Check shallow copying
  BOOST_CHECK(get(pm2, 5) == 7);
  put(pm2, 3, 1);
  BOOST_CHECK(get(pm, 1) == 1);

  return 0;
}

max_stars_repo_name: Abce/boost


text:
#include <armadillo>

#include "ema/Ema.h"
#include "ema-modify/ApplyModifications.h"

#include "settings.h"
#include "Tracker.h"
#include "Weights.h"
#include "mesh/MeshIO.h"
#include "mesh/Mesh.h"
#include "model/ModelReader.h"

int main(int argc, char* argv[]) {

  Settings settings(argc, argv);

  Ema ema;

  ema.read().from(settings.inputFileName);

  // reduce ema data to selected coil subset
  ema.reduce_coil_set().to(settings.channels);

  if(settings.applyModifications == true) {

    emaModify::ApplyModifications(ema).apply(settings.emaModifications);

  }

  ModelReader modelReader(settings.model);
  Model model = modelReader.get_model();
  TrackerData trackerData(model, settings);
  trackerData.sourceIds = settings.sourceIds;

  Tracker tracker(trackerData);
  tracker.update().for_source_ids();

  // fix speaker and create PCA model if desired
  if( settings.fixSpeaker ) {

    const arma::vec speakerWeights = Weights::read(settings.fixedSpeakerWeights);
    tracker.update().to_fixed_speaker(speakerWeights);

  }

  for(int i = 0; i < ema.info().sample_amount(); ++i) {

    // update data for current time frame
    tracker.data().target = ema.point_cloud().from(settings.channels, i);
    tracker.data().currentTime = ema.info().time_stamps().at(i);

    tracker.fitting().fit();

  }

  Json::Value loggedData = tracker.logger().get_logged_data();

  std::ofstream outFile(settings.outputFileName);

  outFile << loggedData << std::endl;

  outFile.close();

  return 0;

}

max_stars_repo_name: ahewer/mri-shape-tools

max_issues_repo_name: ahewer/mri-shape-tools

max_forks_repo_name: ahewer/mri-shape-tools


text:
//! \file
//! \brief
//!
//! Primary Author:  Dylan Leeman

#ifndef AUTONOMY_INSTRUCTION_LIST_HPP
#define AUTONOMY_INSTRUCTION_LIST_HPP
#include <vector>

#include <boost/shared_ptr.hpp>

#include <autonomy/script_instruction.hpp>

namespace autonomy {
    typedef std::vector< boost::shared_ptr< script_instruction > > instruction_list;

    inline
    instruction_list operator + (const instruction_list& left,
                                 const instruction_list& right)
    {
        instruction_list il(left);
        il.insert(il.end(), right.begin(), right.end());
        return il;
    }

    template < typename ptr_type >
    inline
    instruction_list operator + (const ptr_type left,
                                 const instruction_list& right)
    {
        instruction_list il(right);
        il.insert(il.begin(), boost::shared_ptr< script_instruction >(left));
        return il;
    }

    template < typename ptr_type >
    inline
    instruction_list& operator += (instruction_list& left, const ptr_type right)
    {
        left.push_back(boost::shared_ptr< script_instruction >(right));
        return left;
    }

    template < typename ptr_type >
    inline
    instruction_list operator + (const instruction_list& left,
                                 const ptr_type right)
    {
        instruction_list il(left);
        il += right;
        return il;
    }

    template < typename ptr_type >
    inline
    instruction_list inst_list(const ptr_type inst)
    {
        return instruction_list(1, boost::shared_ptr< script_instruction >(inst));
    }

    bool operator== (instruction_list const& left,
                     instruction_list const& right);

    bool operator!= (instruction_list const& left,
                     instruction_list const& right);

}
#endif

max_stars_repo_name: medlefsen/autonomy

max_issues_repo_name: medlefsen/autonomy

max_forks_repo_name: medlefsen/autonomy


text:
// Copyright 2014 Jonathan Graehl-http://graehl.org/
//
// 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.
#ifndef SHELL_JG2012615_HPP
#define SHELL_JG2012615_HPP
#pragma once

#include <boost/filesystem.hpp>
#include <graehl/shared/os.hpp>
#include <graehl/shared/shell_escape.hpp>

namespace graehl {

inline void copy_file(std::string const& source, std::string const& dest, bool skip_same_size_and_time = false) {
  char const* rsync = "rsync -qt";
  char const* cp = "/bin/cp -p";
  std::stringstream s;
  s << (skip_same_size_and_time ? rsync : cp) << ' ';
  out_shell_quote(s, source);
  s << ' ';
  out_shell_quote(s, dest);
  // INFOQ("copy_file", s.str());
  system_safe(s.str());
}

inline void mkdir_parents(std::string const& dirname) {
  boost::filesystem::create_directories(dirname);
}

inline int system_shell_safe(std::string const& cmd) {
  char const* shell = "/bin/sh -c ";
  std::stringstream s;
  s << shell;
  out_shell_quote(s, cmd);
  return system_safe(s.str());
}

}

#endif

max_stars_repo_name: graehl/carmel

max_issues_repo_name: graehl/carmel

max_forks_repo_name: graehl/carmel