text:
#include "irods/SHA256Strategy.hpp"
#include "irods/checksum.h"

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <boost/algorithm/string/predicate.hpp>
#include <openssl/sha.h>

#include "irods/base64.h"

namespace irods {

    const std::string SHA256_NAME( "sha256" );

    error
    SHA256Strategy::init( boost::any& _context ) const {
        _context = SHA256_CTX();
        SHA256_Init( boost::any_cast<SHA256_CTX>( &_context ) );
        return SUCCESS();
    }

    error
    SHA256Strategy::update( const std::string& data, boost::any& _context ) const {
        SHA256_Update( boost::any_cast<SHA256_CTX>( &_context ), data.c_str(), data.size() );
        return SUCCESS();
    }

    error
    SHA256Strategy::digest( std::string& _messageDigest, boost::any& _context ) const {
        unsigned char final_buffer[SHA256_DIGEST_LENGTH];
        SHA256_Final( final_buffer, boost::any_cast<SHA256_CTX>( &_context ) );
        int len = strlen( SHA256_CHKSUM_PREFIX );
        unsigned long out_len = CHKSUM_LEN - len;

        unsigned char out_buffer[CHKSUM_LEN];
        base64_encode( final_buffer, SHA256_DIGEST_LENGTH, out_buffer, &out_len );

        _messageDigest = SHA256_CHKSUM_PREFIX;
        _messageDigest += std::string( ( char* )out_buffer, out_len );

        return SUCCESS();
    }

    bool
    SHA256Strategy::isChecksum( const std::string& _chksum ) const {
        return boost::starts_with( _chksum, SHA256_CHKSUM_PREFIX );
    }
}; // namespace irods

ext: cpp

max_stars_repo_name: aghsmith/irods

max_issues_repo_name: selroc/irods

max_forks_repo_name: selroc/irods


text:
/*
 * float_encoding_unitttest.cpp
 *
 *  Created on: 30 paź 2015
 *      Author: ghash
 */

#include "test/compression_unittest_base.hpp"
#include "float_encoding.hpp"
#include <gtest/gtest.h>
#include <boost/bind.hpp>

namespace ddj
{

class FloatEncodingTest : public CompressionUnittestBase {};

INSTANTIATE_TEST_CASE_P(
    FloatEncoding_Compression_Inst,
    FloatEncodingTest,
    ::testing::Values(100, 100000));

TEST_P(FloatEncodingTest, CompressionOfRandomFloats_WithMaxPrecision_3_size)
{
    FloatEncoding encoder;
    EXPECT_TRUE(
		TestSize<float>(
			boost::bind(&FloatEncoding::Encode<float>, encoder, _1),
			boost::bind(&FloatEncoding::Decode<float>, encoder, _1),
			GetFloatRandomDataWithMaxPrecision(3))
    );
}

TEST_P(FloatEncodingTest, CompressionOfRandomFloats_WithMaxPrecision_3_data)
{
	FloatEncoding encoder;
	EXPECT_TRUE(
		TestContent<float>(
			boost::bind(&FloatEncoding::Encode<float>, encoder, _1),
			boost::bind(&FloatEncoding::Decode<float>, encoder, _1),
			GetFloatRandomDataWithMaxPrecision(3))
	);
}

TEST_P(FloatEncodingTest, CompressionOf_Float_FromFile)
{
	FloatEncoding encoder;
	EXPECT_TRUE(
		TestContent<float>(
			boost::bind(&FloatEncoding::Encode<float>, encoder, _1),
			boost::bind(&FloatEncoding::Decode<float>, encoder, _1),
			GetTsFloatDataFromTestFile())
	);
}

TEST_P(FloatEncodingTest, CompressionOf_PatternA_Short)
{
	FloatEncoding encoder;
	EXPECT_TRUE(
		TestContent<short>(
			boost::bind(&FloatEncoding::Encode<short>, encoder, _1),
			boost::bind(&FloatEncoding::Decode<short>, encoder, _1),
			GetFakeDataWithPatternA<short>(0, GetSize()/3, 1, 0, 1e3))
	);
}

TEST_P(FloatEncodingTest, CompressionOf_PatternA_Char)
{
	FloatEncoding encoder;
	EXPECT_TRUE(
		TestContent<char>(
			boost::bind(&FloatEncoding::Encode<char>, encoder, _1),
			boost::bind(&FloatEncoding::Decode<char>, encoder, _1),
			GetFakeDataWithPatternA<char>(0, GetSize()/3, 1, 0, 1e2))
	);
}

TEST_P(FloatEncodingTest, GetMetadataSize_Consecutive_Int)
{
	TestGetMetadataSize<FloatEncoding, int>(GetIntConsecutiveData());
}

TEST_P(FloatEncodingTest, GetCompressedSize_Consecutive_Int)
{
	TestGetCompressedSize<FloatEncoding, int>(GetIntConsecutiveData());
}

} /* namespace ddj */

