text:
/// @file pair_collection.hpp defintions for the pair collection that are used for mergable tracks

#ifndef BIGGLES_DETAIL_PAIR_COLLECTION_HPP___
#define BIGGLES_DETAIL_PAIR_COLLECTION_HPP___

#include <boost/assert.hpp>
#include <boost/foreach.hpp>
#include <deque>
#include <iterator>
#include <map>
#include <set>

namespace biggles {
namespace detail {

template<typename Value>
class pair_collection_iterator : public std::iterator<std::forward_iterator_tag, const std::pair<Value, Value> >
{
public:
    typedef Value value;

    typedef std::pair<value, value> value_pair;

    pair_collection_iterator() { }

    pair_collection_iterator(const pair_collection_iterator& i)
        : map_iterator_(i.map_iterator_)
        , map_end_(i.map_end_)
        , set_iterator_(i.set_iterator_)
        , value_pair_(i.value_pair_)
    {
        bump_up();
    }

    pair_collection_iterator(typename std::map<value, std::set<value> >::const_iterator map_iterator,
                             typename std::map<value, std::set<value> >::const_iterator map_end,
                             typename std::set<value>::const_iterator set_iterator)
        : map_iterator_(map_iterator)
        , map_end_(map_end)
        , set_iterator_(set_iterator)
    {
        bump_up();
    }

    const pair_collection_iterator& operator = (const pair_collection_iterator& i)
    {
        map_iterator_ = i.map_iterator_;
        map_end_ = i.map_end_;
        set_iterator_ = i.set_iterator_;
        bump_up();
    }

    const pair_collection_iterator& operator ++ ()
    {
        if(map_iterator_ == map_end_)
            return *this;

        ++set_iterator_;
        bump_up();

        return *this;
    }

    bool operator == (const pair_collection_iterator& i)
    {
        return (i.map_iterator_ == map_iterator_) && (i.set_iterator_ == set_iterator_);
    }

    bool operator != (const pair_collection_iterator& i)
    {
        return (i.map_iterator_ != map_iterator_) || (i.set_iterator_ != set_iterator_);
    }

    const std::pair<value, value>& operator * ()
    {
        if(map_iterator_ != map_end_)
            value_pair_ = std::make_pair(map_iterator_->first, *set_iterator_);
        return value_pair_;
    }

    const std::pair<value, value>* operator -> ()
    {
        if(map_iterator_ != map_end_)
            value_pair_ = std::make_pair(map_iterator_->first, *set_iterator_);
        return &value_pair_;
    }

protected:
    typename std::map<value, std::set<value> >::const_iterator map_iterator_;
    typename std::map<value, std::set<value> >::const_iterator map_end_;
    typename std::set<value>::const_iterator set_iterator_;
    std::pair<value, value> value_pair_;

    void bump_up()
    {
        while(1)
        {
            if(map_iterator_ == map_end_)
                return;

            if(set_iterator_ == map_iterator_->second.end())
            {
                ++map_iterator_;
                if(map_iterator_ == map_end_)
                {
                    set_iterator_ = typename std::set<value>::const_iterator();
                }
                else
                {
                    set_iterator_ = map_iterator_->second.begin();
                }
            }
            else
            {
                return;
            }
        }
    }
};

template<typename Value>
class pair_collection
{
public:
    typedef Value value;

    typedef std::pair<const value, const value> value_pair;

private:
    struct pair_compare {
        bool operator() (const value_pair& a, const value_pair& b) const {
            return a.first < b.first or (a.first == b.first and a.second < b.second);
        }
    };

protected:
    typedef std::multiset<value_pair, pair_compare> value_pair_multiset;

public:
    typedef typename value_pair_multiset::const_iterator const_iterator;

    typedef typename value_pair_multiset::const_iterator iterator;

    pair_collection() { }

    pair_collection(const pair_collection& pc)
        : pairs_(pc.pairs_)
    { }

    const pair_collection& operator = (const pair_collection& pc)
    {
        pairs_ = pc.pairs_;
    }

