text:
//  Copyright (c) 2007-2012 Hartmut Kaiser
//
//  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 <hpx/hpx_fwd.hpp>
#include <hpx/exception.hpp>
#include <hpx/runtime/applier/applier.hpp>
#include <hpx/runtime/threads/thread_helpers.hpp>
#include <hpx/util/interval_timer.hpp>
#include <hpx/util/unlock_guard.hpp>

#include <boost/bind.hpp>
#include <boost/thread/locks.hpp>

namespace hpx { namespace util
{
    ///////////////////////////////////////////////////////////////////////////
    interval_timer::interval_timer()
      : microsecs_(0), id_(0)
    {}

    interval_timer::interval_timer(util::function_nonser<bool()> const& f,
            boost::int64_t microsecs, std::string const& description,
            bool pre_shutdown)
      : f_(f), on_term_(),
        microsecs_(microsecs), id_(0), description_(description),
        pre_shutdown_(pre_shutdown), is_started_(false), first_start_(true),
        is_terminated_(false), is_stopped_(false)
    {}

    interval_timer::interval_timer(util::function_nonser<bool()> const& f,
            util::function_nonser<void()> const& on_term,
            boost::int64_t microsecs, std::string const& description,
            bool pre_shutdown)
      : f_(f), on_term_(on_term),
        microsecs_(microsecs), id_(0), description_(description),
        pre_shutdown_(pre_shutdown), is_started_(false), first_start_(true),
        is_terminated_(false), is_stopped_(false)
    {}

    bool interval_timer::start(bool evaluate_)
    {
        boost::unique_lock<mutex_type> l(mtx_);
        if (is_terminated_)
            return false;

        if (!is_started_) {
            if (first_start_) {
                first_start_ = false;

                util::unlock_guard<boost::unique_lock<mutex_type> > ul(l);
                if (pre_shutdown_)
                    register_pre_shutdown_function(boost::bind(&interval_timer::terminate, this));
                else
                    register_shutdown_function(boost::bind(&interval_timer::terminate, this));
            }

            is_stopped_ = false;

            if (evaluate_) {
                l.unlock();
                evaluate(threads::wait_signaled);
            }
            else {
                schedule_thread(l);
            }

            return true;
        }
        return false;
    }

    bool interval_timer::restart(bool evaluate_)
    {
        if (!is_started_)
            return start(evaluate_);

        boost::unique_lock<mutex_type> l(mtx_);

        if (is_terminated_)
            return false;

        // interrupt timer thread, if needed
        stop_locked();

        // reschedule evaluation thread
        if (evaluate_) {
            l.unlock();
            evaluate(threads::wait_signaled);
        }
        else {
            schedule_thread(l);
        }
        return true;
    }

    bool interval_timer::stop()
    {
        boost::lock_guard<mutex_type> l(mtx_);
        is_stopped_ = true;
        return stop_locked();
    }

    bool interval_timer::stop_locked()
    {
        if (is_started_) {
            is_started_ = false;

            if (id_) {
                error_code ec(lightweight);       // avoid throwing on error
                threads::set_thread_state(id_, threads::pending,
                    threads::wait_abort, threads::thread_priority_boost, ec);
                id_ = 0;
            }
            return true;
        }

        HPX_ASSERT(id_ == 0);
        return false;
    }

    void interval_timer::terminate()
    {
        boost::unique_lock<mutex_type> l(mtx_);
        if (!is_terminated_) {
            is_terminated_ = true;
            stop_locked();

            if (on_term_) {
                l.unlock();
                on_term_();
            }
        }
    }

    interval_timer::~interval_timer()
    {
        try {
            terminate();
        }
        catch(...) {
            ;   // there is nothing we can do here
        }
    }

    threads::thread_state_enum interval_timer::evaluate(
        threads::thread_state_ex_enum statex)
    {
        try {
            boost::unique_lock<mutex_type> l(mtx_);

            if (is_stopped_ || is_terminated_ ||
                statex == threads::wait_abort || 0 == microsecs_)
            {
                return threads::terminated;        // object has been finalized, exit
            }

            if (id_ != 0 && id_ != threads::get_self_id())
                return threads::terminated;        // obsolete timer thread

            id_ = 0;
            is_started_ = false;

            bool result = false;

            {
                util::unlock_guard<boost::unique_lock<mutex_type> > ul(l);
                result = f_();            // invoke the supplied function
            }

            // some other thread might already have started the timer
            if (0 == id_ && result) {
                HPX_ASSERT(!is_started_);
                schedule_thread(l);        // wait and repeat
            }
        }
        catch (hpx::exception const& e){
            // the lock above might throw yield_aborted
            if (e.get_error() != yield_aborted)
                throw;
        }
        return threads::terminated;   // do not re-schedule this thread
    }

    // schedule a high priority task after a given time interval
    void interval_timer::schedule_thread(boost::unique_lock<mutex_type> & l)
    {
        HPX_ASSERT(l.owns_lock());

        using namespace hpx::threads;

        error_code ec;

        // create a new suspended thread
        threads::thread_id_type id;
        {
            // FIXME: registering threads might lead to thread suspension since
            // the allocators use hpx::lcos::local::spinlock. Unlocking the
            // lock here would be the right thing but leads to crashes and hangs
            // at shutdown.
            //util::unlock_guard<boost::unique_lock<mutex_type> > ul(l);
            id = hpx::applier::register_thread_plain(
                boost::bind(&interval_timer::evaluate, this, _1),
                description_.c_str(), threads::suspended, true,
                threads::thread_priority_boost, std::size_t(-1),
                threads::thread_stacksize_default, ec);
        }

        if (ec) {
            is_terminated_ = true;
            is_started_ = false;
            return;
        }

        // schedule this thread to be run after the given amount of seconds
        threads::set_thread_state(id,
            boost::chrono::microseconds(microsecs_),
            threads::pending, threads::wait_signaled,
            threads::thread_priority_boost, ec);

        if (ec) {
            is_terminated_ = true;
            is_started_ = false;

            // abort the newly created thread
            threads::set_thread_state(id, threads::pending, threads::wait_abort,
                threads::thread_priority_boost, ec);

            return;
        }

        id_ = id;
        is_started_ = true;
    }
}}

max_stars_repo_name: kempj/hpx

max_issues_repo_name: kempj/hpx

max_forks_repo_name: kempj/hpx


text:
#include "precompiled.h"

#ifndef AUTOMATIC_PRECOMPILATION
#include <iostream>
#include <boost/exception/all.hpp>
#include <boost/program_options.hpp>
#endif

#include "DebugSink.h"
#include "configuration_parser.h"
#include "utility.h"

#include "grid_tests.h"
#include "global_config.h"

using namespace fipster;

void testmain();
vector<string> mainWithOptions(int, char*[]);

#define MAIN_CATCH_BLOCK 0

int main(int ac, char* av[])
{
#if MAIN_CATCH_BLOCK
try{
#endif
	DebugSink::activate_std();
	srand( (unsigned)time( NULL ));
	testmain();

	parser p(mainWithOptions(ac,av));
	DebugSink::activate_std(true,global_config::get().output_path);
	p.create_graph_and_run();
#if MAIN_CATCH_BLOCK
}
catch (...)
{
	cerr << boost::current_exception_diagnostic_information();
	// throw;
}
#endif
	return 0;
}

// old?
#if 0
#include "grid.h"
#include "fdstencils.h"
#include "fdweights.h"
#include "GridDirGenerators.h"
#include "payoff_node_factory.h"
#include "financial_derivative.h"
#include "Cryer.h"

class testC{};

void test1(string s,Task* t){

	cout<<s<<": asdasdasd!!!!!!!!!!!!!!!!!!!!!!!!!"<<endl;
}