max_stars_repo_licenses: MIT Unlicense

max_issues_repo_licenses: MIT Unlicense

max_forks_repo_licenses: MIT Unlicense


text:
// Copyright 2017, 2019 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.

#include <boost/hash2/is_uniquely_represented.hpp>
#include <boost/hash2/byte_type.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/config.hpp>
#include <cstddef>

class X;

struct Y
{
};

enum E
{
    v
};

template<class T> void test_true_()
{
    using boost::hash2::is_uniquely_represented;

    BOOST_TEST_TRAIT_TRUE((is_uniquely_represented<T>));
    BOOST_TEST_TRAIT_TRUE((is_uniquely_represented<T const>));
    BOOST_TEST_TRAIT_TRUE((is_uniquely_represented<T[2]>));
    BOOST_TEST_TRAIT_TRUE((is_uniquely_represented<T const [2]>));
}

template<class T> void test_false_()
{
    using boost::hash2::is_uniquely_represented;

    BOOST_TEST_TRAIT_FALSE((is_uniquely_represented<T>));
    BOOST_TEST_TRAIT_FALSE((is_uniquely_represented<T const>));
    BOOST_TEST_TRAIT_FALSE((is_uniquely_represented<T[2]>));
    BOOST_TEST_TRAIT_FALSE((is_uniquely_represented<T const [2]>));
}

template<class T> void test_true()
{
    test_true_<T>();
    test_true_<T*>();
    test_true_<T[2]>();
    test_true_<T[2][2]>();
}

template<class T> void test_false()
{
    test_false_<T>();
    test_true_<T*>();
    test_false_<T[2]>();
    test_false_<T[2][2]>();
}

int main()
{
    test_true_<bool>();

    test_true_<char>();
    test_true_<signed char>();
    test_true_<unsigned char>();
    test_true_<wchar_t>();

#if !defined(BOOST_NO_CXX11_CHAR16_T)
    test_true_<char16_t>();
#endif

#if !defined(BOOST_NO_CXX11_CHAR32_T)
    test_true_<char32_t>();
#endif

    test_true_<short>();
    test_true_<unsigned short>();
    test_true_<int>();
    test_true_<unsigned int>();
    test_true_<long>();
    test_true_<unsigned long>();
    test_true_<unsigned short>();

    test_false_<float>();
    test_false_<double>();
    test_false_<long double>();

#if !defined(BOOST_NO_CXX11_NULLPTR)
    test_false_<std::nullptr_t>();
#endif

    test_true_<void*>();
    test_true_<void const*>();

    test_true_<void(*)()>();

    test_true_<E>();

    test_false_<X>();
    test_false_<Y>();

    test_true_<boost::hash2::byte_type>();

    return boost::report_errors();
}


text:
/**
 *  @file
 *  @copyright defined in evt/LICENSE.txt
 */
#include <boost/algorithm/string.hpp>
#include <evt/chain/exceptions.hpp>
#include <evt/chain/name.hpp>
#include <fc/exception/exception.hpp>
#include <fc/variant.hpp>