    template<typename InputIterator>
    pair_collection(InputIterator first,
                    InputIterator last);

    template<typename InputIterator>
    void insert(InputIterator first, InputIterator last);

    void insert(const value_pair& pair);

    void erase_pairs_with_element(const value& v);

    bool contains_pair_with_element(const value& v) const;

    size_t size() const { return pairs_.size(); }

    bool empty() const { return pairs_.empty(); }

    const_iterator begin() const { return pairs_.begin(); }

    const_iterator end() const { return pairs_.end(); }

protected:
    value_pair_multiset pairs_;
};

template<typename Value>
template<typename InputIterator>
pair_collection<Value>::pair_collection(InputIterator first,
                                        InputIterator last)
{
    insert(first, last);
}

template<typename Value>
template<typename InputIterator>
void pair_collection<Value>::insert(InputIterator first,
                                    InputIterator last)
{
    BOOST_FOREACH(const value_pair& p, std::make_pair(first, last))
    {
        insert(p);
    }
}

template<typename Value>
void pair_collection<Value>::insert(const pair_collection<Value>::value_pair& pair)
{
    value_pair pair_to_insert(
        (pair.first < pair.second)
        ? std::make_pair(pair.first, pair.second)
        : std::make_pair(pair.second, pair.first));

    BOOST_FOREACH(const value_pair& p, pairs_.equal_range(pair_to_insert))
    {
        if(p == pair_to_insert)
            return;
    }
    pairs_.insert(pair_to_insert);
}

template<typename Value>
bool pair_collection<Value>::contains_pair_with_element(const pair_collection<Value>::value& v) const
{
    BOOST_FOREACH(const value_pair& p, pairs_)
    {
        if(p.first == v)
            return true;
        if(p.second == v)
            return true;
    }

    return false;
}

template<typename Value>
void pair_collection<Value>::erase_pairs_with_element(const value& v)
{
    for(;;) {
        // This erases a single pair with v as first or second
        const_iterator i(pairs_.begin());
        for(; (i != pairs_.end()) && (i->first != v) && (i->second != v); ++i) {
            /* nop */
        }
        if(i != pairs_.end()) {
            pairs_.erase(i);
        } else {
            break;
        }
    }
}

} }

#endif // BIGGLES_DETAIL_PAIR_COLLECTION_HPP___

ext: hpp

max_stars_repo_name: fbi-octopus/biggles

max_issues_repo_name: fbi-octopus/biggles

max_forks_repo_name: fbi-octopus/biggles


text:
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*
 Copyright (C) 2006, 2008 Plamen Neykov
 Copyright (C) 2007, 2008, 2010 Eric Ehlers
 Copyright (C) 2008 Nazcatech sprl Belgium

 This file is part of QuantLib, a free-software/open-source library
 for financial quantitative analysts and developers - http://quantlib.org/

 QuantLib is free software: you can redistribute it and/or modify it
 under the terms of the QuantLib license.  You should have received a
 copy of the license along with this program; if not, please email
 <quantlib-dev@lists.sf.net>. The license is also available online at
 <http://quantlib.org/license.shtml>.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.
*/

/*! \file
    \brief Class ValueObject - Captures the inputs to an Object
*/

#ifndef oh_valueobject_hpp
#define oh_valueobject_hpp

#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <oh/property.hpp>
#include <oh/utilities.hpp>
#include <boost/serialization/access.hpp>

namespace ObjectHandler {

    //! Capture the values of the arguments passed to the Object constructor.
    /*! For each class derived from Object there is a corresponding ValueObject
        class.  The source code of classes derived from ValueObject is generated
        automatically by gensrc.  Each Object holds a reference to its
        ValueObject.

        The ValueObject captures a snapshot of the input arguments that were
        passed to the Object's constructor.  These values can be used later
        for serialization or run-time interrogation of the Object.

        This class's member functions are implemented inline in this header
        file.  This is necessary to work around problems on the Windows platform
        when exporting this class across DLL boundaries.
    */
    class ValueObject {
    public:
        //! \name Structors
        //@{
        //! Default constructor, required by boost::serialization.
        /*! Member variables are initialized with null values, these will be
            populated during deserialization.
        */
        ValueObject() : objectId_(""), className_(""), permanent_(false) {}
        //! Standard constructor called by derived classes.
        ValueObject(
            const std::string &objectId,
            const std::string &className,
            bool permanent)
            : objectId_(objectId), className_(className), permanent_(permanent) {}
        //! Empty virtual destructor.
        virtual ~ValueObject() {}
        //@}