void start(Call* c, Task* t,financial_derivative* ff){
	((Field*)c)->get_result(5,t,0);
	c->get_result(10,t,1);
	c->get_result(10,t,0);
	c->get_result(-10,t,2);
	ff->get_result(0,t,2);
	t->ready();
}

int main2()
{

	DebugSink::activate();

	propery_collection<boundary_conditions> bcs("boundaryConditions.xml");
	//propery_collection<boundary_conditions>::propCollectionBase* b = &bcs;

	int n=10,m=3;

	Grid g(2 ,	new HomogenousCoords(6,0.0,1.0),new HomogenousCoords(11,0.0,1.0),
					new ExpCoords(6,-0.2,0.1,1),new ExpCoords(5,-0.2,0.1,1));

	g.test_grid_interateboundary_canonical_order<1>();

	fdweights* t1 = g.get_fdweights(StencilOneDiagonal,new BlackScholesIsometric(0.05,0.2,0.1),6,0);

	g.checkiterdirstartpoints<2>(t1->stencil);
	/*fdweights* t2 = g.get_fdweights(StencilNoDiagonals,t1->pde,6);
	fdweights* t3 = g.get_fdweights(StencilOneDiagonal,t1->pde,6);
	fdweights* t4 = g.get_fdweights(StencilTwoDiagonals,t1->pde,6);*/

	Call c( -.15 , 1 );
	c.setGrid(&g);
	Task t(boost::bind(test1,"cool",_1),3);
	financial_derivative ff(&c,t1,bcs["testBC"],1000,10);
	financial_derivative ff2(&ff,t1,bcs["testBC"],1000,10,ImplicitEuler);
	ff2.setName("fin_der2");
	ff.setName("fin_der1");
	Task::dispatch_wrapped(boost::bind(start,&c,&t,&ff2));

	Task::finish_computations();

	//c.perform_computation(234.0);
	//financial_derivative f(&c,t1);
	cout<<"END END END END END END END END !"<<endl;
	cout<<Task::n_unfinished_max<<endl;

	return 0;
}

#endif

ext: cpp

max_stars_repo_name: johannesgerer/fipster

max_issues_repo_name: johannesgerer/fipster

max_forks_repo_name: johannesgerer/fipster


text:
//
// Balau core C++ library
//
// Copyright (C) 2008 Bora Software (contact@borasoftware.com)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

///
/// @file ToStringS.hpp
///
/// Pre-defined universal to-string functions for std::allocator based strings (i.e. std::string).
///

#ifndef COM_BORA_SOFTWARE__BALAU_APPLICATION__TO_STRING_S
#define COM_BORA_SOFTWARE__BALAU_APPLICATION__TO_STRING_S

#include <Balau/Type/StdTypes.hpp>
#include <Balau/Type/Impl/ToStringImpl.hpp>

#include <boost/lexical_cast.hpp>
#include <boost/locale.hpp>

#include <complex>
#include <forward_list>
#include <list>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>

template <typename P1, typename P2, typename ... P>
std::string toString(const P1 & p1, const P2 & p2, const P & ... p);

template <typename P1, typename P2, typename ... P>
std::u16string toString16(const P1 & p1, const P2 & p2, const P & ... p);

template <typename P1, typename P2, typename ... P>
std::u32string toString32(const P1 & p1, const P2 & p2, const P & ... p);

///////////////////// Universal UTF-8 to-string function //////////////////////

///
/// Returns the supplied value as is.
///
inline std::string toString(const std::string & value) {
	return value;
}

///
/// Creates a string from the string view.
///
inline std::string toString(const std::string_view & value) {
	return std::string(value);
}

#ifndef BALAU_USE_BOOST_STRING_VIEW

///
/// Creates a string from the Boost string view.
///
inline std::string toString(const boost::string_view & value) {
	return value.to_string();
}

#endif

///
/// Convert the supplied UTF-16 string to a UTF-8 string.
///
inline std::string toString(const std::u16string & value) {
	return boost::locale::conv::utf_to_utf<char, char16_t>(value);
}

///
/// Creates a UTF-8 string from the UTF-16 string view.
///
inline std::string toString(const std::u16string_view & value) {
	return boost::locale::conv::utf_to_utf<char, char16_t>(std::u16string(value));
}

///
/// Convert the supplied UTF-32 string to a UTF-8 string.
///
inline std::string toString(const std::u32string & value) {
	return boost::locale::conv::utf_to_utf<char, char32_t>(value);
}

///
/// Creates a UTF-8 string from the UTF-32 string view.
///
inline std::string toString(const std::u32string_view & value) {
	return boost::locale::conv::utf_to_utf<char, char32_t>(std::u32string(value));
}

///
/// Returns the supplied value as a UTF-8 string.
///
inline std::string toString(char value) {
	std::string str;
	str += value;
	return str;
}

///
/// Convert the supplied code point to a UTF-8 string.
///
inline std::string toString(char16_t value) {
	std::u16string str;
	str += value;
	return toString(str);
}

///
/// Convert the supplied code point to a UTF-8 string.
///
inline std::string toString(char32_t value) {
	std::u32string str;
	str += value;
	return toString(str);
}

///
/// Convert the supplied signed char to a UTF-8 string.
///
inline std::string toString(signed char value) {
	return Balau::Impl::toString<std::allocator<char>>("%d", (int) value);
}

///
/// Convert the supplied short to a UTF-8 string.
///
inline std::string toString(short value) {
	return Balau::Impl::toString<std::allocator<char>>("%d", (int) value);
}

///
/// Convert the supplied int to a UTF-8 string.
///
inline std::string toString(int value) {
	return Balau::Impl::toString<std::allocator<char>>("%d", value);
}

///
/// Convert the supplied long to a UTF-8 string.
///
inline std::string toString(long value) {
	return Balau::Impl::toString<std::allocator<char>>("%ld", value);
}

///
/// Convert the supplied long long to a UTF-8 string.
///
inline std::string toString(long long value) {
	return Balau::Impl::toString<std::allocator<char>>("%lld", value);
}

///
/// Convert the supplied signed char to a UTF-8 string.
///
inline std::string toString(unsigned char value) {
	return Balau::Impl::toString<std::allocator<char>>("%u", (unsigned int) value);
}

///
/// Convert the supplied short to a UTF-8 string.
///
inline std::string toString(unsigned short value) {
	return Balau::Impl::toString<std::allocator<char>>("%u", (unsigned int) value);
}

///
/// Convert the supplied unsigned int to a UTF-8 string.
///
inline std::string toString(unsigned int value) {
	return Balau::Impl::toString<std::allocator<char>>("%u", value);
}

///
/// Convert the supplied unsigned long to a UTF-8 string.
///
inline std::string toString(unsigned long value) {
	return Balau::Impl::toString<std::allocator<char>>("%lu", value);
}

///
/// Convert the supplied unsigned long long to a UTF-8 string.
///
inline std::string toString(unsigned long long value) {
	return Balau::Impl::toString<std::allocator<char>>("%llu", value);
}

///
/// Convert the supplied float to a UTF-8 string.
///
inline std::string toString(float value) {
	return boost::lexical_cast<std::string>(value);
}

///
/// Convert the supplied double to a UTF-8 string.
///
inline std::string toString(double value) {
	return boost::lexical_cast<std::string>(value);
}

///
/// Convert the supplied long double to a UTF-8 string.
///
inline std::string toString(long double value) {
	return boost::lexical_cast<std::string>(value);
}

///
/// Convert the supplied complex to a UTF-8 string.
///
template <typename T> inline std::string toString(const std::complex<T> & value) {
	return toString(value.real(), " + j", value.imag());
}

///
/// Convert the supplied boolean to a UTF-8 string.
///
inline std::string toString(bool value) {
	return value ? "true" : "false";
}

///
/// Returns the supplied const char * as a UTF-8 string.
///
inline std::string toString(const char * value) {
	return std::string(value);
}