namespace evt { namespace chain {

void
name::set(const char* str) {
    const auto len = strnlen(str, 14);
    EVT_ASSERT(len <= 13, name_type_exception, "Name is longer than 13 characters (${name}) ", ("name", string(str)));
    value = string_to_name(str);
    EVT_ASSERT(to_string() == string(str), name_type_exception,
               "Name not properly normalized (name: ${name}, normalized: ${normalized}) ",
               ("name", string(str))("normalized", to_string()));
}

void
name128::set(const char* str) {
    const auto len = strnlen(str, 22);
    EVT_ASSERT(len <= 21, name_type_exception, "Name128 is longer than 21 characters (${name}) ",
               ("name", string(str)));
    value = string_to_name128(str);
    EVT_ASSERT(to_string() == string(str), name_type_exception,
               "Name128 not properly normalized (name: ${name}, normalized: ${normalized}) ",
               ("name", string(str))("normalized", to_string()));
}

name::operator string() const {
    static const char* charmap = ".12345abcdefghijklmnopqrstuvwxyz";

    string str(13, '.');

    uint64_t tmp = value;
    for(uint32_t i = 0; i <= 12; ++i) {
        char c      = charmap[tmp & (i == 0 ? 0x0f : 0x1f)];
        str[12 - i] = c;
        tmp >>= (i == 0 ? 4 : 5);
    }

    boost::algorithm::trim_right_if(str, [](char c) { return c == '.'; });
    return str;
}

name128::operator string() const {
    static const char* charmap = ".-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

    string str(21, '.');

    uint128_t tmp = value;
    tmp >>= 2;
    for(uint32_t i = 0; i <= 20; ++i) {
        char c      = charmap[tmp & 0x3f];
        str[20 - i] = c;
        tmp >>= 6;
    }

    boost::algorithm::trim_right_if(str, [](char c) { return c == '.'; });
    return str;
}

}}  // namespace evt::chain

namespace fc {
void
to_variant(const evt::chain::name& c, fc::variant& v) {
    v = std::string(c);
}
void
from_variant(const fc::variant& v, evt::chain::name& check) {
    check = v.get_string();
}
void
to_variant(const evt::chain::name128& c, fc::variant& v) {
    v = std::string(c);
}
void
from_variant(const fc::variant& v, evt::chain::name128& check) {
    check = v.get_string();
}
}  // namespace fc


text:
#include <Tanker/Users/Requester.hpp>

#include <Tanker/Crypto/Crypto.hpp>
#include <Tanker/Crypto/Format/Format.hpp>
#include <Tanker/Errors/Errc.hpp>
#include <Tanker/Errors/Exception.hpp>
#include <Tanker/Network/HttpClient.hpp>
#include <Tanker/Serialization/Serialization.hpp>
#include <Tanker/Share.hpp>
#include <Tanker/Tracer/ScopeTimer.hpp>
#include <Tanker/Utils.hpp>

#include <boost/algorithm/string/predicate.hpp>
#include <fmt/format.h>
#include <mgs/base64.hpp>
#include <mgs/base64url.hpp>
#include <nlohmann/json.hpp>
#include <range/v3/functional/compose.hpp>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/transform.hpp>

