text:
//  (C) Copyright John Maddock 2006.
//  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)

#define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error

#include <boost/math/concepts/real_concept.hpp>
#include <boost/math/special_functions/gamma.hpp>
#include <boost/test/included/test_exec_monitor.hpp>
#include <boost/test/floating_point_comparison.hpp>
#include <boost/math/tools/stats.hpp>
#include <boost/math/tools/test.hpp>
#include <boost/math/constants/constants.hpp>
#include <boost/type_traits/is_floating_point.hpp>
#include <boost/array.hpp>
#include "functor.hpp"

#include "test_gamma_hooks.hpp"
#include "handle_test_result.hpp"

//
// DESCRIPTION:
// ~~~~~~~~~~~~
//
// This file tests the incomplete gamma functions tgamma,
// tgamma_lower, gamma_p and gamma_q. There are two sets of tests, spot
// tests which compare our results with selected values computed
// using the online special function calculator at
// functions.wolfram.com, while the bulk of the accuracy tests
// use values generated with NTL::RR at 1000-bit precision
// and our generic versions of these functions.
//
// Note that when this file is first run on a new platform many of
// these tests will fail: the default accuracy is 1 epsilon which
// is too tight for most platforms.  In this situation you will
// need to cast a human eye over the error rates reported and make
// a judgement as to whether they are acceptable.  Either way please
// report the results to the Boost mailing list.  Acceptable rates of
// error are marked up below as a series of regular expressions that
// identify the compiler/stdlib/platform/data-type/test-data/test-function
// along with the maximum expected peek and RMS mean errors for that
// test.
//

void expected_results()
{
   //
   // Define the max and mean errors expected for
   // various compilers and platforms.
   //
   const char* largest_type;
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
   if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
   {
      largest_type = "(long\\s+)?double";
   }
   else
   {
      largest_type = "long double";
   }
#else
   largest_type = "(long\\s+)?double";
#endif
   //
   // Linux:
   //
   // These should not really be needed, but on *some* Linux
   // versions these error rates are quite large and appear to
   // be related to the accuracy of powl and expl.  On Itanium
   // or Xeon machines the error rates are much lower than this.
   // Worst cases appear to be AMD64 machines.
   //
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "linux",                          // platform
      largest_type,                     // test type(s)
      "[^|]*medium[^|]*",               // test data group
      "[^|]*", 1000, 200);                 // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "linux",                          // platform
      largest_type,                     // test type(s)
      "[^|]*integer[^|]*",               // test data group
      "[^|]*", 1000, 200);                 // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "linux",                          // platform
      "real_concept",                   // test type(s)
      "[^|]*medium[^|]*",               // test data group
      "[^|]*", 600, 200);                // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "linux",                          // platform
      "real_concept",                   // test type(s)
      "[^|]*integer[^|]*",               // test data group
      "[^|]*", 600, 200);                // test function

   //
   // Mac OS X:
   // It's not clear why these should be required, but see notes above
   // about Linux.
   //
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "Mac OS",                          // platform
      largest_type,                     // test type(s)
      "[^|]*medium[^|]*",               // test data group
      "[^|]*", 5000, 1000);                 // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "Mac OS",                          // platform
      largest_type,                     // test type(s)
      "[^|]*small[^|]*",               // test data group
      "[^|]*", 40, 15);                 // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "Mac OS",                          // platform
      largest_type,                     // test type(s)
      "[^|]*integer[^|]*",               // test data group
      "[^|]*", 2000, 300);                 // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "Mac OS",                          // platform
      "real_concept",                   // test type(s)
      "[^|]*medium[^|]*",               // test data group
      "[^|]*", 5000, 1000);                // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "Mac OS",                          // platform
      "real_concept",                     // test type(s)
      "[^|]*small[^|]*",               // test data group
      "[^|]*", 40, 15);                 // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "Mac OS",                          // platform
      "real_concept",                   // test type(s)
      "[^|]*integer[^|]*",               // test data group
      "[^|]*", 2000, 300);                // test function
   //
   // HP-UX:
   //
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "HP-UX",                          // platform
      largest_type,                     // test type(s)
      "[^|]*medium[^|]*",               // test data group
      "[^|]*", 500, 50);                 // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "HP-UX",                          // platform
      "real_concept",                   // test type(s)
      "[^|]*medium[^|]*",               // test data group
      "[^|]*", 500, 100);                // test function
   //
   // Sun OS:
   //
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "Sun.*",                          // platform
      largest_type,                     // test type(s)
      "[^|]*medium[^|]*",               // test data group
      "[^|]*", 500, 100);               // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "Sun.*",                          // platform
      largest_type,                     // test type(s)
      "[^|]*integer[^|]*",              // test data group
      "[^|]*", 100, 30);                // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "Sun.*",                          // platform
      "real_concept",                   // test type(s)
      "[^|]*medium[^|]*",               // test data group
      "[^|]*", 500, 100);                // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "Sun.*",                          // platform
      "real_concept",                   // test type(s)
      "[^|]*integer[^|]*",               // test data group
      "[^|]*", 100, 30);                // test function

   //
   // Mac OS X:
   //
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "Mac OS",                          // platform
      largest_type,                     // test type(s)
      "[^|]*medium[^|]*",               // test data group
      "[^|]*", 100, 50);                 // test function

   //
   // Large exponent range causes more extreme test cases to be evaluated:
   //
   if(std::numeric_limits<long double>::max_exponent > std::numeric_limits<double>::max_exponent)
   {
      add_expected_result(
         "[^|]*",                          // compiler
         "[^|]*",                          // stdlib
         "[^|]*",                          // platform
         largest_type,                     // test type(s)
         "[^|]*large[^|]*",                // test data group
         ".*", 40000, 3000);  // test function
   }

   //
   // Catch all cases come last:
   //
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "[^|]*",                          // platform
      largest_type,                     // test type(s)
      "[^|]*medium[^|]*",               // test data group
      "[^|]*", 50, 20);                 // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "[^|]*",                          // platform
      largest_type,                     // test type(s)
      "[^|]*small[^|]*",                // test data group
      "[^|]*", 20, 10);                  // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "[^|]*",                          // platform
      largest_type,                     // test type(s)
      "[^|]*large[^|]*",                // test data group
      "boost::math::gamma_q", 500, 50);  // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "Cygwin",                         // platform
      largest_type,                     // test type(s)
      "[^|]*large[^|]*",                // test data group
      "boost::math::gamma_p", 700, 50);  // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "[^|]*",                          // platform
      largest_type,                     // test type(s)
      "[^|]*large[^|]*",                // test data group
      "boost::math::gamma_p", 350, 50);  // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "[^|]*",                          // platform
      largest_type,                     // test type(s)
      "[^|]*integer[^|]*",              // test data group
      ".*", 20, 10);                    // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "[^|]*",                          // platform
      "real_concept",                   // test type(s)
      "[^|]*medium[^|]*",               // test data group
      "[^|]*", 200, 50);                // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "[^|]*",                          // platform
      "real_concept",                   // test type(s)
      "[^|]*small[^|]*",                // test data group
      ".*", 20, 10);                  // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "[^|]*",                          // platform
      "real_concept",                   // test type(s)
      "[^|]*large[^|]*",                // test data group
      ".*", 1000000, 100000);        // test function
   add_expected_result(
      "[^|]*",                          // compiler
      "[^|]*",                          // stdlib
      "[^|]*",                          // platform
      "real_concept",                   // test type(s)
      "[^|]*integer[^|]*",              // test data group
      ".*", 40, 10);                    // test function

   //
   // Finish off by printing out the compiler/stdlib/platform names,
   // we do this to make it easier to mark up expected error rates.
   //
   std::cout << "Tests run with " << BOOST_COMPILER << ", "
      << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
}

template <class T>
void do_test_gamma_2(const T& data, const char* type_name, const char* test_name)
{
   typedef typename T::value_type row_type;
   typedef typename row_type::value_type value_type;

   typedef value_type (*pg)(value_type, value_type);
#if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
   pg funcp = boost::math::tgamma<value_type, value_type>;
#else
   pg funcp = boost::math::tgamma;
#endif

   boost::math::tools::test_result<value_type> result;

   std::cout << "Testing " << test_name << " with type " << type_name
      << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";

   //
   // test tgamma(T, T) against data:
   //
   if(data[0][2] > 0)
   {
      result = boost::math::tools::test(
         data,
         bind_func(funcp, 0, 1),
         extract_result(2));
      handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::tgamma", test_name);
      //
      // test tgamma_lower(T, T) against data:
      //
#if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
      funcp = boost::math::tgamma_lower<value_type, value_type>;
#else
      funcp = boost::math::tgamma_lower;
#endif
      result = boost::math::tools::test(
         data,
         bind_func(funcp, 0, 1),
         extract_result(4));
      handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::tgamma_lower", test_name);
   }
   //
   // test gamma_q(T, T) against data:
   //
#if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
   funcp = boost::math::gamma_q<value_type, value_type>;
#else
   funcp = boost::math::gamma_q;
#endif
   result = boost::math::tools::test(
      data,
      bind_func(funcp, 0, 1),
      extract_result(3));
   handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::gamma_q", test_name);
#if defined(TEST_CEPHES) || defined(TEST_GSL)
   //
   // test other gamma_q(T, T) against data:
   //
   if(boost::is_floating_point<value_type>::value)
   {
      funcp = other::gamma_q;
      result = boost::math::tools::test(
         data,
         bind_func(funcp, 0, 1),
         extract_result(3));
      print_test_result(result, data[result.worst()], result.worst(), type_name, "other::gamma_q");
   }
#endif
   //
   // test gamma_p(T, T) against data:
   //
#if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
   funcp = boost::math::gamma_p<value_type, value_type>;
#else
   funcp = boost::math::gamma_p;
#endif
   result = boost::math::tools::test(
      data,
      bind_func(funcp, 0, 1),
      extract_result(5));
   handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::gamma_p", test_name);
#if defined(TEST_CEPHES) || defined(TEST_GSL)
   //
   // test other gamma_p(T, T) against data:
   //
   if(boost::is_floating_point<value_type>::value)
   {
      funcp = other::gamma_p;
      result = boost::math::tools::test(
         data,
         bind_func(funcp, 0, 1),
         extract_result(5));
      print_test_result(result, data[result.worst()], result.worst(), type_name, "other::gamma_p");
   }
#endif
   std::cout << std::endl;
}