std::u16string toString16(const char16_t * value);
std::u32string toString32(const char32_t * value);

///
/// Returns the supplied const char16_t * as a UTF-8 string.
///
inline std::string toString(const char16_t * value) {
	return toString(toString16(value));
}

///
/// Returns the supplied const char32_t * as a UTF-8 string.
///
inline std::string toString(const char32_t * value) {
	return toString(toString32(value));
}

///
/// Convert the supplied pointer to a UTF-8 string.
///
/// The pointer is converted to an unsigned long long integer value and toString
/// is called on the value.
///
inline std::string toString(const void * ptr) {
	return toString((size_t) ptr);
}

///
/// Convert the supplied nullptr value to a UTF-8 string.
///
/// The returned value is zero in order to match the values
/// returned for other pointer to-string functions.
///
inline std::string toString(std::nullptr_t) {
	return "0";
}

///
/// Return the name of the type index.
///
inline std::string toString(std::type_index value) {
	return value.name();
}

///
/// A toString function that creates the UTF-8 string by calling the function.
///
inline std::string toString(const std::function<std::string ()> & f) {
	return f();
}

///
/// Convert the supplied std::pair value to a UTF-8 string.
///
template <typename F, typename S>
inline std::string toString(const std::pair<F, S> & p) {
	return std::string("{ ") + toString(p.first) + ", " + toString(p.second) + " }";
}

///
/// Helper for container to UTF-8 string functions.
///
/// This helper function can be used for custom container types if required.
///
template <typename ... T, template <typename ...> class C>
inline std::string toStringHelper(const C<T ...> & c)  {
	std::string builder = "{";
	std::string prefix = " ";
	bool empty = true;

	for (const auto & e : c) {
		builder += prefix + toString(e);
		prefix = ", ";
		empty = false;
	}

	if (!empty) {
		builder += " ";
	}

	builder += "}";

	return builder;
}

///
/// Define a UTF-8 to-string function for a container that has a single template parameter.
///
#define BALAU_CONTAINER1_TO_STRING(CONTAINER_TYPE)             \
	template <typename T>                                      \
	inline std::string toString(const CONTAINER_TYPE<T> & c) { \
		return toStringHelper(c);                              \
	}

///
/// Define a UTF-8 to-string function for a container that has two template parameters.
///
#define BALAU_CONTAINER2_TO_STRING(CONTAINER_TYPE)                \
	template <typename T, typename U>                             \
	inline std::string toString(const CONTAINER_TYPE<T, U> & c) { \
		return toStringHelper(c);                                 \
	}

///
/// Define a UTF-8 to-string function for a container that has three template parameters.
///
#define BALAU_CONTAINER3_TO_STRING(CONTAINER_TYPE)                   \
	template <typename T, typename U, typename V>                    \
	inline std::string toString(const CONTAINER_TYPE<T, U, V> & c) { \
		return toStringHelper(c);                                    \
	}

///
/// Define a UTF-8 to-string function for a container that has four template parameters.
///
#define BALAU_CONTAINER4_TO_STRING(CONTAINER_TYPE)                      \
	template <typename T, typename U, typename V, typename W>           \
	inline std::string toString(const CONTAINER_TYPE<T, U, V, W> & c) { \
		return toStringHelper(c);                                       \
	}

///
/// Define a UTF-8 to-string function for a container that has five template parameters.
///
#define BALAU_CONTAINER5_TO_STRING(CONTAINER_TYPE)                         \
	template <typename T, typename U, typename V, typename W, typename X>  \
	inline std::string toString(const CONTAINER_TYPE<T, U, V, W, X> & c) { \
		return toStringHelper(c);                                          \
	}

BALAU_CONTAINER2_TO_STRING(std::deque)
BALAU_CONTAINER2_TO_STRING(std::forward_list)
BALAU_CONTAINER2_TO_STRING(std::list)
BALAU_CONTAINER2_TO_STRING(std::map)
BALAU_CONTAINER3_TO_STRING(std::multiset)
BALAU_CONTAINER4_TO_STRING(std::multimap)
BALAU_CONTAINER3_TO_STRING(std::priority_queue)
BALAU_CONTAINER2_TO_STRING(std::queue)
BALAU_CONTAINER2_TO_STRING(std::set)
BALAU_CONTAINER2_TO_STRING(std::stack)
BALAU_CONTAINER5_TO_STRING(std::unordered_map)
BALAU_CONTAINER5_TO_STRING(std::unordered_multimap)
BALAU_CONTAINER4_TO_STRING(std::unordered_multiset)
BALAU_CONTAINER3_TO_STRING(std::unordered_set)
BALAU_CONTAINER2_TO_STRING(std::vector)

///
/// Print the supplied array as a UTF-8 string.
///
/// @return the supplied array as a UTF-8 string
///
template <typename T, size_t N> inline std::string toString(const std::array<T, N> & c) {
	return toStringHelper(c);
}

///
/// Concatenates the to-string values of the input arguments.
///
/// Calls toString on each input argument and concatenates them together to
/// form a single UTF-8 string.
///
template <typename P1, typename P2, typename ... P>
inline std::string toString(const P1 & p1, const P2 & p2, const P & ... p) {
	return toString(p1) + toString(p2) + (std::string() + ... + toString(p));
}

///////////////////// Universal UTF-16 to-string function /////////////////////

///
/// Convert the supplied UTF-8 string to a UTF-16 string.
///
inline std::u16string toString16(const std::string & value) {
	return boost::locale::conv::utf_to_utf<char16_t, char>(value);
}

///
/// Convert the supplied UTF-8 string view to a UTF-16 string.
///
inline std::u16string toString16(const std::string_view & value) {
	return toString16(std::string(value));
}

#ifndef BALAU_USE_BOOST_STRING_VIEW

///
/// Convert the supplied UTF-8 Boost string view to a UTF-16 string.
///
inline std::u16string toString16(const boost::string_view & value) {
	return toString16(value.to_string());
}

#endif

///
/// Returns the supplied value as is.
///
inline std::u16string toString16(const std::u16string & value) {
	return value;
}

///
/// Creates a UTF-16 string from the UTF-16 string view.
///
inline std::u16string toString16(const std::u16string_view & value) {
	return std::u16string(value);
}

///
/// Convert the supplied UTF-32 string to a UTF-16 string.
///
inline std::u16string toString16(const std::u32string & value) {
	return boost::locale::conv::utf_to_utf<char16_t, char32_t>(value);
}

///
/// Convert the supplied ascii character to a UTF-16 string.
///
inline std::u16string toString16(char value) {
	std::string str;
	str += value;
	return toString16(str);
}

///
/// Convert the supplied UTF-16 character to a UTF-16 string.
///
inline std::u16string toString16(char16_t & value) {
	std::u16string str;
	str += value;
	return str;
}

///
/// Convert the supplied code point to a UTF-16 string.
///
inline std::u16string toString16(char32_t & value) {
	std::u32string str;
	str += value;
	return toString16(str);
}

///
/// Convert the supplied signed char to a UTF-16 string.
///
inline std::u16string toString16(signed char value) {
	return toString16(toString(value));
}

///
/// Convert the supplied short to a UTF-16 string.
///
inline std::u16string toString16(short value) {
	return toString16(toString(value));
}

///
/// Convert the supplied int to a UTF-16 string.
///
inline std::u16string toString16(int value) {
	return toString16(toString(value));
}

///
/// Convert the supplied long to a UTF-16 string.
///
inline std::u16string toString16(long value) {
	return toString16(toString(value));
}

///
/// Convert the supplied long long to a UTF-16 string.
///
inline std::u16string toString16(long long value) {
	return toString16(toString(value));
}

///
/// Convert the supplied unsigned char to a UTF-16 string.
///
inline std::u16string toString16(unsigned char value) {
	return toString16(toString(value));
}