        /*! \name Properties
            System properties are set when the ValueObject is constructed - a snapshot
            of the inputs to the ValueObject's constructor.

            User properties are additional values which are attached to the ValueObject
            after its creation.
        */
        //@{
        //! Retrieve the property names as a std::set.
        std::set<std::string> getPropertyNames() const;
        //! Retrieve the property names as a std::vector.
        virtual std::vector<std::string> getPropertyNamesVector() const = 0;
        //! Retrieve the names of the system properties stored in the ValueObject.
        virtual const std::set<std::string>& getSystemPropertyNames() const = 0;
        //! Retrieve the value of a property given its name.
        property_t getProperty(const std::string& name) const;
        //! Retrieve the value of a system property given its name.
        virtual property_t getSystemProperty(const std::string& name) const = 0;
        //! Determine whether the given user property is present.
        bool hasProperty(const std::string& name) const;
        //! Set the value of the given property.
        void setProperty(const std::string& name, const property_t& value);
        //! Set the value of the given system property.
        virtual void setSystemProperty(const std::string& name, const property_t& value) = 0;
        //@}

        //! \name Inspectors
        //@{
        //! Retrieve the ID of the underlying Object in the Repository.
        const std::string& objectId() const { return objectId_; }
        //! Retrieve the list of precedent Object IDs.
        const std::set<std::string>& getPrecedentObjects() { return precedentIDs_;}
        //! Name of this ValueObject's class.
        const std::string &className() const { return className_; }
        //@}

        //! \name processorName
        //@{
        //! the name of the processor that is required for that ValueObject;
        /*
            For ValueObject classes which do not require special processing,
            processorName() returns DefaultProcessor.
        */
        virtual std::string processorName()  { return "DefaultProcessor"; }
        //@}

        /*! \name Precedent Object IDs
            Functions used in managing the list of precedent Objects.

            If any of the precedent Objects changes then the Object associated
            with this ValueObject must also be recreated.
        */
        //@{
        //! Store the object ID in the list of precedents.
        void processPrecedentID(const std::string& precedentID);
        //! Extract the Object ID from the property_t and pass it to processPrecedentID()
        void processVariant(property_t variantID);
        //! Extract the Object IDs from the property_t vector and pass them to processPrecedentID()
        void processVariant(const std::vector<property_t>& vecVariantID);
        //! Extract the Object IDs from the property_t matrix and pass them to processPrecedentID()
        void processVariant(const std::vector<std::vector<property_t> >& vecVariantIDs);
        //@}
    protected:
        //! ID of the Object associated with this ValueObject.
        std::string objectId_;
        //! A string identifiying the class of this ValueObject.
        std::string className_;
        //! Boolean indicating whether the associated Object is permanent.
        /*! \sa Object::permanent() */
        bool permanent_;
        //! Name/Value pair map representing the user defined properties.
        std::map<std::string, property_t> userProperties;
        //! List of precedent Object IDs
        std::set<std::string> precedentIDs_;
    };

    inline void ValueObject::processPrecedentID(const std::string& precedentID) {
        if (!precedentID.empty())
            precedentIDs_.insert(precedentID);
    }

    // FIXME This function should take a const ref:
    //inline void ValueObject::processVariant(const property_t& variantID){
    inline void ValueObject::processVariant(property_t variantID){
        std::string *objectID;
        if ((objectID = boost::get<std::string>(&variantID)) && !isNumeric(*objectID))
            processPrecedentID(*objectID);
    }