template <class T>
void test_gamma(T, const char* name)
{
   //
   // The actual test data is rather verbose, so it's in a separate file
   //
   // First the data for the incomplete gamma function, each
   // row has the following 6 entries:
   // Parameter a, parameter z,
   // Expected tgamma(a, z), Expected gamma_q(a, z)
   // Expected tgamma_lower(a, z), Expected gamma_p(a, z)
   //
#  include "igamma_med_data.ipp"

   do_test_gamma_2(igamma_med_data, name, "tgamma(a, z) medium values");

#  include "igamma_small_data.ipp"

   do_test_gamma_2(igamma_small_data, name, "tgamma(a, z) small values");

#  include "igamma_big_data.ipp"

   do_test_gamma_2(igamma_big_data, name, "tgamma(a, z) large values");

#  include "igamma_int_data.ipp"

   do_test_gamma_2(igamma_int_data, name, "tgamma(a, z) integer and half integer values");
}

template <class T>
void test_spots(T)
{
   //
   // basic sanity checks, tolerance is 10 epsilon expressed as a percentage:
   //
   T tolerance = boost::math::tools::epsilon<T>() * 1000;
#if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
   tolerance *= 10;
#endif
   BOOST_CHECK_CLOSE(::boost::math::tgamma(static_cast<T>(5), static_cast<T>(1)), static_cast<T>(23.912163676143750903709045060494956383977723517065L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::tgamma(static_cast<T>(5), static_cast<T>(5)), static_cast<T>(10.571838841565097874621959975919877646444998907920L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::tgamma(static_cast<T>(5), static_cast<T>(10)), static_cast<T>(0.70206451384706574414638719662835463671916532623256L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::tgamma(static_cast<T>(5), static_cast<T>(100)), static_cast<T>(3.8734332808745531496973774140085644548465762343719e-36L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::tgamma(static_cast<T>(0.5), static_cast<T>(0.5)), static_cast<T>(0.56241823159440712427949495730204306902676756479651L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::tgamma(static_cast<T>(0.5), static_cast<T>(9)/10), static_cast<T>(0.31853210360412109873859360390443790076576777747449L), tolerance*10);
   BOOST_CHECK_CLOSE(::boost::math::tgamma(static_cast<T>(0.5), static_cast<T>(5)), static_cast<T>(0.0027746032604128093194908357272603294120210079791437L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::tgamma(static_cast<T>(0.5), static_cast<T>(100)), static_cast<T>(3.7017478604082789202535664481339075721362102520338e-45L), tolerance);

   BOOST_CHECK_CLOSE(::boost::math::tgamma_lower(static_cast<T>(5), static_cast<T>(1)), static_cast<T>(0.087836323856249096290954939505043616022276482935091L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::tgamma_lower(static_cast<T>(5), static_cast<T>(5)), static_cast<T>(13.428161158434902125378040024080122353555001092080L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::tgamma_lower(static_cast<T>(5), static_cast<T>(10)), static_cast<T>(23.297935486152934255853612803371645363280834673767L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::tgamma_lower(static_cast<T>(5), static_cast<T>(100)), static_cast<T>(23.999999999999999999999999999999999996126566719125L), tolerance);

   BOOST_CHECK_CLOSE(::boost::math::gamma_q(static_cast<T>(5), static_cast<T>(1)), static_cast<T>(0.99634015317265628765454354418728984933240514654437L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::gamma_q(static_cast<T>(5), static_cast<T>(5)), static_cast<T>(0.44049328506521241144258166566332823526854162116334L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::gamma_q(static_cast<T>(5), static_cast<T>(10)), static_cast<T>(0.029252688076961072672766133192848109863298555259690L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::gamma_q(static_cast<T>(5), static_cast<T>(100)), static_cast<T>(1.6139305336977304790405739225035685228527400976549e-37L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::gamma_q(static_cast<T>(1.5), static_cast<T>(2)), static_cast<T>(0.26146412994911062220282207597592120190281060919079L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::gamma_q(static_cast<T>(20.5), static_cast<T>(22)), static_cast<T>(0.34575332043467326814971590879658406632570278929072L), tolerance);

   BOOST_CHECK_CLOSE(::boost::math::gamma_p(static_cast<T>(5), static_cast<T>(1)), static_cast<T>(0.0036598468273437123454564558127101506675948534556288L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::gamma_p(static_cast<T>(5), static_cast<T>(5)), static_cast<T>(0.55950671493478758855741833433667176473145837883666L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::gamma_p(static_cast<T>(5), static_cast<T>(10)), static_cast<T>(0.97074731192303892732723386680715189013670144474031L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::gamma_p(static_cast<T>(5), static_cast<T>(100)), static_cast<T>(0.9999999999999999999999999999999999998386069466302L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::gamma_p(static_cast<T>(1.5), static_cast<T>(2)), static_cast<T>(0.73853587005088937779717792402407879809718939080921L), tolerance);
   BOOST_CHECK_CLOSE(::boost::math::gamma_p(static_cast<T>(20.5), static_cast<T>(22)), static_cast<T>(0.65424667956532673185028409120341593367429721070928L), tolerance);

   // naive check on derivative function:
   using namespace std;  // For ADL of std functions
   tolerance = boost::math::tools::epsilon<T>() * 5000; // 50 eps
   BOOST_CHECK_CLOSE(::boost::math::gamma_p_derivative(static_cast<T>(20.5), static_cast<T>(22)),
      exp(static_cast<T>(-22)) * pow(static_cast<T>(22), static_cast<T>(19.5)) / boost::math::tgamma(static_cast<T>(20.5)), tolerance);

}

int test_main(int, char* [])
{
   expected_results();
   BOOST_MATH_CONTROL_FP;

#ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
   test_spots(0.0F);
#endif
   test_spots(0.0);
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
   test_spots(0.0L);
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
   test_spots(boost::math::concepts::real_concept(0.1));
#endif
#endif

#ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
   test_gamma(0.1F, "float");
#endif
   test_gamma(0.1, "double");
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
   test_gamma(0.1L, "long double");
#ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
   test_gamma(boost::math::concepts::real_concept(0.1), "real_concept");
#endif
#endif
#else
   std::cout << "<note>The long double tests have been disabled on this platform "
      "either because the long double overloads of the usual math functions are "
      "not available at all, or because they are too inaccurate for these tests "
      "to pass.</note>" << std::cout;
#endif
   return 0;
}


text:
// This file is auto-generated, don't edit it. Thanks.

#include <alibabacloud/antiddos_public_20170518.hpp>
#include <alibabacloud/endpoint_util.hpp>
#include <alibabacloud/open_api.hpp>
#include <boost/any.hpp>
#include <boost/throw_exception.hpp>
#include <darabonba/core.hpp>
#include <darabonba/util.hpp>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

using namespace Alibabacloud_Antiddos-public20170518;

Alibabacloud_Antiddos-public20170518::Client::Client(const shared_ptr<Alibabacloud_OpenApi::Config>& config) : Alibabacloud_OpenApi::Client(config) {
  _endpointRule = make_shared<string>("");
  checkConfig(config);
  _endpoint = make_shared<string>(getEndpoint(make_shared<string>("antiddos-public"), _regionId, _endpointRule, _network, _suffix, _endpointMap, _endpoint));
};

string Alibabacloud_Antiddos-public20170518::Client::getEndpoint(shared_ptr<string> productId,
                                                                 shared_ptr<string> regionId,
                                                                 shared_ptr<string> endpointRule,
                                                                 shared_ptr<string> network,
                                                                 shared_ptr<string> suffix,
                                                                 shared_ptr<map<string, string>> endpointMap,
                                                                 shared_ptr<string> endpoint) {
  if (!Darabonba_Util::Client::empty(endpoint)) {
    return *endpoint;
  }
  if (!Darabonba_Util::Client::isUnset<map<string, string>>(endpointMap) && !Darabonba_Util::Client::empty(make_shared<string>((*endpointMap)[regionId]))) {
    return (*endpointMap)[regionId];
  }
  return Alibabacloud_EndpointUtil::Client::getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

DescribeBgpPackByIpResponse Alibabacloud_Antiddos-public20170518::Client::describeBgpPackByIpWithOptions(shared_ptr<DescribeBgpPackByIpRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"body", boost::any(Darabonba_Util::Client::toMap(request))}
  }));
  return DescribeBgpPackByIpResponse(doRPCRequest(make_shared<string>("DescribeBgpPackByIp"), make_shared<string>("2017-05-18"), make_shared<string>("HTTPS"), make_shared<string>("POST"), make_shared<string>("AK"), make_shared<string>("json"), req, runtime));
}

DescribeBgpPackByIpResponse Alibabacloud_Antiddos-public20170518::Client::describeBgpPackByIp(shared_ptr<DescribeBgpPackByIpRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return describeBgpPackByIpWithOptions(request, runtime);
}

DescribeCapResponse Alibabacloud_Antiddos-public20170518::Client::describeCapWithOptions(shared_ptr<DescribeCapRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"body", boost::any(Darabonba_Util::Client::toMap(request))}
  }));
  return DescribeCapResponse(doRPCRequest(make_shared<string>("DescribeCap"), make_shared<string>("2017-05-18"), make_shared<string>("HTTPS"), make_shared<string>("POST"), make_shared<string>("AK"), make_shared<string>("json"), req, runtime));
}

DescribeCapResponse Alibabacloud_Antiddos-public20170518::Client::describeCap(shared_ptr<DescribeCapRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return describeCapWithOptions(request, runtime);
}

DescribeDdosCountResponse Alibabacloud_Antiddos-public20170518::Client::describeDdosCountWithOptions(shared_ptr<DescribeDdosCountRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"body", boost::any(Darabonba_Util::Client::toMap(request))}
  }));
  return DescribeDdosCountResponse(doRPCRequest(make_shared<string>("DescribeDdosCount"), make_shared<string>("2017-05-18"), make_shared<string>("HTTPS"), make_shared<string>("POST"), make_shared<string>("AK"), make_shared<string>("json"), req, runtime));
}

DescribeDdosCountResponse Alibabacloud_Antiddos-public20170518::Client::describeDdosCount(shared_ptr<DescribeDdosCountRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return describeDdosCountWithOptions(request, runtime);
}

DescribeDdosCreditResponse Alibabacloud_Antiddos-public20170518::Client::describeDdosCreditWithOptions(shared_ptr<DescribeDdosCreditRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"body", boost::any(Darabonba_Util::Client::toMap(request))}
  }));
  return DescribeDdosCreditResponse(doRPCRequest(make_shared<string>("DescribeDdosCredit"), make_shared<string>("2017-05-18"), make_shared<string>("HTTPS"), make_shared<string>("POST"), make_shared<string>("AK"), make_shared<string>("json"), req, runtime));
}

DescribeDdosCreditResponse Alibabacloud_Antiddos-public20170518::Client::describeDdosCredit(shared_ptr<DescribeDdosCreditRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return describeDdosCreditWithOptions(request, runtime);
}

DescribeDdosEventListResponse Alibabacloud_Antiddos-public20170518::Client::describeDdosEventListWithOptions(shared_ptr<DescribeDdosEventListRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"body", boost::any(Darabonba_Util::Client::toMap(request))}
  }));
  return DescribeDdosEventListResponse(doRPCRequest(make_shared<string>("DescribeDdosEventList"), make_shared<string>("2017-05-18"), make_shared<string>("HTTPS"), make_shared<string>("POST"), make_shared<string>("AK"), make_shared<string>("json"), req, runtime));
}