///
/// Convert the supplied unsigned short to a UTF-16 string.
///
inline std::u16string toString16(unsigned short value) {
	return toString16(toString(value));
}

///
/// Convert the supplied unsigned int to a UTF-16 string.
///
inline std::u16string toString16(unsigned int value) {
	return toString16(toString(value));
}

///
/// Convert the supplied unsigned long to a UTF-16 string.
///
inline std::u16string toString16(unsigned long value) {
	return toString16(toString(value));
}

///
/// Convert the supplied unsigned long long to a UTF-16 string.
///
inline std::u16string toString16(unsigned long long value) {
	return toString16(toString(value));
}

///
/// Convert the supplied float to a UTF-16 string.
///
inline std::u16string toString16(float value) {
	return toString16(toString(value));
}

///
/// Convert the supplied double to a UTF-16 string.
///
inline std::u16string toString16(double value) {
	return toString16(toString(value));
}

///
/// Convert the supplied long double to a UTF-16 string.
///
inline std::u16string toString16(long double value) {
	return toString16(toString(value));
}

///
/// Convert the supplied complex to a UTF-16 string.
///
template <typename T> inline std::u16string toString16(const std::complex<T> & value) {
	return toString16(value.real(), " + j", value.imag());
}

///
/// Convert the supplied boolean to a UTF-16 string.
///
inline std::u16string toString16(bool value) {
	return value ? u"true" : u"false";
}

///
/// Returns the supplied const char * as a UTF-16 string.
///
inline std::u16string toString16(const char * value) {
	return toString16(toString((value)));
}

///
/// Returns the supplied const char16_t * as a UTF-16 string.
///
inline std::u16string toString16(const char16_t * value) {
	return std::u16string(value);
}

///
/// Returns the supplied const char32_t * as a UTF-16 string.
///
inline std::u16string toString16(const char32_t * value) {
	return toString16(toString32(value));
}

///
/// Convert the supplied pointer to a UTF-16 string.
///
/// The pointer is converted to an unsigned long long integer value and toString16
/// is called on the value.
///
inline std::u16string toString16(const void * ptr) {
	return toString16((size_t) ptr);
}

///
/// Convert the supplied nullptr value to a UTF-16 string.
///
/// The returned value is zero in order to match the values
/// returned for other pointer to-string functions.
///
inline std::u16string toString16(std::nullptr_t) {
	return u"0";
}

///
/// Return the name of the type index.
///
inline std::u16string toString16(std::type_index value) {
	return toString16(value.name());
}

///
/// A toString16 function that creates the UTF-16 string by calling the function.
///
inline std::u16string toString16(const std::function<std::u16string ()> & f) {
	return f();
}

///
/// Convert the supplied std::pair value to a UTF-16 string.
///
template <typename F, typename S>
inline std::u16string toString16(const std::pair<F, S> & p) {
	return std::u16string(u"{ ") + toString16(p.first) + u", " + toString16(p.second) + u" }";
}

///
/// Helper for container to UTF-16 string functions.
///
/// This helper function can be used for custom container types if required.
///
template <typename ... T, template <typename ...> class C>
inline std::u16string toString16Helper(const C<T ...> & c)  {
	std::u16string builder = u"{";
	std::u16string prefix = u" ";
	bool empty = true;

	for (const auto & e : c) {
		builder += prefix + toString16(e);
		prefix = u", ";
		empty = false;
	}

	if (!empty) {
		builder += u" ";
	}

	builder += u"}";

	return builder;
}

///
/// Define a UTF-16 to-string function for a container that has a single template parameter.
///
#define BALAU_CONTAINER1_TO_STRING16(CONTAINER_TYPE)                \
	template <typename T>                                           \
	inline std::u16string toString16(const CONTAINER_TYPE<T> & c) { \
		return toString16Helper(c);                                 \
	}

///
/// Define a UTF-16 to-string function for a container that has two template parameters.
///
#define BALAU_CONTAINER2_TO_STRING16(CONTAINER_TYPE)                   \
	template <typename T, typename U>                                  \
	inline std::u16string toString16(const CONTAINER_TYPE<T, U> & c) { \
		return toString16Helper(c);                                    \
	}

///
/// Define a UTF-16 to-string function for a container that has three template parameters.
///
#define BALAU_CONTAINER3_TO_STRING16(CONTAINER_TYPE)                      \
	template <typename T, typename U, typename V>                         \
	inline std::u16string toString16(const CONTAINER_TYPE<T, U, V> & c) { \
		return toString16Helper(c);                                       \
	}

///
/// Define a UTF-16 to-string function for a container that has four template parameters.
///
#define BALAU_CONTAINER4_TO_STRING16(CONTAINER_TYPE)                         \
	template <typename T, typename U, typename V, typename W>                \
	inline std::u16string toString16(const CONTAINER_TYPE<T, U, V, W> & c) { \
		return toString16Helper(c);                                          \
	}

///
/// Define a UTF-16 to-string function for a container that has five template parameters.
///
#define BALAU_CONTAINER5_TO_STRING16(CONTAINER_TYPE)                            \
	template <typename T, typename U, typename V, typename W, typename X>       \
	inline std::u16string toString16(const CONTAINER_TYPE<T, U, V, W, X> & c) { \
		return toString16Helper(c);                                             \
	}

BALAU_CONTAINER2_TO_STRING16(std::deque)
BALAU_CONTAINER2_TO_STRING16(std::forward_list)
BALAU_CONTAINER2_TO_STRING16(std::list)
BALAU_CONTAINER2_TO_STRING16(std::map)
BALAU_CONTAINER3_TO_STRING16(std::multiset)
BALAU_CONTAINER4_TO_STRING16(std::multimap)
BALAU_CONTAINER3_TO_STRING16(std::priority_queue)
BALAU_CONTAINER2_TO_STRING16(std::queue)
BALAU_CONTAINER2_TO_STRING16(std::set)
BALAU_CONTAINER2_TO_STRING16(std::stack)
BALAU_CONTAINER5_TO_STRING16(std::unordered_map)
BALAU_CONTAINER5_TO_STRING16(std::unordered_multimap)
BALAU_CONTAINER4_TO_STRING16(std::unordered_multiset)
BALAU_CONTAINER3_TO_STRING16(std::unordered_set)
BALAU_CONTAINER2_TO_STRING16(std::vector)

///
/// Concatenates the to-string values of the input arguments.
///
/// Calls toString16 on each input argument and concatenates them together to
/// form a single UTF-16 string.
///
template <typename P1, typename P2, typename ... P>
inline std::u16string toString16(const P1 & p1, const P2 & p2, const P & ... p) {
	return toString16(p1) + toString16(p2) + (std::u16string() + ... + toString16(p));
}

///////////////////// Universal UTF-32 to-string function /////////////////////

///
/// Convert the supplied UTF-8 string to a UTF-32 string.
///
inline std::u32string toString32(const std::string & value) {
	return boost::locale::conv::utf_to_utf<char32_t, char>(value);
}

///
/// Convert the supplied UTF-8 string view to a UTF-32 string.
///
inline std::u32string toString32(const std::string_view & value) {
	return toString32(std::string(value));
}

#ifndef BALAU_USE_BOOST_STRING_VIEW

///
/// Convert the supplied UTF-8 Boost string view to a UTF-32 string.
///
inline std::u32string toString32(const boost::string_view & value) {
	return toString32(value.to_string());
}

#endif

///
/// Convert the supplied UTF-16 string to a UTF-8 string.
///
inline std::u32string toString32(const std::u16string & value) {
	return boost::locale::conv::utf_to_utf<char32_t, char16_t>(value);
}

///
/// Returns the supplied value as is.
///
inline std::u32string toString32(const std::u32string & value) {
	return value;
}

///
/// Creates a UTF-32 string from the UTF-32 string view.
///
inline std::u32string toString32(const std::u32string_view & value) {
	return std::u32string(value);
}