    inline void ValueObject::processVariant(const std::vector<property_t>& vecVariantID){
        std::vector<property_t>::const_iterator iterator = vecVariantID.begin();
        for(; iterator != vecVariantID.end(); ++iterator)
            processVariant(*iterator);
    }

    inline void ValueObject::processVariant(const std::vector<std::vector<property_t> >& vecVariantIDs){
        std::vector<std::vector<property_t> >::const_iterator iterator = vecVariantIDs.begin();
        for(; iterator != vecVariantIDs.end(); ++iterator){
            processVariant(*iterator);
        }
    }

    inline std::set<std::string> ValueObject::getPropertyNames() const {
        std::set<std::string> ret(getSystemPropertyNames());
        for(std::map<std::string, property_t>::const_iterator i
            = userProperties.begin(); i != userProperties.end(); ++i)
            ret.insert(i->first);
        return ret;
    }

    inline property_t ValueObject::getProperty(const std::string& name) const {
        if(userProperties.find(name) != userProperties.end())
            return userProperties.find(name)->second;
        else
            return getSystemProperty(name);
    }

    inline bool ValueObject::hasProperty(const std::string& name) const {
        return userProperties.find(name) != userProperties.end();
    }

    inline void ValueObject::setProperty(const std::string& name, const property_t& value) {
        const std::set<std::string>& sysNames = getSystemPropertyNames();
        if(sysNames.find(name) != sysNames.end())
            setSystemProperty(name, value);
        else
            userProperties[name] = value;
    }
}

#endif


text:
#include "modules/bio_base/seqset_merger.h"
#include "base/base.h"
#include "modules/bio_base/seqset.h"
#include "modules/bio_base/seqset_mergemap.h"
#include "modules/io/file_io.h"
#include "modules/io/parallel.h"
#include "modules/io/spiral_file_mem.h"
#include "modules/io/spiral_file_mmap.h"
#include "modules/test/coverage.h"

#include <sys/mman.h>

#include <boost/filesystem.hpp>

DECLARE_TEST_COVERAGE(seqset_merger);

seqset_merger::seqset_merger(
    const std::vector<const seqset_flat*>& flats,
    const std::vector<const seqset_mergemap*>& seqset_mergemaps)
    : m_flats(flats),
      m_mergemaps(seqset_mergemaps),
      m_num_inputs(m_flats.size()) {
  CHECK_EQ(m_flats.size(), m_mergemaps.size());
  CHECK_GT(m_num_inputs, 0);
  m_num_seqs = m_mergemaps[0]->get_bitcount().size();
  for (unsigned i = 0; i < m_num_inputs; ++i) {
    CHECK_EQ(m_flats[i]->get_seqset()->uuid(),
             m_mergemaps[i]->metadata().orig_seqset_uuid);
    CHECK_EQ(m_num_seqs, m_mergemaps[i]->get_bitcount().size());
    CHECK_EQ(m_mergemaps[i]->get_bitcount().total_bits(), m_flats[i]->size());
  }
}

namespace {

unsigned shared_prefix_length(const dna_slice& seq1, const dna_slice& seq2) {
  unsigned shared_length = std::min(seq1.size(), seq2.size());

  for (unsigned i = 0; i < shared_length; ++i) {
    if (seq1[i] != seq2[i]) {
      return i;
    }
  }
  return shared_length;
}

}  // namespace

void seqset_merger::build(const spiral_file_create_state& state,
                          progress_handler_t progress) {
  CHECK(!m_seqset);

  for (unsigned i = 0; i < m_num_inputs; ++i) {
    CHECK_EQ(state.uuid(), m_mergemaps[i]->metadata().merged_seqset_uuid);
  }

  unsigned max_read_len = 0;
  for (const auto& f : m_flats) {
    max_read_len = std::max<unsigned>(max_read_len, f->get_seqset()->max_read_len());
  }

  SPLOG("Creating merged seqset with %ld entries, %d maximum entry length", m_num_seqs, max_read_len);
  m_seqset.reset(new seqset(state, m_num_seqs, max_read_len));

  parallel_for(
      0, m_num_seqs,
      [this](size_t start, size_t limit) { merge_range(start, limit); },
      progress);
  SPLOG("Finalizing merged seqset");
  m_seqset->finalize(progress);
  SPLOG("Done creating merged seqest");
}