DescribeDdosEventListResponse Alibabacloud_Antiddos-public20170518::Client::describeDdosEventList(shared_ptr<DescribeDdosEventListRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return describeDdosEventListWithOptions(request, runtime);
}

DescribeDdosThresholdResponse Alibabacloud_Antiddos-public20170518::Client::describeDdosThresholdWithOptions(shared_ptr<DescribeDdosThresholdRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"body", boost::any(Darabonba_Util::Client::toMap(request))}
  }));
  return DescribeDdosThresholdResponse(doRPCRequest(make_shared<string>("DescribeDdosThreshold"), make_shared<string>("2017-05-18"), make_shared<string>("HTTPS"), make_shared<string>("POST"), make_shared<string>("AK"), make_shared<string>("json"), req, runtime));
}

DescribeDdosThresholdResponse Alibabacloud_Antiddos-public20170518::Client::describeDdosThreshold(shared_ptr<DescribeDdosThresholdRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return describeDdosThresholdWithOptions(request, runtime);
}

DescribeInstanceResponse Alibabacloud_Antiddos-public20170518::Client::describeInstanceWithOptions(shared_ptr<DescribeInstanceRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"body", boost::any(Darabonba_Util::Client::toMap(request))}
  }));
  return DescribeInstanceResponse(doRPCRequest(make_shared<string>("DescribeInstance"), make_shared<string>("2017-05-18"), make_shared<string>("HTTPS"), make_shared<string>("POST"), make_shared<string>("AK"), make_shared<string>("json"), req, runtime));
}

DescribeInstanceResponse Alibabacloud_Antiddos-public20170518::Client::describeInstance(shared_ptr<DescribeInstanceRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return describeInstanceWithOptions(request, runtime);
}

DescribeRegionsResponse Alibabacloud_Antiddos-public20170518::Client::describeRegionsWithOptions(shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>();
  return DescribeRegionsResponse(doRPCRequest(make_shared<string>("DescribeRegions"), make_shared<string>("2017-05-18"), make_shared<string>("HTTPS"), make_shared<string>("POST"), make_shared<string>("AK"), make_shared<string>("json"), req, runtime));
}

DescribeRegionsResponse Alibabacloud_Antiddos-public20170518::Client::describeRegions() {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return describeRegionsWithOptions(runtime);
}

ModifyDdosStatusResponse Alibabacloud_Antiddos-public20170518::Client::modifyDdosStatusWithOptions(shared_ptr<ModifyDdosStatusRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"body", boost::any(Darabonba_Util::Client::toMap(request))}
  }));
  return ModifyDdosStatusResponse(doRPCRequest(make_shared<string>("ModifyDdosStatus"), make_shared<string>("2017-05-18"), make_shared<string>("HTTPS"), make_shared<string>("POST"), make_shared<string>("AK"), make_shared<string>("json"), req, runtime));
}

ModifyDdosStatusResponse Alibabacloud_Antiddos-public20170518::Client::modifyDdosStatus(shared_ptr<ModifyDdosStatusRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return modifyDdosStatusWithOptions(request, runtime);
}

ModifyDefenseThresholdResponse Alibabacloud_Antiddos-public20170518::Client::modifyDefenseThresholdWithOptions(shared_ptr<ModifyDefenseThresholdRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"body", boost::any(Darabonba_Util::Client::toMap(request))}
  }));
  return ModifyDefenseThresholdResponse(doRPCRequest(make_shared<string>("ModifyDefenseThreshold"), make_shared<string>("2017-05-18"), make_shared<string>("HTTPS"), make_shared<string>("POST"), make_shared<string>("AK"), make_shared<string>("json"), req, runtime));
}

ModifyDefenseThresholdResponse Alibabacloud_Antiddos-public20170518::Client::modifyDefenseThreshold(shared_ptr<ModifyDefenseThresholdRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return modifyDefenseThresholdWithOptions(request, runtime);
}

ext: cpp

max_stars_repo_name: aliyun/alibabacloud-cpp-sdk

max_issues_repo_name: aliyun/alibabacloud-cpp-sdk

max_forks_repo_name: aliyun/alibabacloud-cpp-sdk


text:
//  Copyright (c) 2018 Robert Ramey
//
// 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 <exception>
#include <iostream>
#include <type_traits>
#include <boost/safe_numerics/safe_integer.hpp>
#include <boost/safe_numerics/safe_integer_range.hpp>
#include <boost/safe_numerics/safe_integer_literal.hpp>

#include <boost/safe_numerics/utility.hpp>

using namespace boost::safe_numerics;

int main(){
    safe_unsigned_range<7, 24> i;

    // since the range is included in [0,255], the underlying type of i
    // will be an unsigned char.
    try{
        i = 0;  // throws out_of_range exception
        std::cout << "fails to detect erroneous assignment" << std::endl;
    }
    catch(std::exception & e){
        // should arrive here
    }
    try{
        i = 9;  // ok - no exception expected
    }
    catch(std::exception & e){
        std::cout << "erroneous error for legal assignment" << std::endl;
    }
    try{
        i *= 9; // fails to compile because result can't fin in range
        std::cout << "fails to out of range result" << std::endl;
    }
    catch(std::exception & e){
        // should arrive here
    }
    try{
        i = -1; // throws out_of_range exception
        std::cout << "fails to detect erroneous assignment" << std::endl;
    }
    catch(std::exception & e){
        // should arrive here
    }
    std::uint8_t j = 4;
    auto k = i + j;

    // if either or both types are safe types, the result is a safe type
    // determined by promotion policy.  In this instance
    // the range of i is [7, 24] and the range of j is [0,255].
    // so the type of k will be a safe type with a range of [7,279]
    static_assert(
        is_safe<decltype(k)>::value
        && std::numeric_limits<decltype(k)>::min() == 7
        && std::numeric_limits<decltype(k)>::max() == 279,
        "k is a safe range of [7,279]"
    );
    return 0;
}


text:
/*
    Copyright (c) 2002-2009 Tampere University.

    This file is part of TTA-Based Codesign Environment (TCE).

    Permission is hereby granted, free of charge, to any person obtaining a
    copy of this software and associated documentation files (the "Software"),
    to deal in the Software without restriction, including without limitation
    the rights to use, copy, modify, merge, publish, distribute, sublicense,
    and/or sell copies of the Software, and to permit persons to whom the
    Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    DEALINGS IN THE SOFTWARE.
 */