namespace Tanker::Users
{
namespace
{
std::vector<Trustchain::UserAction> fromBlocksToUserActions(
    gsl::span<std::string const> blocks)
{
  return blocks |
         ranges::views::transform(ranges::compose(
             &Trustchain::deserializeUserAction, mgs::base64::lazy_decode())) |
         ranges::to<std::vector>;
}

std::vector<Trustchain::KeyPublishAction> fromBlocksToKeyPublishActions(
    gsl::span<std::string const> blocks)
{
  return blocks |
         ranges::views::transform(
             ranges::compose(&Trustchain::deserializeKeyPublishAction,
                             mgs::base64::lazy_decode())) |
         ranges::to<std::vector>;
}

template <typename T>
std::vector<std::string> base64KeyPublishActions(std::vector<T> const& actions)
{
  return actions | ranges::views::transform([](auto const& action) {
           return mgs::base64::encode(Serialization::serialize(action));
         }) |
         ranges::to<std::vector>;
}
}

Requester::Requester(Network::HttpClient* httpClient) : _httpClient(httpClient)
{
}

tc::cotask<Requester::GetResult> Requester::getUsersImpl(
    nlohmann::json const& query)
{
  auto url = _httpClient->makeUrl("user-histories", query);
  auto const response = TC_AWAIT(_httpClient->asyncGet(url)).value();
  auto rootBlock =
      Serialization::deserialize<Trustchain::Actions::TrustchainCreation>(
          mgs::base64::decode(response.at("root").get<std::string>()));
  TC_RETURN((GetResult{
      std::move(rootBlock),
      fromBlocksToUserActions(
          response.at("histories").get<std::vector<std::string>>())}));
}

tc::cotask<Requester::GetResult> Requester::getRevokedDeviceHistory(
    Trustchain::DeviceId const& deviceId)
{
  auto url = _httpClient->makeUrl(
      fmt::format("devices/{:#S}/revoked-device-history", deviceId));
  auto const response = TC_AWAIT(_httpClient->asyncGet(url)).value();
  auto rootBlock =
      Serialization::deserialize<Trustchain::Actions::TrustchainCreation>(
          mgs::base64::decode(response.at("root").get<std::string>()));
  TC_RETURN(
      (GetResult{std::move(rootBlock),
                 fromBlocksToUserActions(
                     response.at("history").get<std::vector<std::string>>())}));
}

tc::cotask<Requester::GetResult> Requester::getUsers(
    gsl::span<Trustchain::UserId const> userIds, IsLight isLight)
{
  auto const query = nlohmann::json{
      {"user_ids[]",
       userIds | ranges::views::transform(mgs::base64url_nopad::lazy_encode())},
      {"is_light", isLight == IsLight::Yes ? "true" : "false"}};
  TC_RETURN(TC_AWAIT(getUsersImpl(query)));
}

tc::cotask<Requester::GetResult> Requester::getUsers(
    gsl::span<Trustchain::DeviceId const> deviceIds, IsLight isLight)
{
  auto const query = nlohmann::json{
      {"device_ids[]",
       deviceIds |
           ranges::views::transform(mgs::base64url_nopad::lazy_encode())},
      {"is_light", isLight == IsLight::Yes ? "true" : "false"}};
  TC_RETURN(TC_AWAIT(getUsersImpl(query)));
}

tc::cotask<std::vector<Trustchain::KeyPublishAction>>
Requester::getKeyPublishes(gsl::span<Trustchain::ResourceId const> resourceIds)
{
  auto const query =
      nlohmann::json{{"resource_ids[]",
                      resourceIds | ranges::views::transform(
                                        mgs::base64url_nopad::lazy_encode())}};
  auto url = _httpClient->makeUrl("resource-keys", query);
  auto const response = TC_AWAIT(_httpClient->asyncGet(url)).value();
  TC_RETURN(fromBlocksToKeyPublishActions(
      response.at("resource_keys").get<std::vector<std::string>>()));
}

tc::cotask<void> Requester::postResourceKeys(Share::ShareActions const& actions)
{
  auto const response =
      TC_AWAIT(_httpClient->asyncPost(
                   _httpClient->makeUrl("resource-keys"),
                   {{"key_publishes_to_user",
                     base64KeyPublishActions(actions.keyPublishesToUsers)},
                    {"key_publishes_to_user_group",
                     base64KeyPublishActions(actions.keyPublishesToUserGroups)},
                    {"key_publishes_to_provisional_user",
                     base64KeyPublishActions(
                         actions.keyPublishesToProvisionalUsers)}}))
          .value();
}

tc::cotask<void> Requester::revokeDevice(
    Trustchain::Actions::DeviceRevocation const& deviceRevocation)
{
  TC_AWAIT(
      _httpClient->asyncPost(
          _httpClient->makeUrl("device-revocations"),
          {{"device_revocation",
            mgs::base64::encode(Serialization::serialize(deviceRevocation))}}))
      .value();
}

tc::cotask<IRequester::GetEncryptionKeyResult> Requester::getEncryptionKey(
    Trustchain::UserId const& userId,
    Crypto::PublicSignatureKey const& ghostDevicePublicSignatureKey)
{
  using namespace fmt::literals;

  auto query = nlohmann::json{
      {"ghost_device_public_signature_key",
       mgs::base64url_nopad::encode(ghostDevicePublicSignatureKey)}};
  auto url = _httpClient->makeUrl(
      fmt::format("users/{userId:#S}/encryption-key", "userId"_a = userId),
      query);
  auto const res = TC_AWAIT(_httpClient->asyncGet(url)).value();
  TC_RETURN((GetEncryptionKeyResult{
      res.at("encrypted_user_private_encryption_key")
          .get<Crypto::SealedPrivateEncryptionKey>(),
      res.at("ghost_device_id").get<Trustchain::DeviceId>()}));
}

tc::cotask<std::map<
    HashedEmail,
    std::pair<Crypto::PublicSignatureKey, Crypto::PublicEncryptionKey>>>
Requester::getPublicProvisionalIdentities(
    gsl::span<HashedEmail const> hashedEmails)
{
  std::map<HashedEmail,
           std::pair<Crypto::PublicSignatureKey, Crypto::PublicEncryptionKey>>
      ret;
  if (hashedEmails.empty())
    TC_RETURN(ret);

  auto query = nlohmann::json{
      {"hashed_emails",
       hashedEmails | ranges::views::transform(mgs::base64::lazy_encode())}};
  auto url = _httpClient->makeUrl("public-provisional-identities");
  auto const result = TC_AWAIT(_httpClient->asyncPost(url, query)).value();
  auto const publicIdentitites = result.at("public_provisional_identities");
  for (auto const& elem : publicIdentitites.at("hashed_emails"))
  {
    auto const hashedEmail = elem.at("value").get<HashedEmail>();
    auto const publicSignatureKey =
        elem.at("public_signature_key").get<Crypto::PublicSignatureKey>();
    auto const publicEncryptionKey =
        elem.at("public_encryption_key").get<Crypto::PublicEncryptionKey>();
    ret[hashedEmail] = {publicSignatureKey, publicEncryptionKey};
  }
  TC_RETURN(ret);
}

tc::cotask<std::map<
    HashedPhoneNumber,
    std::pair<Crypto::PublicSignatureKey, Crypto::PublicEncryptionKey>>>
Requester::getPublicProvisionalIdentities(
    gsl::span<HashedPhoneNumber const> hashedPhoneNumbers)
{
  std::map<HashedPhoneNumber,
           std::pair<Crypto::PublicSignatureKey, Crypto::PublicEncryptionKey>>
      ret;
  if (hashedPhoneNumbers.empty())
    TC_RETURN(ret);

  auto query =
      nlohmann::json{{"hashed_phone_numbers",
                      hashedPhoneNumbers | ranges::views::transform(
                                               mgs::base64::lazy_encode())}};
  auto url = _httpClient->makeUrl("public-provisional-identities");
  auto const result = TC_AWAIT(_httpClient->asyncPost(url, query)).value();
  auto const publicIdentitites = result.at("public_provisional_identities");
  for (auto const& elem : publicIdentitites.at("hashed_phone_numbers"))
  {
    auto const hashedPhoneNumber = elem.at("value").get<HashedPhoneNumber>();
    auto const publicSignatureKey =
        elem.at("public_signature_key").get<Crypto::PublicSignatureKey>();
    auto const publicEncryptionKey =
        elem.at("public_encryption_key").get<Crypto::PublicEncryptionKey>();
    ret[hashedPhoneNumber] = {publicSignatureKey, publicEncryptionKey};
  }
  TC_RETURN(ret);
}
}