///
/// Returns the supplied ascii character as a UTF-32 string.
///
inline std::u32string toString32(char value) {
	std::string str;
	str += value;
	return toString32(str);
}

///
/// Convert the supplied UTF-16 character to a UTF-32 string.
///
inline std::u32string toString32(char16_t & value) {
	std::u16string str;
	str += value;
	return toString32(str);
}

///
/// Convert the supplied code point to a UTF-32 string.
///
inline std::u32string toString32(char32_t & value) {
	std::u32string str;
	str += value;
	return str;
}

///
/// Convert the supplied signed char to a UTF-32 string.
///
inline std::u32string toString32(signed char value) {
	return toString32(toString(value));
}

///
/// Convert the supplied short to a UTF-32 string.
///
inline std::u32string toString32(short value) {
	return toString32(toString(value));
}

///
/// Convert the supplied int to a UTF-32 string.
///
inline std::u32string toString32(int value) {
	return toString32(toString(value));
}

///
/// Convert the supplied long to a UTF-32 string.
///
inline std::u32string toString32(long value) {
	return toString32(toString(value));
}

///
/// Convert the supplied long long to a UTF-32 string.
///
inline std::u32string toString32(long long value) {
	return toString32(toString(value));
}

///
/// Convert the supplied unsigned char to a UTF-32 string.
///
inline std::u32string toString32(unsigned char value) {
	return toString32(toString(value));
}

///
/// Convert the supplied unsigned short to a UTF-32 string.
///
inline std::u32string toString32(unsigned short value) {
	return toString32(toString(value));
}

///
/// Convert the supplied unsigned int to a UTF-32 string.
///
inline std::u32string toString32(unsigned int value) {
	return toString32(toString(value));
}

///
/// Convert the supplied unsigned long to a UTF-32 string.
///
inline std::u32string toString32(unsigned long value) {
	return toString32(toString(value));
}

///
/// Convert the supplied unsigned long long to a UTF-32 string.
///
inline std::u32string toString32(unsigned long long value) {
	return toString32(toString(value));
}

///
/// Convert the supplied float to a UTF-32 string.
///
inline std::u32string toString32(float value) {
	return toString32(toString(value));
}

///
/// Convert the supplied double to a UTF-32 string.
///
inline std::u32string toString32(double value) {
	return toString32(toString(value));
}

///
/// Convert the supplied long double to a UTF-32 string.
///
inline std::u32string toString32(long double value) {
	return toString32(toString(value));
}

///
/// Convert the supplied complex to a UTF-32 string.
///
template <typename T> inline std::u32string toString32(const std::complex<T> & value) {
	return toString32(value.real(), " + j", value.imag());
}

///
/// Convert the supplied boolean to a UTF-32 string.
///
inline std::u32string toString32(bool value) {
	return value ? U"true" : U"false";
}

///
/// Returns the supplied const char * as a UTF-32 string.
///
inline std::u32string toString32(const char * value) {
	return toString32(toString((value)));
}

///
/// Returns the supplied const char16_t * as a UTF-32 string.
///
inline std::u32string toString32(const char16_t * value) {
	return toString32(toString16((value)));
}

///
/// Returns the supplied const char32_t * as a UTF-32 string.
///
inline std::u32string toString32(const char32_t * value) {
	return std::u32string(value);
}

///
/// Convert the supplied pointer to a UTF-32 string.
///
/// The pointer is converted to an unsigned long long integer value and toString32
/// is called on the value.
///
inline std::u32string toString32(const void * ptr) {
	return toString32((size_t) ptr);
}

///
/// Convert the supplied nullptr value to a UTF-32 string.
///
/// The returned value is zero in order to match the values
/// returned for other pointer to-string functions.
///
inline std::u32string toString32(std::nullptr_t) {
	return U"0";
}

///
/// Return the name of the type index.
///
inline std::u32string toString32(std::type_index value) {
	return toString32(value.name());
}

///
/// A toString32 function that creates the UTF-32 string by calling the function.
///
inline std::u32string toString32(const std::function<std::u32string ()> & f) {
	return f();
}

///
/// Convert the supplied std::pair value to a UTF-32 string.
///
template <typename F, typename S>
inline std::u32string toString32(const std::pair<F, S> & p) {
	return std::u32string(U"{ ") + toString32(p.first) + U", " + toString32(p.second) + U" }";
}

///
/// Helper for container to UTF-8 string functions.
///
/// This helper function can be used for custom container types if required.
///
template <typename ... T, template <typename ...> class C>
inline std::u32string toString32Helper(const C<T ...> & c)  {
	std::u32string builder = U"{";
	std::u32string prefix = U" ";
	bool empty = true;

	for (const auto & e : c) {
		builder += prefix + toString32(e);
		prefix = U", ";
		empty = false;
	}

	if (!empty) {
		builder += U" ";
	}

	builder += U"}";

	return builder;
}

///
/// Define a UTF-32 to-string function for a container that has a single template parameter.
///
#define BALAU_CONTAINER1_TO_STRING32(CONTAINER_TYPE)                \
	template <typename T>                                           \
	inline std::u32string toString32(const CONTAINER_TYPE<T> & c) { \
		return toString32Helper(c);                                 \
	}

///
/// Define a UTF-32 to-string function for a container that has two template parameters.
///
#define BALAU_CONTAINER2_TO_STRING32(CONTAINER_TYPE)                   \
	template <typename T, typename U>                                  \
	inline std::u32string toString32(const CONTAINER_TYPE<T, U> & c) { \
		return toString32Helper(c);                                    \
	}

///
/// Define a UTF-32 to-string function for a container that has three template parameters.
///
#define BALAU_CONTAINER3_TO_STRING32(CONTAINER_TYPE)                      \
	template <typename T, typename U, typename V>                         \
	inline std::u32string toString32(const CONTAINER_TYPE<T, U, V> & c) { \
		return toString32Helper(c);                                       \
	}

///
/// Define a UTF-32 to-string function for a container that has four template parameters.
///
#define BALAU_CONTAINER4_TO_STRING32(CONTAINER_TYPE)                         \
	template <typename T, typename U, typename V, typename W>                \
	inline std::u32string toString32(const CONTAINER_TYPE<T, U, V, W> & c) { \
		return toString32Helper(c);                                          \
	}

///
/// Define a UTF-32 to-string function for a container that has five template parameters.
///
#define BALAU_CONTAINER5_TO_STRING32(CONTAINER_TYPE)                            \
	template <typename T, typename U, typename V, typename W, typename X>       \
	inline std::u32string toString32(const CONTAINER_TYPE<T, U, V, W, X> & c) { \
		return toString32Helper(c);                                             \
	}

BALAU_CONTAINER2_TO_STRING32(std::deque)
BALAU_CONTAINER2_TO_STRING32(std::forward_list)
BALAU_CONTAINER2_TO_STRING32(std::list)
BALAU_CONTAINER2_TO_STRING32(std::map)
BALAU_CONTAINER3_TO_STRING32(std::multiset)
BALAU_CONTAINER4_TO_STRING32(std::multimap)
BALAU_CONTAINER3_TO_STRING32(std::priority_queue)
BALAU_CONTAINER2_TO_STRING32(std::queue)
BALAU_CONTAINER2_TO_STRING32(std::set)
BALAU_CONTAINER2_TO_STRING32(std::stack)
BALAU_CONTAINER5_TO_STRING32(std::unordered_map)
BALAU_CONTAINER5_TO_STRING32(std::unordered_multimap)
BALAU_CONTAINER4_TO_STRING32(std::unordered_multiset)
BALAU_CONTAINER3_TO_STRING32(std::unordered_set)
BALAU_CONTAINER2_TO_STRING32(std::vector)