/**
 * @file OperationBindingCheck.cc
 *
 * Implementation of OperationBindingCheck class.
 *
 * @author Heikki Kultala 2008 (hkultala-no.spam-cs.tut.fi)
 * @note rating: red
 */

#include <boost/format.hpp>

#include "OperationBindingCheck.hh"
#include "HWOperation.hh"
#include "Machine.hh"
#include "ExecutionPipeline.hh"
#include "FUPort.hh"
#include "FunctionUnit.hh"
#include "MachineCheckResults.hh"

using namespace TTAMachine;

OperationBindingCheck::OperationBindingCheck() :
    MachineCheck("Check operation binding, port directions, triggers") {}

/**
 * Checks that machine's FU's have legal port and trigger bindings
 *
 * @param mach machine to check
 * @param results place where to put detailed error descriptions
 * @return true if everything is ok, false if something is wrong
 */
bool OperationBindingCheck::check(
    const TTAMachine::Machine& mach, MachineCheckResults& results) const {

    TTAMachine::Machine::FunctionUnitNavigator fuNav =
        mach.functionUnitNavigator();

    bool retval = true;
    bool triggerok = true;
    for (int i = 0; i < fuNav.count(); i++) {
        FunctionUnit& fu = *fuNav.item(i);

        // find trigger port
        FUPort* triggerPort = NULL;
        for (int j = 0; j < fu.operationPortCount(); j++) {
            FUPort* port = fu.operationPort(j);
            if (port->isTriggering()) {

                // check that we do not have multiple trigger ports.
                if ( triggerPort != NULL) {
                    results.addError(
                        *this, (boost::format("Multiple trigger ports are "
                                              "not supported, Used in FU: %s")
                                % fu.name()).str());
                    retval = false;
                    triggerok = false;
                }
                else {
                    // check trigger and fu ports are the same
                    triggerPort = port;
                    if (!port->isOpcodeSetting()) {
                        results.addError(
                            *this, (boost::format("Opcode setting and trigger "
                                                  "port differ in FU: ")
                                    % fu.name()).str());
                        retval = false;
                        triggerok = false;
                    }
                }
            }
        }
        // check that we have a trigger port
        if ( triggerPort == NULL) {
            results.addError(
                *this, (boost::format("Trigger port not found in FU: %s")
                        % fu.name()).str());
            return false;
        }

        // check all operations
        for (int j = 0; j < fu.operationCount(); j++) {

            HWOperation& hwop = *fu.operation(j);
            bool triggerRead = false;

            // check read port bindins
            ExecutionPipeline& pipe = *hwop.pipeline();
            const ExecutionPipeline::OperandSet reads = pipe.readOperands();
            for (ExecutionPipeline::OperandSet::const_iterator iter =
                     reads.begin(); iter != reads.end(); iter++) {
                Port* readPort = hwop.port(*iter);
                if ( readPort->inputSocket() == NULL) {
                    std::string errorMsg =
                        (boost::format(
                            "Operation %s in FU %s reads operand %d which "
                            "is not connected to input socket. "
                            "Check port bindings!")
                         % hwop.name() % fu.name() % *iter).str();

                    results.addError(*this, (errorMsg));
                    retval = false;
                } else {
                    // check if this was read from the trigger
                    if (readPort == triggerPort) {
                        triggerRead = true;
                    }
                }
            }

            // was trigger actually read?
            if ( triggerok && !triggerRead) {
                std::string errorMsg =
                    (boost::format(
                         "Trigger not bound for operation: %s in FU %s") %
                     hwop.name() % fu.name()).str();
                results.addError(*this, errorMsg);
                retval = false;
            }

            // check write port bidings
            const ExecutionPipeline::OperandSet writes =
                pipe.writtenOperands();
            for (ExecutionPipeline::OperandSet::const_iterator iter =
                     writes.begin(); iter != writes.end(); iter++) {
                Port* writePort = hwop.port(*iter);
                if ( writePort->outputSocket() == NULL) {
                    results.addError(
                        *this, (boost::format("Operation %s in FU %s "
                                              "writes operand %d"
                                              "which is not connected to "
                                              "output socket. "
                                              "Check port bindings!")
                                % hwop.name() % fu.name() % *iter).str());
                    retval = false;
                }
            }
        }
    }
    return retval;
}

ext: cc

max_stars_repo_name: kanishkan/tce

max_issues_repo_name: kanishkan/tce

max_forks_repo_name: kanishkan/tce


text:
/*
 * \brief This file tests our dependencies (cpprest, openssl, etc.) are installed correctly, by exercising the compiler
 * and linker on this machine.
 * \since 8.0.2
 * \date 2016-06-15
 * \author Adam Fowler <adam.fowler@marklogic.com>
 */

#include <cpprest/json.h>
#include <openssl/md5.h>
#include <boost/uuid/uuid.hpp>

int main(int argc, const char * argv[]) {
  web::json::value value;
  MD5_CTX _context;
  boost::uuids::uuid random_uuid = boost::uuids::random_generator()();
  return 0;
}

max_stars_repo_name: adamfowleruk/mlcplusplus

max_issues_repo_name: marklogic/mlcplusplus

max_forks_repo_name: adamfowleruk/mlcplusplus


text:
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example

// Copyright (c) 2014 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2020 Baidyanath Kundu, Haldia, India.

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

//[from_wkt
//` Shows the usage of from_wkt

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/polygon.hpp>

int main()
{
    using point_type = boost::geometry::model::d2::point_xy<double>;
    using box_type = boost::geometry::model::box<point_type>;
    using segment_type = boost::geometry::model::segment<point_type>;
    using polygon_type = boost::geometry::model::polygon<point_type>;
    using linestring_type = boost::geometry::model::linestring<point_type>;

    auto const a = boost::geometry::from_wkt<point_type>("POINT(1 2)");
    auto const d = boost::geometry::from_wkt<box_type>("BOX(0 0,3 3)");
    auto const e = boost::geometry::from_wkt<segment_type>("SEGMENT(1 0,3 4)");
    auto const c = boost::geometry::from_wkt<polygon_type>("POLYGON((0 0,0 7,4 2,2 0,0 0))");
    auto const b = boost::geometry::from_wkt<linestring_type>("LINESTRING(0 0,2 2,3 1)");

    return 0;
}

//]


text:
#include <string>
#include <ros/ros.h>											// 包含ROS的头文件
#include <ros/time.h>
#include <geometry_msgs/TransformStamped.h>
#include <tf/transform_broadcaster.h>
#include <nav_msgs/Odometry.h>
#include <boost/asio.hpp>										//包含boost库函数
#include <boost/bind.hpp>
#include <math.h>
#include <geometry_msgs/Twist.h>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;
using namespace boost::asio;									//定义一个命名空间，用于后面的读写操作
ros::Time current_time, last_time;
void writeSerial(const geometry_msgs::Twist& msg);

io_service iosev;												//节点文件
serial_port sp(iosev, "/dev/mrobot");
char* FILENAME;
void readConfigFile(char* filename);
void writeConfigFile(char* filename);

#define		R			105.00
#define		L			210.50
#define		fastAbs(n)	n > 0 ? n : -n
#define		PI			3.1415926535897932f

int _ID_FLAG = 0, _READ = 1;
unsigned char Get_Crc8(unsigned char *ptr, unsigned short len)
{
	unsigned char crc;
	unsigned char i;
	crc = 0;
	while(len--)
	{
		crc ^= *ptr++;
		for(i = 0; i < 8; i++)
		{
			if(crc&0x01)crc=(crc>>1)^0x8C;
			else crc >>= 1;
		}
	}
	return crc;
}

const string toHexString(const unsigned char* input, const int datasize)
{
	string output;
	char ch[3];

	for(int i = 0; i < datasize; ++i)
	{
		snprintf(ch, 3, "%02x", input[i]);
		output += ch;
	}
	return output;
}

bool compareID(const unsigned char* ID, string ID_FROM_FILE)
{
	string temp;
	temp = toHexString(ID, 12);
	if (temp == ID_FROM_FILE)
	{
		return true;
	} else
	{
		return false;
	}
}

double x = 0.0;
double y = 0.0;
double th = 0.0;

double vx = 0.0;
double vy = 0.0;
double vth = 0.0;

enum SendCommandType {
	SIMPLE_INFO = 23130,
	WITH_SONAR_INFO = 23125,
	WITH_SIX_AXIS_SENSOR_INFO = 23210,
	ALL_INFO = 23205,
	SPEED_INFO = 42330,
	BATTERY_INFO = 42325,
	SONAR_INFO = 42410,
	SIX_AXIS_SENSOR_INFO = 42405,
};

enum ReceiveCommandType {
	REQUIRE_WITH_SIMPLE_INFO = 0,
	REQUIRE_WITH_SONAR_INFO,
	REQUIRE_WITH_SIX_AXIS_SENSOR_INFO,
	REQUIRE_WITH_ALL_INFO,
	REQUIRE_WITH_SPEED_INFO,
	REQUIRE_WITH_BATTERY_INFO,
	REQUIRE_WITH_ONLY_SONAR_INFO,
	REQUIRE_WITH_ONLY_SIX_AXIS_SENSOR_INFO,
};