seqset_merger::iterator seqset_merger::get_base_iterator(dna_base base,
                                                         iterator it) {
  if (it == end()) {
    if (base == dna_base(3)) {
      NOTE_TEST_COVERAGE(seqset_merger);
      return end();
    }

    NOTE_TEST_COVERAGE(seqset_merger);
    dna_sequence search_for;
    search_for.push_back(dna_base(int(base) + 1));
    return std::lower_bound(begin(), end(),
                            dna_slice(search_for.begin(), search_for.end()));
  }

  dna_sequence search_for;
  search_for.push_back(base);
  search_for += dna_sequence(it->begin(), it->end());
  dna_slice search_for_slice(search_for.begin(), search_for.end());
  iterator result = std::lower_bound(begin(), end(), search_for_slice);
  while (result != begin()) {
    iterator prev = result;
    --prev;
    unsigned compare_len = std::min(prev->size(), search_for.size());
    if (subseq_compare(prev->begin(), search_for.begin(), compare_len,
                       compare_len) == dna_compare_result::EQUAL) {
      NOTE_TEST_COVERAGE(seqset_merger);
      result = prev;
    } else {
      NOTE_TEST_COVERAGE(seqset_merger);
      return result;
    }
  }
  return result;
}

void seqset_merger::merge_range(size_t start_offset, size_t limit_offset) {
  iterator start = begin() + start_offset;
  iterator limit = begin() + limit_offset;

  iterator end_iterator = end();

  dna_slice prev_seq;
  if (start == begin()) {
    NOTE_TEST_COVERAGE(seqset_merger);
  } else {
    NOTE_TEST_COVERAGE(seqset_merger);
    prev_seq = *(start - 1);
  }
  dna_base_array<iterator> base_iterator;
  dna_base_array<iterator> base_limit;
  dna_base_array<dna_slice> base_slice;
  for (dna_base base : dna_bases()) {
    base_iterator[base] = get_base_iterator(base, start);
    base_limit[base] = get_base_iterator(base, limit);
    if (base_iterator[base] == end_iterator) {
      NOTE_TEST_COVERAGE(seqset_merger);
    } else {
      NOTE_TEST_COVERAGE(seqset_merger);
      base_slice[base] = *base_iterator[base];
    }
  }

  for (iterator cur = start; cur != limit; ++cur) {
    dna_slice cur_seq = *cur;
    DCHECK(cur_seq > prev_seq) << "\nCur:  " << cur_seq.as_string()
                               << "\nPrev: " << prev_seq.as_string() << "\n";
    DCHECK_GT(cur_seq.size(), 0);

    m_seqset->set_entry_size(cur.merge_idx(), cur_seq.size());

    for (dna_base base : dna_bases()) {
      // Compare the main DNA sequence with an overlap candidate.  To
      // qualify, the candidate suffix (i.e. everything but the first
      // base) must be a prefix of the main sequence.  If there's an
      // overlap, advance the candidate sequence buffer and return
      // true.
      if (base_iterator[base] == base_limit[base]) {
        NOTE_TEST_COVERAGE(seqset_merger);
        continue;
      }
      unsigned overlap_size =
          std::min(base_slice[base].size() - 1, cur_seq.size());
      // The potential overlap is the smaller of the candidate suffix
      // or main sequence
      DCHECK_EQ(base_slice[base][0], base);

      dna_compare_result compare =
          subseq_compare(base_slice[base].begin() + 1, cur_seq.begin(),
                         overlap_size, overlap_size);
      if (compare == dna_compare_result::EQUAL) {
        m_seqset->set_bit(cur.merge_idx(), base, true);
        base_iterator[base]++;
        if (base_iterator[base] == base_limit[base]) {
          NOTE_TEST_COVERAGE(seqset_merger);
        } else {
          NOTE_TEST_COVERAGE(seqset_merger);
          base_slice[base] = *base_iterator[base];
        }
      } else {
        CHECK_EQ(compare, dna_compare_result::SECOND_IS_LESS)
            << "Out-of-order prevs for overlap " << overlap_size
            << ": \nCur:  " << cur_seq.as_string() << "\n"
            << base << ":   " << base_slice[base].as_string();
        NOTE_TEST_COVERAGE(seqset_merger);
      }
    }

    m_seqset->set_shared(cur.merge_idx(),
                         shared_prefix_length(cur_seq, prev_seq));

    prev_seq = cur_seq;
  }

  for (dna_base base : dna_bases()) {
    CHECK(base_iterator[base] == base_limit[base])
        << base << " " << base_iterator[base].merge_idx() << " "
        << base_limit[base].merge_idx() << "\nM:  " << prev_seq.as_string()
        << "\nL:  " << limit->as_string()
        << "\nb: " << base_iterator[base]->as_string()
        << "\nl: " << base_limit[base]->as_string() << "\n";
  }
}