///
/// Concatenates the to-string values of the input arguments.
///
/// Calls toString32 on each input argument and concatenates them together to
/// form a single UTF-32 string.
///
template <typename P1, typename P2, typename ... P>
inline std::u32string toString32(const P1 & p1, const P2 & p2, const P & ... p) {
	return toString32(p1) + toString32(p2) + (std::u32string() + ... + toString32(p));
}

/////////////// Universal to-string function - templated version //////////////

///
/// UTF-8 specialisation of ToString<CharT, AllocatorT> with std::allocator.
///
/// Convert the supplied object to a std::string by calling toString.
///
template <> struct ToString<char, std::allocator<char>> {
	template <typename T> std::string operator () (const T & object) const {
		return toString(object);
	}
};

///
/// UTF-16 specialisation of ToString<CharT, AllocatorT> with std::allocator.
///
/// Convert the supplied object to a std::u16string by calling toString16.
///
template <> struct ToString<char16_t, std::allocator<char16_t>> {
	template <typename T> std::u16string operator () (const T & object) const {
		return toString16(object);
	}
};

///
/// UTF-32 specialisation of ToString<CharT, AllocatorT> with std::allocator.
///
/// Convert the supplied object to a std::u32string by calling toString32.
///
template <> struct ToString<char32_t, std::allocator<char32_t>> {
	template <typename T> std::u32string operator () (const T & object) const {
		return toString32(object);
	}
};

#endif // COM_BORA_SOFTWARE__BALAU_APPLICATION__TO_STRING_S

ext: hpp

max_stars_repo_name: borasoftware/balau

max_issues_repo_name: borasoftware/balau

max_forks_repo_name: borasoftware/balau


text:
#ifndef CLIENT_H
#define CLIENT_H

#include <boost/asio.hpp>

class Client
{
public:
    Client(boost::asio::io_service& t_io_service, const std::string t_host, const std::size_t t_port, const boost::asio::ip::tcp& t_protocol_type = boost::asio::ip::tcp::v4());

    void send(const std::string& t_file_name);

private:
    void send_file_content(std::string_view t_data_to_send);
    void send_file_size(const std::size_t t_file_size);

    boost::asio::ip::tcp::socket m_socket;
    boost::asio::io_service& m_io_service;
};

#endif

max_stars_repo_name: TheSonOfDeimos/TCP-File-Transfer

max_issues_repo_name: TheSonOfDeimos/TCP-File-Transfer

max_forks_repo_name: TheSonOfDeimos/TCP-File-Transfer


text:
/**
 * @file
 * @author  Mamadou Babaei <info@babaei.net>
 * @version 0.1.0
 *
 * @section LICENSE
 *
 * (The MIT License)
 *
 * Copyright (c) 2018 - 2019 Mamadou Babaei
 * Copyright (c) 2018 - 2019 Seditious Games Studio
 *
 * 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.
 *
 * @section DESCRIPTION
 *
 * Provides the low-level implementation for the persistent data module.
 */

#include "GPersistentDataImpl/GPersistentDataImpl.h"

#include <sstream>
#include <utility>

#include <GHacks/GUndef_check.h>
THIRD_PARTY_INCLUDES_START
#include <boost/exception/diagnostic_information.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <GHacks/GDisable_C4800.h>
#include <boost/regex.hpp>
#include <GHacks/GRestore_C4800.h>
THIRD_PARTY_INCLUDES_END
#include <GHacks/GRestore_check.h>

THIRD_PARTY_INCLUDES_START
#include <cereal/archives/json.hpp>
#include <fmt/format.h>
#include <fmt/ostream.h>
THIRD_PARTY_INCLUDES_END

#include <GCompressionImpl/GCompressionImpl.h>
#include <GCryptoImpl/GCryptoImpl.h>
#include <GHacks/GInclude_Windows.h>
//#include <GPlatformImpl/GFilesSstemImpl.h>
#include <GPlatformImpl/GSystemImpl.h>
#include <GVersionImpl/GBuildInfoImpl.h>

//#include "GDatabase.h"

struct GPersistentDataImpl::Impl
{

};

GPersistentDataImpl::GPersistentDataImpl()
    : Pimpl(std::make_unique<GPersistentDataImpl::Impl>())
{

}

//GCryptoImpl& GPersistentDataImpl::GetCryptoInstance()
//{
//    static GCryptoImpl Instance(GPersistentDataImpl::Impl::GetSignKey());
//    return Instance;
//}

//GDatabaseImpl& GPersistentDataImpl::GetDatabaseInstance()
//{
//    static bool bInitialized = false;

//    return Instance;
//}

//GPersistentDataImpl::GameDataRecord& GPersistentDataImpl::GetGameData()
//{
//    return Pimpl->GameData;
//}

max_stars_repo_name: SeditiousGames/GodsOfDeceit

max_issues_repo_name: SeditiousGames/GodsOfDeceit

max_forks_repo_name: SeditiousGames/GodsOfDeceit


text:
#include <exception>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
#include <boost/any.hpp>

enum class AnyType {
    Unknown,
    Boolean,
    Integer,
    Double,
    String
};

using WrappedAny = std::tuple < AnyType, boost::any >;

int main() {
    // push value to vector with its type
    std::vector<WrappedAny> v{};
    v.emplace_back(AnyType::Boolean, true);
    v.emplace_back(AnyType::Integer, -1);
    v.emplace_back(AnyType::Double, 1.5);
    v.emplace_back(AnyType::String, std::string("hello"));

    try {
        // print out values by using embedded type
        for (auto& i : v) {
            auto type = std::get<0>(i);
            auto value = std::get<1>(i);

            switch (type) {
            case AnyType::Boolean:
                std::cout << boost::any_cast<bool>(value) << "\n";
                break;

            case AnyType::Integer:
                std::cout << boost::any_cast<int>(value) << "\n";
                break;

            case AnyType::Double:
                std::cout << boost::any_cast<double>(value) << "\n";
                break;

            case AnyType::String:
                std::cout << boost::any_cast<std::string>(value) << "\n";
                break;

            case AnyType::Unknown:
                std::cout << "Unknown type.\n";
                break;
            }
        }
    }
    catch (std::exception& e) {
        std::cout << e.what() << "\n";
    }
}


text:
//  Copyright 2010-2011 Vicente J. Botet Escriba
//  Distributed under the Boost Software License, Version 1.0.
//  See http://www.boost.org/LICENSE_1_0.txt

#define BOOST_CHRONO_VERSION 2

#include <iostream>
#include <boost/type_traits/is_same.hpp>
#include <boost/chrono/stopwatches/stopwatch.hpp>
#include "../cycle_count.hpp"
#include <boost/detail/lightweight_test.hpp>

#if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
#define NOTHING ""
#endif

template <typename Stopwatch>
void check_invariants()
{
    BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::rep, typename Stopwatch::clock::duration::rep>::value), NOTHING, ());
    BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::period, typename Stopwatch::clock::duration::period>::value), NOTHING, ());
    BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::duration, typename Stopwatch::clock::time_point::duration>::value), NOTHING, ());
    BOOST_CHRONO_STATIC_ASSERT(Stopwatch::is_steady == Stopwatch::clock::is_steady, NOTHING, ());
}

template <typename Stopwatch>
void check_default_constructor()
{
  Stopwatch sw;
  BOOST_TEST(sw.is_running());
}

template <typename Stopwatch>
void check_dont_start_constructor()
{
  Stopwatch sw(boost::chrono::dont_start);
  BOOST_TEST(!sw.is_running());
  ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
  typename Stopwatch::duration d=sw.elapsed();
  BOOST_TEST(d == Stopwatch::duration::zero());
}

#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
template <typename Stopwatch>
void check_constructor_ec()
{
  boost::system::error_code ec;
  Stopwatch sw(ec);
  BOOST_TEST(sw.is_running());
  BOOST_TEST(ec.value()==0);
}