union sendData
{
	int d;
	unsigned char data[4];
}leftdata, rightdata;

union checkSum
{
	short d;
	unsigned char data[1];
}SendCheckSum, ReceiveCheckSum;

union receiveHeader
{
	int d;
	unsigned char data[2];
}receive_command, receive_header;

union receiveEnder
{
	int d;
	unsigned char data[2];
}receive_ender;

union sendCommand
{
	int d;
	unsigned char data[2];
}send_command;

union odometry													//里程计数据共用体
{
	float odoemtry_float;
	unsigned char odometry_char[4];
}vel_left, vel_right, temprature, odom_yaw, odom_pitch, odom_roll, sonar_front, sonar_back, sonar_left, sonar_right;

union battery													//电池数据共用体
{
	float battery_float;
	unsigned char battery_char[4];
}electricity, battery_percentage;

unsigned char buf[200];											//定义字符串长度
unsigned char _ID[12];											//存放芯片ID的临时变量
string read_str;
short command = -1;
const unsigned char ender[2] = {0x0d, 0x0a};
const unsigned char header[2] = {0x55, 0xaa};

void readSerial()
{
	int i, _length = 0;
	unsigned char _checkSum;
	read(sp, buffer(buf));
	ros::Time curr_time;
	for (i = 0; i < 2; i++)
	{
		receive_header.data[i] = buf[i];
	}
	if (receive_header.data[0] == header[0] && receive_header.data[1] == header[1])
	{
		for (i = 0; i < 2; i++)
		{
			receive_command.data[i] = buf[i + 2];
		}
		_length = buf[4];
		_checkSum = Get_Crc8(buf, 5 + _length);
		switch(receive_command.d)
		{
			case SIMPLE_INFO:
				command = REQUIRE_WITH_SIMPLE_INFO;
				if (buf[6 + _length] == ender[0] && buf[6 + _length + 1] == ender[1])
				{
					ReceiveCheckSum.data[0] = buf[5 + _length];
					if (_checkSum == ReceiveCheckSum.d)
					{
						for(i = 0; i < 4; i++)
						{
							vel_left.odometry_char[i] = buf[i + 5];
							vel_right.odometry_char[i] = buf[i + 9];
							electricity.battery_char[i] = buf[i + 13];
							battery_percentage.battery_char[i] = buf[i + 17];
						}
						vx = (vel_right.odoemtry_float + vel_left.odoemtry_float) / 2 / 1000;
						vth = (vel_right.odoemtry_float - vel_left.odoemtry_float) / L;

						curr_time = ros::Time::now();

						double dt = (curr_time - last_time).toSec();
						double delta_x = (vx * cos(th) - vy * sin(th)) * dt;
						double delta_y = (vx * sin(th) + vy * cos(th)) * dt;
						double delta_th = vth * dt;

						x += delta_x;
						y += delta_y;
						th += delta_th;
						last_time = curr_time;
					}
					else
					{
						ROS_INFO("Received data check sum error!");
					}
				}
			break;
			case WITH_SONAR_INFO:
				command = REQUIRE_WITH_SONAR_INFO;
				if (buf[6 + _length] == ender[0] && buf[6 + _length + 1] == ender[1])
				{
					ReceiveCheckSum.data[0] = buf[5 + _length];
					if (_checkSum == ReceiveCheckSum.d)
					{
						for(i = 0; i < 4; i++)
						{
							vel_left.odometry_char[i] = buf[i + 5];
							vel_right.odometry_char[i] = buf[i + 9];
							electricity.battery_char[i] = buf[i + 13];
							battery_percentage.battery_char[i] = buf[i + 17];
							sonar_front.odometry_char[i] = buf[i + 21];
							sonar_back.odometry_char[i] = buf[i + 25];
							sonar_left.odometry_char[i] = buf[i + 29];
							sonar_right.odometry_char[i] = buf[i + 33];
						}
						vx = (vel_right.odoemtry_float + vel_left.odoemtry_float) / 2 / 1000;
						vth = (vel_right.odoemtry_float - vel_left.odoemtry_float) / L;

						curr_time = ros::Time::now();

						double dt = (curr_time - last_time).toSec();
						double delta_x = (vx * cos(th) - vy * sin(th)) * dt;
						double delta_y = (vx * sin(th) + vy * cos(th)) * dt;
						double delta_th = vth * dt;

						x += delta_x;
						y += delta_y;
						th += delta_th;
						last_time = curr_time;
					}
					else
					{
						ROS_INFO("Received data check sum error!");
					}
				}
			break;
			case WITH_SIX_AXIS_SENSOR_INFO:
				command = REQUIRE_WITH_SIX_AXIS_SENSOR_INFO;
				if (buf[6 + _length] == ender[0] && buf[6 + _length + 1] == ender[1])
				{
					ReceiveCheckSum.data[0] = buf[5 + _length];
					if (_checkSum == ReceiveCheckSum.d)
					{
						for(i = 0; i < 4; i++)
						{
							vel_left.odometry_char[i] = buf[i + 5];
							vel_right.odometry_char[i] = buf[i + 9];
							electricity.battery_char[i] = buf[i + 13];
							battery_percentage.battery_char[i] = buf[i + 17];
							odom_pitch.odometry_char[i] = buf[i + 21];
							odom_roll.odometry_char[i] = buf[i + 25];
							odom_yaw.odometry_char[i] = buf[i + 29];
							temprature.odometry_char[i] = buf[i + 33];
						}
						vx = (vel_right.odoemtry_float + vel_left.odoemtry_float) / 2 / 1000;
						vth = (vel_right.odoemtry_float - vel_left.odoemtry_float) / L;

						curr_time = ros::Time::now();

						double dt = (curr_time - last_time).toSec();
						double delta_x = (vx * cos(th) - vy * sin(th)) * dt;
						double delta_y = (vx * sin(th) + vy * cos(th)) * dt;
						double delta_th = vth * dt;

						x += delta_x;
						y += delta_y;
						th += delta_th;
						last_time = curr_time;
					}
					else
					{
						ROS_INFO("Received data check sum error!");
					}
				}
			break;
			case ALL_INFO:
				command = REQUIRE_WITH_ALL_INFO;
				if (buf[6 + _length] == ender[0] && buf[6 + _length + 1] == ender[1])
				{
					ReceiveCheckSum.data[0] = buf[5 + _length];
					if (_checkSum == ReceiveCheckSum.d)
					{
						for(i = 0; i < 4; i++)
						{
							vel_left.odometry_char[i] = buf[i + 5];
							vel_right.odometry_char[i] = buf[i + 9];
							electricity.battery_char[i] = buf[i + 13];
							battery_percentage.battery_char[i] = buf[i + 17];
							odom_pitch.odometry_char[i] = buf[i + 21];
							odom_roll.odometry_char[i] = buf[i + 25];
							odom_yaw.odometry_char[i] = buf[i + 29];
							temprature.odometry_char[i] = buf[i + 33];
							sonar_front.odometry_char[i] = buf[i + 37];
							sonar_back.odometry_char[i] = buf[i + 41];
							sonar_left.odometry_char[i] = buf[i + 45];
							sonar_right.odometry_char[i] = buf[i + 49];
						}
						vx = (vel_right.odoemtry_float + vel_left.odoemtry_float) / 2 / 1000;
						vth = (vel_right.odoemtry_float - vel_left.odoemtry_float) / L;

						curr_time = ros::Time::now();

						double dt = (curr_time - last_time).toSec();
						double delta_x = (vx * cos(th) - vy * sin(th)) * dt;
						double delta_y = (vx * sin(th) + vy * cos(th)) * dt;
						double delta_th = vth * dt;

						x += delta_x;
						y += delta_y;
						th += delta_th;
						last_time = curr_time;
					}
					else
					{
						ROS_INFO("Received data check sum error!");
					}
				}
			break;
			case SPEED_INFO:
				command = REQUIRE_WITH_SPEED_INFO;
				if (buf[6 + _length] == ender[0] && buf[6 + _length + 1] == ender[1])
				{
					ReceiveCheckSum.data[0] = buf[5 + _length];
					if (_checkSum == ReceiveCheckSum.d)
					{
						for(i = 0; i < 4; i++)
						{
							vel_left.odometry_char[i] = buf[i + 5];
							vel_right.odometry_char[i] = buf[i + 9];
						}
						vx = (vel_right.odoemtry_float + vel_left.odoemtry_float) / 2 / 1000;
						vth = (vel_right.odoemtry_float - vel_left.odoemtry_float) / L;

						curr_time = ros::Time::now();

						double dt = (curr_time - last_time).toSec();
						double delta_x = (vx * cos(th) - vy * sin(th)) * dt;
						double delta_y = (vx * sin(th) + vy * cos(th)) * dt;
						double delta_th = vth * dt;

						x += delta_x;
						y += delta_y;
						th += delta_th;
						last_time = curr_time;
					}
					else
					{
						ROS_INFO("Received data check sum error!");
					}
				}
			break;
			case BATTERY_INFO:
				command = REQUIRE_WITH_BATTERY_INFO;
				if (buf[6 + _length] == ender[0] && buf[6 + _length + 1] == ender[1])
				{
					ReceiveCheckSum.data[0] = buf[5 + _length];
					if (_checkSum == ReceiveCheckSum.d)
					{
						for(i = 0; i < 4; i++)
						{
							electricity.battery_char[i] = buf[i + 5];
							battery_percentage.battery_char[i] = buf[i + 9];
						}
						vx = (vel_right.odoemtry_float + vel_left.odoemtry_float) / 2 / 1000;
						vth = (vel_right.odoemtry_float - vel_left.odoemtry_float) / L;

						curr_time = ros::Time::now();

						double dt = (curr_time - last_time).toSec();
						double delta_x = (vx * cos(th) - vy * sin(th)) * dt;
						double delta_y = (vx * sin(th) + vy * cos(th)) * dt;
						double delta_th = vth * dt;

						x += delta_x;
						y += delta_y;
						th += delta_th;
						last_time = curr_time;
					}
					else
					{
						ROS_INFO("Received data check sum error!");
					}
				}
			break;
			case SONAR_INFO:
				command = REQUIRE_WITH_ONLY_SONAR_INFO;
				if (buf[6 + _length] == ender[0] && buf[6 + _length + 1] == ender[1])
				{
					ReceiveCheckSum.data[0] = buf[5 + _length];
					if (_checkSum == ReceiveCheckSum.d)
					{
						for(i = 0; i < 4; i++)
						{
							sonar_front.odometry_char[i] = buf[i + 5];
							sonar_back.odometry_char[i] = buf[i + 9];
							sonar_left.odometry_char[i] = buf[i + 13];
							sonar_right.odometry_char[i] = buf[i + 17];
						}
						vx = (vel_right.odoemtry_float + vel_left.odoemtry_float) / 2 / 1000;
						vth = (vel_right.odoemtry_float - vel_left.odoemtry_float) / L;

						curr_time = ros::Time::now();

						double dt = (curr_time - last_time).toSec();
						double delta_x = (vx * cos(th) - vy * sin(th)) * dt;
						double delta_y = (vx * sin(th) + vy * cos(th)) * dt;
						double delta_th = vth * dt;

						x += delta_x;
						y += delta_y;
						th += delta_th;
						last_time = curr_time;
					}
					else
					{
						ROS_INFO("Received data check sum error!");
					}
				}
			break;
			case SIX_AXIS_SENSOR_INFO:
				command = REQUIRE_WITH_ONLY_SIX_AXIS_SENSOR_INFO;
				if (buf[6 + _length] == ender[0] && buf[6 + _length + 1] == ender[1])
				{
					ReceiveCheckSum.data[0] = buf[5 + _length];
					if (_checkSum == ReceiveCheckSum.d)
					{
						for(i = 0; i < 4; i++)
						{
							odom_pitch.odometry_char[i] = buf[i + 5];
							odom_roll.odometry_char[i] = buf[i + 9];
							odom_yaw.odometry_char[i] = buf[i + 13];
							temprature.odometry_char[i] = buf[i + 17];
						}
						vx = (vel_right.odoemtry_float + vel_left.odoemtry_float) / 2 / 1000;
						vth = (vel_right.odoemtry_float - vel_left.odoemtry_float) / L;

						curr_time = ros::Time::now();

						double dt = (curr_time - last_time).toSec();
						double delta_x = (vx * cos(th) - vy * sin(th)) * dt;
						double delta_y = (vx * sin(th) + vy * cos(th)) * dt;
						double delta_th = vth * dt;

						x += delta_x;
						y += delta_y;
						th += delta_th;
						last_time = curr_time;
					}
					else
					{
						ROS_INFO("Received data check sum error!");
					}
				}
			break;
		}
		for(i = 0; i < 12; i++)
		{
			_ID[i] = buf[8 + _length + i];
		}
		readConfigFile(FILENAME);
	}
}