max_stars_repo_name: TankerHQ/sdk-native

max_issues_repo_name: TankerHQ/sdk-native

max_forks_repo_name: TankerHQ/sdk-native


text:
#include "graph.hpp"
#include "nodes.hpp"

#include <Aquila/types/SyncedMemory.hpp>

#include <Aquila/core.hpp>
#include <Aquila/core/IAlgorithm.hpp>
#include <Aquila/core/IGraph.hpp>
#include <Aquila/framegrabbers/IFrameGrabber.hpp>
#include <Aquila/nodes/INode.hpp>
#include <Aquila/nodes/NodeInfo.hpp>

#include <MetaObject/MetaParameters.hpp>
#include <MetaObject/core/SystemTable.hpp>
#include <MetaObject/logging/profiling.hpp>
#include <MetaObject/object/RelayManager.hpp>
#include <MetaObject/python/MetaObject.hpp>
#include <MetaObject/python/PythonSetup.hpp>
#include <MetaObject/python/rcc_ptr.hpp>
#include <MetaObject/thread/Thread.hpp>
#include <MetaObject/thread/ThreadRegistry.hpp>

#include <boost/functional.hpp>
#include <boost/python.hpp>
#include <boost/python/return_internal_reference.hpp>
#include <boost/python/signature.hpp>

#include <thread>

namespace aq
{
    namespace python
    {

        void setupGraphInterface()
        {
            static bool setup = false;
            if (setup)
            {
                return;
            }
            MO_LOG(info, "Registering IGraph to python");
            setup = true;
        }