void seqset_merger::iterator::seek_to_merge_idx() {
  for (unsigned flat_id = 0; flat_id < m_merger->m_flats.size(); flat_id++) {
    m_part_idx[flat_id] =
        m_merger->m_mergemaps[flat_id]->get_bitcount().count(m_merge_idx);
  }
}

void seqset_merger::iterator::increment() {
  for (unsigned flat_id = 0; flat_id < m_merger->m_flats.size(); flat_id++) {
    if (m_merger->m_mergemaps[flat_id]->get_bitcount().get(m_merge_idx)) {
      m_part_idx[flat_id]++;
    }
  }
  m_merge_idx++;
}

void seqset_merger::iterator::decrement() {
  DCHECK_GT(m_merge_idx, 0);
  m_merge_idx--;
  for (unsigned flat_id = 0; flat_id < m_merger->m_flats.size(); flat_id++) {
    if (m_merger->m_mergemaps[flat_id]->get_bitcount().get(m_merge_idx)) {
      m_part_idx[flat_id]--;
    }
  }
}

dna_slice seqset_merger::iterator::dereference() const {
  dna_slice seq;
  for (unsigned flat_id = 0; flat_id < m_merger->m_flats.size(); ++flat_id) {
    if (m_merger->m_mergemaps[flat_id]->get_bitcount().get(m_merge_idx)) {
      dna_slice part_seq = m_merger->m_flats[flat_id]->get(m_part_idx[flat_id]);
      if (part_seq.size() > seq.size()) {
        NOTE_TEST_COVERAGE(seqset_merger);
        seq = part_seq;
      } else {
        NOTE_TEST_COVERAGE(seqset_merger);
      }
    }
  }
  DCHECK_GT(seq.size(), 0);
  return seq;
}

ext: cpp

max_stars_repo_name: spiralgenetics/biograph

max_issues_repo_name: spiralgenetics/biograph

max_forks_repo_name: spiralgenetics/biograph


text:
#pragma once

#include <algorithm>
#include <thread>

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>

#include "TcpConnection.hpp"
#include "DBConfig.hpp"
#include "DBI.hpp"

using boost::asio::ip::tcp;
using stac::config::DBConfig;
using stac::config::connection_string;
using stac::db::DBI;
using stac::db::print_sql_error;

namespace stac {
namespace tcpip {

template <typename ConnectionHandler>
class TcpServer
{
  using shared_handler_t = boost::shared_ptr<ConnectionHandler>;

  unsigned short m_port = 0;
  unsigned m_thread_count = 1;
  std::vector<std::thread> m_thread_pool;
  boost::asio::io_service m_service;
  tcp::acceptor m_acceptor;
  boost::asio::signal_set m_signals;
  std::shared_ptr<DBI> m_dbi;
public:
  TcpServer() = delete;

  TcpServer(TcpServer const &) = delete;

  TcpServer &operator=(TcpServer const &) = delete;