void writeSerial(const geometry_msgs::Twist& msg)
{
	double RobotV = msg.linear.x * 1000;
	double YawRate = msg.angular.z;
	unsigned char buf_[16] = {0};
	int i, length = 0;
	double r = RobotV / YawRate;
	if(RobotV == 0)
	{
		leftdata.d = -YawRate * R;
		rightdata.d = YawRate * R;
	} else if(YawRate == 0)
	{
		leftdata.d = RobotV;
		rightdata.d = RobotV;
	}
	else
	{
		leftdata.d = YawRate * (r - R);
		rightdata.d = YawRate * (r + R);
	}
	for(i = 0; i < 2; i++)
	{
		buf_[i] = header[i];
	}
	send_command.d = 21850;
	for(i = 0; i < 2; i++)
	{
		buf_[i + 2] = send_command.data[i];
	}
	length = 8;
	buf_[4] = length;
	for(i = 0; i < 4; i++)
	{
		buf_[i + 5] = rightdata.data[i];
		buf_[i + 9] = leftdata.data[i];
	}
	buf_[5 + length] = Get_Crc8(buf_, 5 + length);
	buf_[6 + length] = ender[0];
	buf_[6 + length + 1] = ender[1];
	write(sp, buffer(buf_));
	readSerial();
}

void readConfigFile(char* filename)
{
	if (_READ)
	{
		ifstream file;
		file.open(filename, ios::in | ios::binary);
		if (file)
		{
			file >> read_str;
			if (compareID(_ID, read_str))
			{
				ROS_INFO("ID Compare Successful");
			}else
			{
				ROS_ERROR("ID Compare Failed");
				exit(-1);
			}
		} else
		{
			writeConfigFile(filename);
		}
		file.close();
		_READ = 0;
	}
}

void writeConfigFile(char* filename)
{
	ofstream file;
	file.open(filename, ios::out | ios::app | ios::binary);
	if (file)
	{
		file << toHexString(_ID, 12);
	} else
	{
		ROS_INFO("Error opening Config file %s!", filename);
	}
	file.close();
	_READ = 1;
}

int main(int argc, char** argv)
{
	FILENAME = strcat(getenv("HOME"), "/mrobot.config");
	try
	{
		// 设置参数
		sp.set_option(serial_port::baud_rate(115200));
		sp.set_option(serial_port::flow_control(serial_port::flow_control::none));
		sp.set_option(serial_port::parity(serial_port::parity::none));
		sp.set_option(serial_port::stop_bits(serial_port::stop_bits::one));
		sp.set_option(serial_port::character_size(8));
		ROS_INFO("Serial Port initialized successful.");
		ros::init(argc, argv, "serial_node");									//初始化节点
		ros::Time::init();
		current_time = ros::Time::now();
		last_time = ros::Time::now();
		ros::Rate loop_rate(50);
		ros::NodeHandle nh;
		ros::Publisher pub = nh.advertise<nav_msgs::Odometry>("odom", 50);		//定义发布消息的名称
		ros::Subscriber sub = nh.subscribe("cmd_vel", 50, &writeSerial);
		tf::TransformBroadcaster odom_broadcaster;
		ROS_INFO("ROS Node initialized successful.");

		while (ros::ok()) {
			ros::spinOnce();

			current_time = ros::Time::now();
			geometry_msgs::TransformStamped odom_trans;

			odom_trans.header.stamp = current_time;
			odom_trans.header.frame_id = "odom";
			odom_trans.child_frame_id = "base_footprint";

			geometry_msgs::Quaternion odom_quat;
			if (command == REQUIRE_WITH_ALL_INFO)
			{
				odom_quat = tf::createQuaternionMsgFromYaw(th);
				odom_trans.transform.translation.x = x;
				odom_trans.transform.translation.y = y;
				odom_trans.transform.translation.z = 0.0;
				odom_trans.transform.rotation = odom_quat;
				ROS_INFO("Left Speed: %.4f m/s.", vel_left.odoemtry_float / 1000);
				ROS_INFO("Right Speed: %.4f m/s.", vel_right.odoemtry_float / 1000);
				ROS_INFO("Battery Voltage: %.3f mV.", electricity.battery_float);
				ROS_INFO("Battery Electricity Percentage: %.3f%%.", battery_percentage.battery_float);
				ROS_INFO("Temprature: %.2f C.", temprature.odoemtry_float);
				ROS_INFO("Pitch: %.3f.", odom_pitch.odoemtry_float);
				ROS_INFO("Roll: %.3f.", odom_roll.odoemtry_float);
				ROS_INFO("Yaw: %.3f.", odom_yaw.odoemtry_float);
				ROS_INFO("Sonar front: %.3f m.", sonar_front.odoemtry_float);
				ROS_INFO("Sonar back: %.3f m.", sonar_back.odoemtry_float);
				ROS_INFO("Sonar left: %.3f m.", sonar_left.odoemtry_float);
				ROS_INFO("Sonar right: %.3f m.", sonar_right.odoemtry_float);
			} else if (command == REQUIRE_WITH_SIMPLE_INFO)
			{
				odom_quat = tf::createQuaternionMsgFromYaw(th);
				odom_trans.transform.translation.x = x;
				odom_trans.transform.translation.y = y;
				odom_trans.transform.translation.z = 0.0;
				odom_trans.transform.rotation = odom_quat;
				ROS_INFO("Left Speed: %.4f m/s.", vel_left.odoemtry_float / 1000);
				ROS_INFO("Right Speed: %.4f m/s.", vel_right.odoemtry_float / 1000);
				ROS_INFO("Battery Voltage: %.3f mV.", electricity.battery_float);
				ROS_INFO("Battery Electricity Percentage: %.3f%%.", battery_percentage.battery_float);
			} else if(command == REQUIRE_WITH_SIX_AXIS_SENSOR_INFO)
			{
				odom_quat = tf::createQuaternionMsgFromYaw(th);
				odom_trans.transform.translation.x = x;
				odom_trans.transform.translation.y = y;
				odom_trans.transform.translation.z = 0.0;
				odom_trans.transform.rotation = odom_quat;
				ROS_INFO("Left Speed: %.4f m/s.", vel_left.odoemtry_float / 1000);
				ROS_INFO("Right Speed: %.4f m/s.", vel_right.odoemtry_float / 1000);
				ROS_INFO("Battery Voltage: %.3f mV.", electricity.battery_float);
				ROS_INFO("Battery Electricity Percentage: %.3f%%.", battery_percentage.battery_float);
				ROS_INFO("Temprature: %.2f C.", temprature.odoemtry_float);
				ROS_INFO("Pitch: %.3f.", odom_pitch.odoemtry_float);
				ROS_INFO("Roll: %.3f.", odom_roll.odoemtry_float);
				ROS_INFO("Yaw: %.3f.", odom_yaw.odoemtry_float);
			} else
			{
				odom_quat = tf::createQuaternionMsgFromYaw(th);
				odom_trans.transform.translation.x = x;
				odom_trans.transform.translation.y = y;
				odom_trans.transform.translation.z = 0.0;
				odom_trans.transform.rotation = odom_quat;
			}

			//send the transform
			odom_broadcaster.sendTransform(odom_trans);

			nav_msgs::Odometry msgl;
			msgl.header.stamp = current_time;
			msgl.header.frame_id = "odom";

			msgl.pose.pose.position.x = x;
			msgl.pose.pose.position.y = y;
			msgl.pose.pose.position.z = 0.0;
			msgl.pose.pose.orientation = odom_quat;

			msgl.child_frame_id = "base_footprint";
			msgl.twist.twist.linear.x = vx;
			msgl.twist.twist.linear.y = vy;
			msgl.twist.twist.angular.z = vth;

			pub.publish(msgl);   											//发布消息
			command = -1;
			loop_rate.sleep();
		}
		iosev.run();
	}
	catch (exception& err)
	{
		ROS_ERROR("Exception Error: %s", err.what());
		return -1;
	}
	return 0;
}