        template <class T>
        void addNode(const rcc::shared_ptr<aq::IGraph>& graph, GraphOwnerWrapper<T>& wrapper)
        {
            graph->addNode(wrapper.obj);
            wrapper.graph = graph;
        }

        std::vector<std::string> getSlots(const rcc::shared_ptr<aq::IGraph>& graph)
        {
            std::vector<std::string> out;
            auto mgr = graph->getRelayManager();
            if (mgr)
            {
                auto relays = mgr->getAllRelays();
                for (const auto& pair : relays)
                {
                    std::stringstream ss;
                    ss << pair.second << " - " << mo::TypeTable::instance()->typeToName(pair.first->getSignature());
                    out.push_back(ss.str());
                }
            }
            return out;
        }

        void emitsignal(const rcc::shared_ptr<aq::IGraph>& graph, const std::string& name)
        {
            auto mgr = graph->getRelayManager();
            auto relay = mgr->getRelayOptional<void(void)>(name);
            if (relay)
            {
                auto current = mo::IAsyncStream::current();
                (*relay)(*current);
            }
            else
            {
                auto all_relays = mgr->getAllRelays();
                std::string suggestions;
                for (const auto& relay : all_relays)
                {
                    if (relay.second.find(name) != std::string::npos)
                    {
                        suggestions += relay.second + ", ";
                    }
                }
                if (!suggestions.empty())
                {
                    MO_LOG(info, "Unable to find relay with name {} did you mean: {}", name, suggestions);
                }
            }
        }

        rcc::shared_ptr<aq::IGraph> makeGraph(IObjectConstructor* ctr)
        {
            rcc::shared_ptr<aq::IGraph> output;
            auto obj = ctr->Construct();
            if (obj)
            {
                output = obj;
                output->Init(true);
                auto table = SystemTable::instance();
                if (table)
                {
                    auto graphs = table->getSingleton<std::vector<rcc::weak_ptr<aq::IGraph>>>();
                    if (!graphs)
                    {
                        graphs = std::make_shared<std::vector<rcc::weak_ptr<aq::IGraph>>>();
                        table->setSingleton(graphs);
                    }
                    if (graphs)
                    {
                        graphs->push_back(output);
                    }
                }
            }
            return output;
        }

        bool waitSignal(const rcc::shared_ptr<aq::IGraph>& graph, const std::string& name, int timeout)
        {
            bool received = false;
            if (graph)
            {
                auto mgr = graph->getRelayManager();

                if (mgr->getRelayOptional<void(void)>(name))
                {
                    auto relay = mgr->getRelay<void(void)>(name);
                    boost::condition_variable cv;
                    boost::mutex mtx;
                    mo::TSlot<void(void)> slot([&cv, &received]() {
                        received = true;
                        cv.notify_all();
                    });
                    slot.connect(relay);
                    if (timeout == 0)
                    {
                        boost::unique_lock<boost::mutex> lock(mtx);
                        cv.wait(lock);
                    }
                    else
                    {
                        boost::unique_lock<boost::mutex> lock(mtx);
                        cv.wait_for(lock, boost::chrono::milliseconds(timeout));
                    }
                }
                else
                {
                    MO_LOG(info, "{} not a valid signal", name);
                }
            }
            return received;
        }

        void setupGraphObjects(std::vector<IObjectConstructor*>& ctrs)
        {
            for (auto itr = ctrs.begin(); itr != ctrs.end();)
            {
                if ((*itr)->GetObjectInfo()->GetObjectName() == "Graph")
                {
                    boost::python::object module(
                        boost::python::handle<>(boost::python::borrowed(PyImport_AddModule("aquila"))));

                    boost::python::class_<aq::IGraph,
                                          rcc::shared_ptr<aq::IGraph>,
                                          boost::python::bases<mo::IMetaObject>,
                                          boost::noncopyable>
                        bpobj("Graph", boost::python::no_init);
                    bpobj.def("__init__",
                              boost::python::make_constructor(
                                  std::function<rcc::shared_ptr<aq::IGraph>()>(std::bind(&makeGraph, *itr))));
                    bpobj.def("save",
                              boost::python::make_function(&aq::IGraph::saveGraph,
                                                           boost::python::default_call_policies(),
                                                           boost::python::arg("filename")));
                    bpobj.def("start", &aq::IGraph::startThread);
                    bpobj.def("stop", &aq::IGraph::stopThread);
                    bpobj.def("pause", &aq::IGraph::pauseThread);
                    bpobj.def("step", &aq::IGraph::process);
                    // bpobj.def("addNode", static_cast<void(aq::IGraph::*) (const
                    // rcc::shared_ptr<aq::nodes::INode>&)>(&aq::IGraph::addNode));
                    bpobj.def("addNode", addNode<aq::nodes::Node>);
                    bpobj.def("addNode", addNode<aq::nodes::IFrameGrabber>);
                    bpobj.def("listSlots", &getSlots);
                    bpobj.def("emit", &emitsignal);
                    bpobj.def("wait", &waitSignal, (boost::python::arg("name"), boost::python::arg("timeout") = 0));
                    bpobj.add_property("dirty", &aq::IGraph::getDirty);

                    boost::python::import("aquila").attr("Graph") = bpobj;
                    ctrs.erase(itr);
                    return;
                }
                ++itr;
            }
        }
    } // namespace python
} // namespace aq