  TcpServer(DBConfig const& conf, unsigned thread_count = 1)
    : m_thread_count(thread_count),
      m_service(),
      m_acceptor(m_service),
      m_signals(m_service),
      m_dbi(std::make_shared<DBI>(connection_string(conf), conf.username, conf.password, conf.schema))
  {
    std::cout << "DB connection made, starting server...\n";
    this->m_signals.add(SIGINT);
    this->m_signals.add(SIGTERM);
#if defined(SIGQUIT)
    this->m_signals.add(SIGQUIT);
#endif
    handle_await_stop();
  }

  void run(unsigned short port)
  {
    auto handler = boost::make_shared<ConnectionHandler>(m_service, m_dbi);

    boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), port);
    m_acceptor.open(endpoint.protocol());
    m_acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
    m_acceptor.bind(endpoint);
    m_acceptor.listen();

    std::cout << "Server is now listening on port " << port << '\n';
    m_acceptor.async_accept(handler->socket(),
        [=](boost::system::error_code ec)
        {
          handle_accept(handler, ec);
        });
    for(unsigned i = 0; i < m_thread_count; ++i)
    {
      m_thread_pool.emplace_back( [=]{ m_service.run(); } );
    }
    std::for_each(m_thread_pool.begin(), m_thread_pool.end(), [](auto& t){ t.join(); });
  }

private:
  void handle_await_stop()
  {
    m_signals.async_wait(
      [this](auto const& err, auto sigNum)
      {
        std::cerr << "Signal Received: " << sigNum << ". Message: " << err.message() << '\n';
        m_acceptor.close();
      });
  }

  void handle_accept(shared_handler_t handler, boost::system::error_code const& error_code)
  {
    if(error_code) return;

    std::cout << "Handling new connection...\n";
    handler->start();

    auto new_handler = boost::make_shared<ConnectionHandler>(m_service, m_dbi);

    m_acceptor.async_accept(new_handler->socket(),
        [=](boost::system::error_code ec)
        {
          handle_accept(new_handler, ec);
        });
  }
};
} // tcpip
} // stac

max_stars_repo_name: RaVenHelm/STAC-Server

max_issues_repo_name: RaVenHelm/STAC-Server

max_forks_repo_name: RaVenHelm/STAC-Server


text:
//          Copyright Marc Bodmer 2011-2012.
// 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)

#pragma once

#include <exception>
#include <boost/exception/all.hpp>

namespace tnetstring {

struct Exception : virtual std::exception, virtual boost::exception {};

struct Parse_exception : virtual Exception {};

typedef boost::error_info<struct tag_error_msg, std::string> Error_msg_info;

typedef boost::error_info<struct tag_count, int> Count_info;

typedef boost::error_info<struct tag_size, int> Size_info;

typedef boost::error_info<struct tag_parse_pos, int> Parse_pos_info;

typedef boost::error_info<struct tag_parse_char, char> Parse_char_info;

typedef boost::error_info<struct tag_parse_value, std::string> Parse_value_info;

} // ::tnetstring

max_stars_repo_name: mbodmer/libtnetstring

max_issues_repo_name: mbodmer/libtnetstring

max_forks_repo_name: mbodmer/libtnetstring


text:
///////////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) 2008-2012  Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
//  See accompanying file COPYING.TXT file for licensing details.
//
///////////////////////////////////////////////////////////////////////////////
#include <cppcms/service.h>
#include <booster/aio/deadline_timer.h>
#include <iostream>

struct stopper {
	cppcms::service *srv;
	stopper(cppcms::service *s) : srv(s) {}
	void operator()(booster::system::error_code const &) const
	{
		srv->shutdown();
	}
};

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

	try {
		cppcms::service srv(argc,argv);

		booster::aio::deadline_timer timer(srv.get_io_service());
		timer.expires_from_now(booster::ptime::seconds(1));
		timer.async_wait(stopper(&srv));
		srv.run();
	}
	catch(std::exception const &e) {
		std::cerr<< "Failed: " << e.what() << std::endl;
		return 1;
	}
	std::cout << "Ok" << std::endl;
	return 0;
}

max_stars_repo_name: gatehouse/cppcms

max_issues_repo_name: gatehouse/cppcms