max_stars_repo_name: ROSCLUB/mrobot

max_issues_repo_name: ROSCLUB/mrobot

max_forks_repo_name: ROSCLUB/mrobot


text:
#ifndef DYNAMIC_GRAPH_PY
#define DYNAMIC_GRAPH_PY

#include <iostream>
#include <sstream>

#include <boost/python.hpp>
#include <boost/python/stl_iterator.hpp>

#include <dynamic-graph/debug.h>
#include <dynamic-graph/exception-factory.h>
#include <dynamic-graph/signal-base.h>

#include "dynamic-graph/python/signal-wrapper.hh"

namespace bp = boost::python;

namespace dynamicgraph {
namespace python {

template <typename Iterator>
inline bp::list to_py_list(Iterator begin, Iterator end) {
  typedef typename Iterator::value_type T;
  bp::list lst;
  std::for_each(begin, end, [&](const T& t) { lst.append(t); });
  return lst;
}

template <typename Iterator>
inline bp::tuple to_py_tuple(Iterator begin, Iterator end) {
  return bp::tuple(to_py_list(begin, end));
}

template <typename T>
inline std::vector<T> to_std_vector(const bp::object& iterable) {
  return std::vector<T>(bp::stl_input_iterator<T>(iterable), bp::stl_input_iterator<T>());
}

void exposeSignals();

// Declare functions defined in other source files
namespace signalBase {
SignalBase<int>* createSignalWrapper(const char* name, const char* type, bp::object object);
}  // namespace signalBase
namespace entity {

/// \param obj an Entity object
void addCommands(boost::python::object obj);
void addSignals(boost::python::object obj);

Entity* create(const char* type, const char* name);
bp::object executeCmd(bp::tuple args, bp::dict);
}  // namespace entity

namespace factory {
bp::tuple getEntityClassList();
}
namespace pool {
void writeGraph(const char* filename);
bp::list getEntityList();
const std::map<std::string, Entity*>* getEntityMap();
}  // namespace pool
namespace debug {
void addLoggerFileOutputStream(const char* filename);
void addLoggerCoutOutputStream();
void closeLoggerFileOutputStream();
void realTimeLoggerSpinOnce();
void realTimeLoggerDestroy();
void realTimeLoggerInstance();
}  // namespace debug

}  // namespace python
}  // namespace dynamicgraph

#endif

ext: hh


text:
//  (C) Copyright Edward Diener 2011-2015
//  Use, modification and distribution are subject to the Boost Software License,
//  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt).

#include <boost/vmd/assert.hpp>
#include <boost/vmd/elem.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/preprocessor/comparison/equal.hpp>
#include <boost/preprocessor/seq/elem.hpp>
#include <boost/preprocessor/tuple/elem.hpp>

int main()
  {

#if BOOST_PP_VARIADICS

  #define A_SEQ_PLUS (mmf)(34)(^^)(!) 456

  BOOST_VMD_ASSERT(BOOST_PP_EQUAL(BOOST_PP_SEQ_ELEM(1,BOOST_PP_TUPLE_ELEM(0,BOOST_VMD_ELEM(0,A_SEQ_PLUS,BOOST_VMD_RETURN_AFTER,BOOST_VMD_TYPE_SEQ))),456),BOOST_VMD_TEST_FAIL_SEQ)

#endif

  return boost::report_errors();

  }

ext: cxx