max_stars_repo_name: dtmoodie/Acquilla

max_issues_repo_name: dtmoodie/Acquilla

max_forks_repo_name: dtmoodie/Acquilla


text:
#include <cstdio>
#include <iostream>
#include <boost/graph/adjacency_list.hpp>

#include "algos.h"
#include "random_graph.h"
#include "bench_mem_trace.h"

#define do_not_optimize(v) asm volatile("" : : "r,m"(v) : "memory");

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> Graph;

const unsigned vertices[] = {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000};

template <unsigned num, unsigned div>
void fill_random_graph(void) {
	char name[128];

	for (const auto v : vertices) {
		Graph g = gen_random_connected_graph<Graph>(v, (double)num/div);
		auto o = gen_random_order(g);
		const unsigned n = boost::num_vertices(g) + boost::num_edges(g);

		sprintf(name, "fill_random_graph<%u,%u> v=%u n=%u", num, div, v, n);
		start_trace(name);
		fill(g, o);
		stop_trace();
	}
}

template <unsigned num, unsigned div>
void lex_m_random_graph(void) {
	char name[128];

	for (const auto v : vertices) {
		Graph g = gen_random_connected_graph<Graph>(v, (double)num/div);
		const unsigned n = boost::num_vertices(g) * boost::num_edges(g);

		sprintf(name, "lex_m_random_graph<%u,%u> v=%u n=%u", num, div, v, n);
		start_trace(name);
		do_not_optimize(lex_m(g));
		stop_trace();
	}
}

template <unsigned num, unsigned div>
void lex_p_random_graph(void) {
	char name[128];

	for (const auto v : vertices) {
		Graph g = gen_random_connected_graph<Graph>(v, (double)num/div);
		const unsigned n = boost::num_vertices(g) + boost::num_edges(g);

		if (num != div)
			fill(g, lex_m(g));

		sprintf(name, "lex_p_random_graph<%u,%u> v=%u n=%u", num, div, v, n);
		start_trace(name);
		do_not_optimize(lex_p(g));
		stop_trace();
	}
}

int main(void) {
	fill_random_graph <1, 10>(); // edge density  10%
	fill_random_graph <1,  4>(); // edge density  25%
	fill_random_graph <1,  2>(); // edge density  50%
	fill_random_graph <2,  3>(); // edge density  66%
	fill_random_graph <3,  4>(); // edge density  75%
	fill_random_graph <1,  1>(); // edge density 100% (complete graph)

	lex_m_random_graph<1, 10>(); // edge density  10%
	lex_m_random_graph<1,  4>(); // edge density  25%
	lex_m_random_graph<1,  2>(); // edge density  50%
	lex_m_random_graph<2,  3>(); // edge density  66%
	lex_m_random_graph<3,  4>(); // edge density  75%
	lex_m_random_graph<1,  1>(); // edge density 100% (complete graph)

	lex_p_random_graph<1, 10>(); // edge density  10%
	lex_p_random_graph<1,  4>(); // edge density  25%
	lex_p_random_graph<1,  2>(); // edge density  50%
	lex_p_random_graph<2,  3>(); // edge density  66%
	lex_p_random_graph<3,  4>(); // edge density  75%
	lex_p_random_graph<1,  1>(); // edge density 100% (complete graph)

	return 0;
}

ext: cc