max_forks_repo_name: gatehouse/cppcms


text:
#include "counter_application.hpp"
#include <lib-tmsp/server.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/log/trivial.hpp>

int main(int argc, char const* argv[])
{
	if(argc < 3)
	{
		BOOST_LOG_TRIVIAL(info) << "Provide TMSP listening endpoint on command line. Example: 0.0.0.0 46658";
		return 1;
	}

	try
	{
		boost::asio::io_service io_service;
		tmsp::server_type const server(
			io_service,
			boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(argv[1]), std::atoi(argv[2])),
			std::make_shared<counter::application_type>()
			);

		// In this simple application, all work is scheduled on the main thread using boost asio (just below).
		// Since the application is thus protected from being re-entered, there is no need for a mutex to synchronize access.
		// It was left there as a kind reminder that synchronization must be used if the thread count ever increases.
		io_service.run();
	}

	catch(...)
	{
		BOOST_LOG_TRIVIAL(error) << boost::current_exception_diagnostic_information();
		return 2;
	}

	return 0;
}

max_stars_repo_name: block-finance/cpp-abci

max_issues_repo_name: mdyring/cpp-tmsp

max_forks_repo_name: block-finance/cpp-abci


text:
/*
 * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
 */

#include <map>
#include "net/tunnel_encap_type.h"
#include <boost/assign/list_of.hpp>

using namespace std;

TunnelEncapType::TunnelEncapType() : encap_(UNSPEC) {
}

static const std::map<string, TunnelEncapType::Encap>
    fromString = boost::assign::map_list_of
        ("unspecified", TunnelEncapType::UNSPEC)
        ("gre", TunnelEncapType::MPLS_O_GRE)
        ("udp", TunnelEncapType::MPLS_O_UDP)
        ("vxlan", TunnelEncapType::VXLAN);

static const std::map<TunnelEncapType::Encap, string>
    toString = boost::assign::map_list_of
        (TunnelEncapType::UNSPEC, "unspecified")
        (TunnelEncapType::MPLS_O_GRE, "gre")
        (TunnelEncapType::MPLS_O_UDP, "udp")
        (TunnelEncapType::VXLAN, "vxlan");

TunnelEncapType::Encap
TunnelEncapType::TunnelEncapFromString(const std::string &encap) {
    std::map<string, TunnelEncapType::Encap>::const_iterator it = fromString.find(encap);
    if (it == fromString.end()) {
        return TunnelEncapType::UNSPEC;
    } else {
        return it->second;
    }
}

const std::string &TunnelEncapType::TunnelEncapToString(TunnelEncapType::Encap encap) {
    std::map<TunnelEncapType::Encap, string>::const_iterator it = toString.find(encap);
    static string unspecified("unspecified");
    if (it == toString.end()) {
        return unspecified;
    } else {
        return it->second;
    }
}

ext: cc

max_stars_repo_name: sysbot/contrail-controller

max_issues_repo_name: sysbot/contrail-controller

max_forks_repo_name: sysbot/contrail-controller


text:
//  Copyright (c) 2005-2009 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 <boost/config.hpp>

#ifndef SAGA_AUTOLINK_LIB_NAME
#error "Macro SAGA_AUTOLINK_LIB_NAME not set (internal error)"
#endif

// enable auto-linking for supported platforms
#if defined(BOOST_MSVC) \
    || defined(__BORLANDC__) \
    || (defined(__MWERKS__) && defined(_WIN32) && (__MWERKS__ >= 0x3000)) \
    || (defined(__ICL) && defined(_MSC_EXTENSIONS) && (_MSC_VER >= 1200))

#if defined(_DEBUG)
#pragma comment(lib, SAGA_AUTOLINK_LIB_NAME "d" ".lib")
#else
#pragma comment(lib, SAGA_AUTOLINK_LIB_NAME ".lib")
#endif

#endif

#undef SAGA_AUTOLINK_LIB_NAME

max_stars_repo_name: saga-project/saga-cpp

max_issues_repo_name: saga-project/saga-cpp

max_forks_repo_name: saga-project/saga-cpp