text:
//------------------------------------------------------------------------------
/*
    This file is part of rippled: https://github.com/ripple/rippled
    Copyright (c) 2012, 2013 Ripple Labs Inc.

    Permission to use, copy, modify, and/or distribute this software for any
    purpose  with  or without fee is hereby granted, provided that the above
    copyright notice and this permission notice appear in all copies.

    THE  SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
    WITH  REGARD  TO  THIS  SOFTWARE  INCLUDING  ALL  IMPLIED  WARRANTIES  OF
    MERCHANTABILITY  AND  FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
    ANY  SPECIAL ,  DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
    WHATSOEVER  RESULTING  FROM  LOSS  OF USE, DATA OR PROFITS, WHETHER IN AN
    ACTION  OF  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================

#include <ripple/websocket/WebSocket04.h>
#include <ripple/websocket/Handler.h>
#include <ripple/websocket/Server.h>

#include <boost/make_shared.hpp>
#include <beast/weak_fn.h>

namespace ripple {
namespace websocket {

char const* WebSocket04::versionName()
{
    return "websocketpp 0.40";
}

void WebSocket04::handleDisconnect (Connection& connection)
{
    connection.close (websocketpp::close::status::protocol_error,
                      "overload");
}

void WebSocket04::closeTooSlowClient (
    Connection& connection,
    unsigned int timeout,
    std::string const& message)
{
    connection.close (
        websocketpp::close::status::value (timeout), message);
}

bool WebSocket04::isTextMessage (Message const& message)
{
    return message.get_opcode () == websocketpp::frame::opcode::text;
}

using HandlerPtr04 = WebSocket04::HandlerPtr;
using EndpointPtr04 = WebSocket04::EndpointPtr;

HandlerPtr04 WebSocket04::makeHandler (ServerDescription const& desc)
{
    return std::make_shared <HandlerImpl <WebSocket04>> (desc);
}

EndpointPtr04  WebSocket04::makeEndpoint (HandlerPtr&& handler)
{
    auto endpoint = std::make_shared <Endpoint> (std::move (handler));

    endpoint->set_open_handler (
        [endpoint] (websocketpp::connection_hdl hdl) {
            if (auto conn = endpoint->get_con_from_hdl(hdl))
                endpoint->handler()->on_open (conn);
        });

    endpoint->set_close_handler (
        [endpoint] (websocketpp::connection_hdl hdl) {
            if (auto conn = endpoint->get_con_from_hdl(hdl))
                endpoint->handler()->on_close (conn);
        });

    endpoint->set_fail_handler (
        [endpoint] (websocketpp::connection_hdl hdl) {
            if (auto conn = endpoint->get_con_from_hdl(hdl))
                endpoint->handler()->on_fail (conn);
        });

    endpoint->set_pong_handler (
        [endpoint] (websocketpp::connection_hdl hdl, std::string data) {
            if (auto conn = endpoint->get_con_from_hdl(hdl))
                endpoint->handler()->on_pong (conn, data);
        });

    endpoint->set_http_handler (
        [endpoint] (websocketpp::connection_hdl hdl) {
            if (auto conn = endpoint->get_con_from_hdl(hdl))
                endpoint->handler()->http (conn);
        });

    endpoint->set_message_handler (
        [endpoint] (websocketpp::connection_hdl hdl,
                    MessagePtr msg) {
            if (auto conn = endpoint->get_con_from_hdl(hdl))
                endpoint->handler()->on_message (conn, msg);
        });

    endpoint->set_send_empty_handler (
        [endpoint] (websocketpp::connection_hdl hdl) {
            if (auto conn = endpoint->get_con_from_hdl(hdl))
                endpoint->handler()->on_send_empty (conn);
        });

    endpoint->init_asio();

    return endpoint;
}

template <>
void ConnectionImpl <WebSocket04>::setPingTimer ()
{
    auto freq = getConfig ().WEBSOCKET_PING_FREQ;
    if (freq <= 0)
        return;
    if (auto con = m_connection.lock ())
    {
        auto t = boost::posix_time::seconds (freq);
        auto ms = t.total_milliseconds();
        con->set_timer (
            ms,
            std::bind (
                beast::weak_fn (&ConnectionImpl <WebSocket04>::pingTimer,
                                shared_from_this()),
                beast::asio::placeholders::error));
    }
}

boost::asio::io_service::strand& WebSocket04::getStrand (Connection& con)
{
    return *con.get_strand();
}

template <>
void Server <WebSocket04>::listen()
{
    m_endpoint->listen (desc_.port.ip, desc_.port.port);
    m_endpoint->start_accept();
    auto c = m_endpoint->get_io_service ().run ();
    WriteLog (lsWARNING, WebSocket)
            << "Server run with: '" << c;

}

std::unique_ptr<beast::Stoppable> makeServer04 (ServerDescription const& desc)
{
    return std::make_unique <Server <WebSocket04>> (desc);
}

} // websocket
} // ripple

max_stars_repo_name: tdfischer/rippled

max_issues_repo_name: tdfischer/rippled

max_forks_repo_name: tdfischer/rippled


text:
#include "Epetra_ConfigDefs.h"
#ifdef HAVE_MPI
#include "mpi.h"
#include "Epetra_MpiComm.h"
#else
#include "Epetra_SerialComm.h"
#endif

#include "Teuchos_CommandLineProcessor.hpp"
#include "Teuchos_StandardCatchMacros.hpp"
#include "Teuchos_ParameterList.hpp"
#include "Teuchos_XMLParameterListCoreHelpers.hpp"

#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_real_distribution.hpp>
#include <boost/math/special_functions/erf.hpp>
#include <boost/random/normal_distribution.hpp>
#include <boost/math/special_functions/gamma.hpp>
#include <boost/math/special_functions/beta.hpp>

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

    std::string    xmlInFileName = "";
    std::string    extraXmlFile = "";
    std::string    xmlOutFileName = "paramList.out";

    Teuchos::CommandLineProcessor  clp(false);
    clp.setOption("xml-in-file",&xmlInFileName,"The XML file to read into a parameter list");
    clp.setDocString("TO DO.");

    Teuchos::CommandLineProcessor::EParseCommandLineReturn
    parse_return = clp.parse(argc,argv);
    if( parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) {
        std::cout << "\nEnd Result: TEST FAILED" << std::endl;
        return parse_return;
    }

#ifdef HAVE_MPI
    MPI_Init(&argc, &argv);
    Epetra_MpiComm Comm(MPI_COMM_WORLD);
#else
    Epetra_SerialComm Comm;
#endif

    Teuchos::RCP<Teuchos::ParameterList> paramList = Teuchos::rcp(new Teuchos::ParameterList);
    if(xmlInFileName.length()) {
        Teuchos::updateParametersFromXmlFile(xmlInFileName, inoutArg(*paramList));
        if (Comm.MyPID()==0){
            paramList->print(std::cout,2,true,true);
        }
    }

    double a = -6.0;
    double b = 6.0;
    int n = 10;
    double v;

    double alpha = 1.0/(0.1*0.1);
    double beta  = 1771.0*0.1*0.1;
    for (int i=0; i<n; ++i){
       v = a + (b-a)*double(i)/double(n-1);
       double erfx = boost::math::erf<double>(v/std::sqrt(2.0));
       double y = (1.0/2.0)*(1.0 + erfx);
       double yinv = boost::math::gamma_p_inv<double,double>(alpha,y);
       double g = yinv*beta;

       std::cout << v << std::setw(15) << g << "\n";
    }

    /*double mean = 0.0;
    double stan = 1.0;
    boost::random::normal_distribution<> w(mean,stan);
    boost::random::mt19937 rng;
    rng.seed(std::time(0));
    for (unsigned int i=0; i<10; ++i){
        double x = w(rng);
        double erfarg = (x-mean)/(stan*std::sqrt(2.0));
        double erfx = boost::math::erf<double>(erfarg);
        double y = (1.0/2.0)*(1.0 + erfx);
        double yinv = boost::math::gamma_p_inv<double,double>(1.0/(0.1*0.1),y);
        double z = yinv*10.0*0.1*0.1;
        double z2 = boost::math::ibeta_inv<double,double,double>(5.0,4.0,y);
        std::cout << x << std::setw(20) << y << std::setw(20) << z << std::setw(20) << z2 << "\n";
    }*/

#ifdef HAVE_MPI
    MPI_Finalize();
#endif
return 0;

}

max_stars_repo_name: bstaber/Trilinos

max_issues_repo_name: bstaber/Trilinos

max_forks_repo_name: bstaber/Trilinos


text:
#include <boost/property_tree/json_parser.hpp>
#include <stdexcept>
#include <fstream>
#include "options.h"

namespace common
{

boost::program_options::variables_map Options::getCmdLine(int argc, char *argv[]) const
{
    using namespace boost::program_options;
    options_description allDescription = getCmdLineDescription();
    variables_map vm;
    store(parse_command_line(argc, argv, allDescription), vm);
    return vm;
}

boost::program_options::options_description Options::getCmdLineDescription() const
{
    using namespace boost::program_options;
    options_description config("Config files");
    config.add_options()
            ("config_default", value<std::string>(), "config_default file name")
            ("config_override", value<std::string>(), "config_override file name")
            ;

    boost::program_options::options_description extra_description;
    // add to extra_description here

    boost::program_options::options_description all_description;
    all_description.add(config).add(extra_description);
    return all_description;
}

// for now, only from config_default file assuming no duplicates
//TODO: deal with duplicats
// Remove dups from the same config file
// overrie and add from ( in order)  1.config_override file, 2. enviroment variables 3.cmd line
void Options::setProperties( const boost::program_options::variables_map& cmdLine)
{
    const std::string& config_default = cmdLine["config_default"].as<std::string>();
    if(config_default.empty()){
        return;
    }
    boost::property_tree::read_json(config_default, _properties);

}

}


text:
#include "worldserver.h"

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

#include "app.h"

ProtobufMsgDispatcher dispatcher;

int main (int argc, const char* argv[])
{
	//BasicConfigurator::configure();

	NetApp app("worldserver", dispatcher, dispatcher);

	app.main(argc, argv);
}

max_stars_repo_name: david-pp/tinyworld

max_issues_repo_name: david-pp/tinyworld-servers

max_forks_repo_name: david-pp/tinyworld-servers


text:
//include <scottgs/Timing.hpp>

#include <iostream>
#include <cstdlib>
#include <algorithm>

#include "FloatMatrix.hpp"
#include "MatrixMultiply.hpp"

#include <boost/numeric/ublas/io.hpp>

void initRandomMatrix(scottgs::FloatMatrix& m);

int main(int argc, char * argv[])
{
	std::cout << "Homework 1" << std::endl
		  << "Grant Scott (scottgs)" << std::endl;  // CHANGE TO YOUR name AND pawprint

	// ---------------------------------------------
	// BEGIN: Self Test Portion
	// ---------------------------------------------
	std::cout << "Running Self Test" << std::endl
		  << "-----------------" << std::endl;
	scottgs::FloatMatrix l42(4, 2);
	l42(0,0) = 2; l42(0,1) = 3;
	l42(1,0) = 4; l42(1,1) = 5;
	l42(2,0) = 6; l42(2,1) = 7;
	l42(3,0) = 8; l42(3,1) = 9;

	scottgs::FloatMatrix r23(2,3);
	r23(0,0) = 2; r23(0,1) = 3; r23(0,2) = 4;
	r23(1,0) = 5; r23(1,1) = 6; r23(1,2) = 7;

	// (19,24,29),(33,42,51),(47,60,73),(61,78,95)
	scottgs::FloatMatrix er(4,3);
	er(0,0) = 19; er(0,1) = 24; er(0,2) = 29;
	er(1,0) = 33; er(1,1) = 42; er(1,2) = 51;
	er(2,0) = 47; er(2,1) = 60; er(2,2) = 73;
	er(3,0) = 61; er(3,1) = 78; er(3,2) = 95;

	scottgs::MatrixMultiply mm;
	scottgs::FloatMatrix result = mm(l42,r23);
	std::cout << "Result of " << std::endl << l42 << std::endl
		  << "   times  " << std::endl << r23 << std::endl
		  << "  equals  " << std::endl << result << std::endl;

	if ( ! std::equal( er.data().begin(), er.data().end(), result.data().begin() ) )
	{
		std::cerr << "Self Test Expected Result: " << er << std::endl
			  << "           ... but found : " << result << std::endl;
		return 1;
	}

	scottgs::FloatMatrix result2 = mm.multiply(l42,r23);
	std::cout << "Result of " << std::endl << l42 << std::endl
		  << "   times  " << std::endl << r23 << std::endl
		  << "  equals  " << std::endl << result2 << std::endl;

	if ( ! std::equal( er.data().begin(), er.data().end(), result2.data().begin() ) )
	{
		std::cerr << "Self Test Expected Result: " << er << std::endl
			  << "           ... but found : " << result2 << std::endl;
		return 1;
	}

	std::cout << "Self Test Complete" << std::endl
		  << "==================" << std::endl;

	// ---------------------------------------------
	// END: Self Test Portion
	// ---------------------------------------------

	return 0;
}

max_stars_repo_name: samkreter/High-Performance-Computing

max_issues_repo_name: samkreter/High-Performance-Computing

max_forks_repo_name: samkreter/High-Performance-Computing