template <typename Stopwatch>
void check_constructor_throws()
{
  Stopwatch sw(boost::throws());
  BOOST_TEST(sw.is_running());
}
#endif

template <typename Stopwatch>
void check_elapsed()
{
  Stopwatch sw;
  BOOST_TEST(sw.is_running());
  ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
  typename Stopwatch::duration d=sw.elapsed();
  BOOST_TEST(sw.is_running());
  BOOST_TEST(d >= boost::chrono::milliseconds(100));
}

template <typename Stopwatch>
void check_start_start()
{
  Stopwatch sw;
  BOOST_TEST(sw.is_running());
  ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
  sw.start();
  BOOST_TEST(sw.is_running());
  ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
  typename Stopwatch::duration d=sw.elapsed();
  BOOST_TEST(sw.is_running());
  BOOST_TEST(d >= boost::chrono::milliseconds(100));
  BOOST_TEST(d < boost::chrono::milliseconds(200));
}

template <typename Stopwatch>
void check_dont_start_start()
{
  Stopwatch sw(boost::chrono::dont_start);
  BOOST_TEST(!sw.is_running());
  ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
  sw.start();
  BOOST_TEST(sw.is_running());
  ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
  typename Stopwatch::duration d=sw.elapsed();
  BOOST_TEST(sw.is_running());
  BOOST_TEST(d >= boost::chrono::milliseconds(100));
  BOOST_TEST(d < boost::chrono::milliseconds(200));
}

template <typename Stopwatch>
void check_dont_start_start_stop()
{
  Stopwatch sw(boost::chrono::dont_start);
  BOOST_TEST(!sw.is_running());
  sw.start();
  BOOST_TEST(sw.is_running());
  ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
  sw.stop();
  BOOST_TEST(!sw.is_running());
  typename Stopwatch::duration d=sw.elapsed();
  BOOST_TEST(!sw.is_running());
  BOOST_TEST(d >= boost::chrono::milliseconds(0));
}

template <typename Stopwatch>
void check_dont_start_scoped_run()
{
  Stopwatch sw(boost::chrono::dont_start);
  BOOST_TEST(!sw.is_running());
  {
    typename Stopwatch::scoped_run _(sw);
    BOOST_TEST(sw.is_running());
    ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
  }
  BOOST_TEST(!sw.is_running());
  typename Stopwatch::duration d=sw.elapsed();
  BOOST_TEST(!sw.is_running());
  BOOST_TEST(d >= boost::chrono::milliseconds(0));
}

template <typename Stopwatch>
void check_stop()
{
  Stopwatch sw;
  BOOST_TEST(sw.is_running());
  ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
  sw.stop();
  BOOST_TEST(!sw.is_running());
  typename Stopwatch::duration d=sw.elapsed();
  BOOST_TEST(!sw.is_running());
  BOOST_TEST(d == boost::chrono::milliseconds(0));
}

template <typename Stopwatch>
void check_stop_stop()
{
  Stopwatch sw;
  BOOST_TEST(sw.is_running());
  ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
  sw.stop();
  BOOST_TEST(!sw.is_running());
  typename Stopwatch::duration d=sw.elapsed();
  BOOST_TEST(!sw.is_running());
  BOOST_TEST(d == boost::chrono::milliseconds(0));
  sw.stop();
  BOOST_TEST(!sw.is_running());
  d=sw.elapsed();
  BOOST_TEST(!sw.is_running());
  BOOST_TEST(d == boost::chrono::milliseconds(0));
}

template <typename Stopwatch>
void check_all()
{
  check_invariants<Stopwatch>();
  check_default_constructor<Stopwatch>();
#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
  check_constructor_ec<Stopwatch>();
  check_constructor_throws<Stopwatch>();
#endif
  check_elapsed<Stopwatch>();

  check_start_start<Stopwatch>();
  check_dont_start_constructor<Stopwatch>();
  check_dont_start_start<Stopwatch>();
  check_dont_start_start_stop<Stopwatch>();
  check_dont_start_scoped_run<Stopwatch>();
  check_stop<Stopwatch>();
  check_stop_stop<Stopwatch>();

}

int main()
{
  std::cout << "cycle_count=";
  check_all<boost::chrono::stopwatch< ex::cycle_count<1500> > >();

  return boost::report_errors();
}


text: #include <boost/mpl/aux_/preprocessed/no_ttp/list.hpp>

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino


text:
// This file is part of SWGANH which is released under the MIT license.
// See file LICENSE or go to http://swganh.com/LICENSE

#ifndef WIN32
#include <Python.h>
#endif

#include <exception>
#include <iostream>
#include <string>

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

#include "swganh/logger.h"
#include "swganh/utilities.h"

#include "swganh/app/swganh_app.h"
#include "swganh/app/swganh_kernel.h"
#include "swganh/event_dispatcher.h"
#include "swganh/scripting/utilities.h"

using namespace boost;
using namespace swganh;
using namespace std;

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

    // Step 2: Release the GIL from the main thread so that other threads can use it
    PyEval_ReleaseThread(PyGILState_GetThisThreadState());

    try {
        app::SwganhApp app(argc, argv);

        for (;;) {

            if (swganh::KeyboardHit())
            {
                char input = swganh::GetHitKey();
                if (input == '`' || input =='~')
                {
                    app.StartInteractiveConsole();
                }
                else
                {
                    // Echo out the input that was given and add it back to the input stream to read in.
                    std::cout << input;
                    cin.putback(input);

                    string cmd;
                    cin >> cmd;

                    if (cmd.compare("exit") == 0 || cmd.compare("quit") == 0 || cmd.compare("q") == 0) {
                        LOG(info) << "Exit command received from command line. Shutting down.";
                        break;
                    }
					else if(cmd.compare("si_dump") == 0) {
						app.GetAppKernel()->GetEventDispatcher()->Dispatch(std::make_shared<swganh::BaseEvent>("SpatialIndexSvgDump"));
					}
					else {
                        LOG(warning) << "Invalid command received: " << cmd;
                        std::cout << "Type exit or (q)uit to quit" << std::endl;
                    }
                }
            }
			boost::this_thread::sleep(boost::posix_time::milliseconds(500));
        }

    } catch(std::exception& e) {
        LOG(fatal) << "Unhandled application exception occurred: " << e.what();
    }

    // Step 4: Lock the GIL before calling finalize
    PyGILState_Ensure();
    Py_Finalize();

    return 0;
}

ext: cc

max_stars_repo_name: apathyboy/swganh

max_issues_repo_name: apathyboy/swganh

max_forks_repo_name: apathyboy/swganh


text:
#include "DocumentLoader.h"
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <sstream>

using json = nlohmann::json;
using namespace boost::filesystem;

namespace {

    std::string getFileContents(const path &p) {
        ifstream f{p};
        const auto size = file_size(p);
        std::string buffer(size, ' ');
        f.read(&buffer[0], static_cast<std::streamsize>(size));
        return buffer;
    }

}

RemoteDocument DocumentLoader::loadDocument(const std::string &url) {

    // first check the cache
    auto it = cache.find(url);
    if(it != cache.end())
        return RemoteDocument(url, it->second);

    // do something to load
    path p(url);
    if(exists(p)) {
        // read file into string
        std::string fileContents = getFileContents(p);

        // create the json object
        json j = json::parse(fileContents);

        // add to cache
        cache[url] = j;

        return RemoteDocument(url, j);
    }
    else {
        std::stringstream ss;
        ss << "Error: Url not found: [" << url << "]";
        throw std::runtime_error(ss.str());
    }

}

void DocumentLoader::addDocumentToCache(const std::string &url, const std::string &contents) {
    json j = json::parse(contents);
    cache.insert(std::make_pair(url, j));
}

max_stars_repo_name: dcdpr/jsonld-cpp

max_issues_repo_name: dcdpr/jsonld-cpp

max_forks_repo_name: dcdpr/jsonld-cpp


text:
/**
 * @file Solution.cpp
 * @author Giulio Romualdi
 * @copyright Released under the terms of the MIT License.
 * @date 2021
 */

#include <scs.h>
#include <util.h>
#include <glbopts.h>

#include <ScsEigen/Solution.h>

#include <Eigen/Sparse>

using namespace ScsEigen;

Solution::Status Solution::getStatus(int i)
{
    switch (i)
    {
    case SCS_INFEASIBLE_INACCURATE:
        return Status::infeasible_inaccurate;
    case SCS_UNBOUNDED_INACCURATE:
        return Status::unbounded_inaccurate;
    case SCS_SIGINT:
        return Status::sigint;
    case SCS_FAILED:
        return Status::failed;
    case SCS_INDETERMINATE:
        return Status::indeterminate;
    case SCS_INFEASIBLE:
        return Status::infeasible;
    case SCS_UNBOUNDED:
        return Status::unbounded;
    case SCS_UNFINISHED:
        return Status::unfinished;
    case SCS_SOLVED:
        return Status::solved;
    case SCS_SOLVED_INACCURATE:
        return Status::solved_inaccurate;
    default:
        return Status::unknown;
    }
}

bool Solution::isValid() const
{
    // solution and complete solution can be empty only if solution Solution::Status is different
    // from "solved" and "solved_inaccurate"

    const bool isSolutionOk = ((status == Status::solved || status == Status::solved_inaccurate)
                               && (solution.size() != 0 && completeSolution.size() != 0))
                              || (status != Status::solved && status != Status::solved_inaccurate);

    // residueUnbounded and residueInfeasibility can be nan. Please check
    // https://github.com/cvxgrp/scs/blob/48dfbe81caad2162c3ce5757faccdb3f3d31e142/src/scs.c#L226-L229

    return (status != Status::unknown) && !std::isnan(primalObjective) && !std::isnan(dualObjective)
           && !std::isnan(primalResidue) && !std::isnan(relativeDualityGap)
           && !std::isnan(setupTime) && !std::isnan(solveTime) && (dualVariable.size() != 0)
           && (primalEqualitySlack.size() != 0) && isSolutionOk;
}

max_stars_repo_name: GiulioRomualdi/scs-eigen

max_issues_repo_name: GiulioRomualdi/scs-eigen

max_forks_repo_name: GiulioRomualdi/scs-eigen


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

namespace boost { namespace simd
{
  namespace tag
  {
    /*!
      @brief saturate generic tag

      Represents the saturate function in generic contexts.

      @par Models:
      Hierarchy
    **/
    struct saturate_ : ext::elementwise_<saturate_>
    {
      /// @brief parent Hierarchy
      typedef ext::elementwise_<saturate_> parent;
      template<class... Args>
      static BOOST_FORCEINLINE BOOST_AUTO_DECLTYPE dispatch(Args&&... args)
      BOOST_AUTO_DECLTYPE_BODY( dispatching_saturate_( ext::adl_helper(), static_cast<Args&&>(args)... ) )
    };
  }
  namespace ext
  {
    template<class Site, class... Ts>
    BOOST_FORCEINLINE generic_dispatcher<tag::saturate_, Site> dispatching_saturate_(adl_helper, boost::dispatch::meta::unknown_<Site>, boost::dispatch::meta::unknown_<Ts>...)
    {
      return generic_dispatcher<tag::saturate_, Site>();
    }
    template<class... Args>
    struct impl_saturate_;
  }

  /*!

    Saturate a value of type @c T with the limit values of type @c S.

    @par Semantic:

    @code
    T r = saturate(x, as_<S>())
    @endcode

    is similar to:

    @code
    if (a0 > Inf<S>()) r =  T(Inf<S>());
    else if  (a0 <  Minf<S>()) r =  T(Minf<S>());
    else r = a0;
    @endcode

    @par Note:
    Note that the functor is only valid if conceptually the type S is included in type T
    (or the contrary but this case leads to identity)

    @param a0 Value to saturate
    @param a1 Type specifier of the saturation limit

    @return  The input value saturated on limit of the type specifier
  **/
  BOOST_DISPATCH_FUNCTION_IMPLEMENTATION(tag::saturate_, saturate, 2)

  /*!
    Returns the saturated value of the first input in the template parameter type,
    but in the same type as the input.

    @par Semantic:

    @code
    T r = saturate<S>(x)
    @endcode

    is similar to:

    @code
    if (a0 > Inf<S>()) r =  T(Inf<S>());
    else if  (a0 <  Minf<S>()) r =  T(Minf<S>());
    else r = a0;
    @endcode

    @param a0

    @return a value of same type as the inputs
  **/
  template<class T,class A0> BOOST_FORCEINLINE
  typename boost::dispatch::meta::
                  call< tag::saturate_( A0 const&
                                      , boost::dispatch::meta::as_<T>
                                      )
                      >::type
  saturate(A0 const& a0)
  {
    typename boost::dispatch::make_functor<tag::saturate_, A0>::type callee;
    return callee(a0,boost::dispatch::meta::as_<T>());
  }
} }

#endif


text:
// Copyright 2018 Krister Joas <krister@joas.jp>

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

//     http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <iostream>
#include <boost/filesystem.hpp>
#include "m.hh"

namespace fs = boost::filesystem;

namespace m {
class Loader
{
  public:
    Loader(const std::string& topdir = ".", const std::string& builddir = "build")
      : _topdir(topdir), _builddir(builddir)
    {}
    BuilderBase& load_file(const std::string& file, BuilderBase* initial_builder = nullptr);
  private:
    void find_files(const fs::path& dir, const std::string& file, std::set<std::string>& result);
    const std::string _topdir;
    const std::string _builddir;
};
}

ext: hh

max_stars_repo_name: kuriboshi/m

max_issues_repo_name: kuriboshi/m

max_forks_repo_name: kuriboshi/m


text:
#include <cstdlib>
#include <cstring>
#include <random>
#include <string>

#include <boost/random.hpp>

#include "common.h"
#include "scope.h"

const std::vector<cstring> str_keywords = {"if",  "void",    "else",
                                           "key", "actions", "true"};

static const char alphanum[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                               "abcdefghijklmnopqrstuvwxyz";
// "0123456789"

namespace CODEGEN {
static boost::random::mt19937 rng;

void set_seed(int64_t seed) { rng = boost::mt19937(seed); }

int64_t get_rnd_int(int64_t min, int64_t max) {
    boost::random::uniform_int_distribution<int64_t> distribution(min, max);
    return distribution(rng);
}

big_int get_rnd_big_int(big_int min, big_int max) {
    boost::random::uniform_int_distribution<big_int> distribution(min, max);
    return distribution(rng);
}

cstring randstr(size_t len) {
    cstring ret;
    std::stringstream ss;

    while (1) {
        ss.str("");
        for (size_t i = 0; i < len; i++) {
            ss << alphanum[get_rnd_int(0, sizeof(alphanum) - 2)];
        }
        ret = ss.str();
        if (std::find(str_keywords.begin(), str_keywords.end(), ret) !=
            str_keywords.end()) {
            continue;
        }

        // name is usable, break the loop
        if (P4Scope::used_names.count(ret) == 0) {
            break;
        }
        delete ret;
    }

    P4Scope::used_names.insert(ret);
    return ret;
}

int64_t randind(const std::vector<int64_t> &percent) {
    int sum = accumulate(percent.begin(), percent.end(), 0);

    // do not pick zero since that conflicts with zero percentage values
    auto rand_num = get_rnd_int(1, sum);
    int ret = 0;

    int64_t ret_sum = 0;
    for (auto i : percent) {
        ret_sum += i;
        if (ret_sum >= rand_num) {
            break;
        }
        ret = ret + 1;
    }
    return ret;
}
} // namespace CODEGEN