Commit 492bfe23 authored by Armin Sobhani's avatar Armin Sobhani
Browse files

change to use boost::container for sc example

parent 3327e957
......@@ -9,7 +9,7 @@
include_directories(../include)
set(BOOST_COMPONENTS system program_options iostreams)
set(BOOST_COMPONENTS system program_options iostreams container)
if(BOOST_COMPONENTS)
list(REMOVE_DUPLICATES BOOST_COMPONENTS)
......
......@@ -21,6 +21,8 @@
# include <unistd.h>
#endif //_WIN32
#include <boost/container/vector.hpp>
#include <boost/container/allocator.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
......@@ -39,14 +41,16 @@
namespace bsq = boost::bioseq;
namespace bio = boost::iostreams;
namespace bc = boost::container;
typedef bsq::sequence_host
<
char
, std::allocator
, std::vector
, bsq::component::name<>
, bsq::component::description<>
// , bsq::no_init_alloc<char>
, bc::allocator<char>
, bc::vector
// , bsq::component::name<>
// , bsq::component::description<>
> seq;
typedef bsq::ioformat
......@@ -81,7 +85,7 @@ int main(int argc, char *argv[])
{
for (size_t i = 1; i < argc; ++i)
{
std::ifstream is(argv[i]);
// std::ifstream is(argv[i]);
// std::ifstream is;
// char buffer[16384];
// is.sync_with_stdio(false);
......@@ -98,8 +102,8 @@ int main(int argc, char *argv[])
// bio::file_source f{argv[i]};
// bio::stream<bio::file_source> is{f};
// bio::mapped_file_source f{argv[i]};
// bio::stream<bio::mapped_file_source> is{f};
bio::mapped_file_source f{argv[i]};
bio::stream<bio::mapped_file_source> is{f};
// bio::filtering_istream fs(in, 16384);
// bio::gzip_decompressor filter;
......
......@@ -61,6 +61,12 @@ private:
virtual void do_scan(std::basic_istream<CharT,Traits>& in, SeqT& s)
{
// CharT t = in.rdbuf()->sbumpc();
// while (in.rdbuf()->sbumpc() != Traits::eof())
// ;
// in.setstate(std::ios::failbit);
// return;
bool nws[] =
{
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
......@@ -95,21 +101,27 @@ private:
line.insert(line.begin(), &data[start_offset + 1], first_line);
auto next = std::find(first_line, &data[size], 0x3E);
SeqT t;
// SeqT t;
// SeqT t(next - first_line);
t.reserve(next - first_line);
s.clear();
s.resize(std::distance(first_line, next), boost::container::default_init);
auto not_ws = [&nws](CharT c) { return nws[c]; };
std::copy_if(first_line, next, std::back_inserter(t), not_ws);
auto last = std::copy_if(first_line, next, s.data(), not_ws);
s.resize(std::distance(s.data(), last), boost::container::default_init);
// s.reserve(next - first_line);
// auto not_ws = [&nws](CharT c) { return nws[c]; };
// std::copy_if(first_line, next, std::back_inserter(s), not_ws);
// std::copy_n(first_line, next - first_line, std::back_inserter(t));
// auto rng = boost::make_iterator_range(first_line, next);
// boost::insert(t, t.begin(), rng
// | boost::adaptors::filtered(std::ref(not_ws)));
// std::memcpy(t.data(), first_line, next - first_line);
scan_name(line, t, has_name_component<SeqT>());
scan_description(line, t, has_description_component<SeqT>());
// scan_name(line, s, has_name_component<SeqT>());
// scan_description(line, s, has_description_component<SeqT>());
s = std::move(t);
// s = std::move(t);
// s = t;
in.seekg(next - &data[start_offset], std::ios_base::cur);
}
......
......@@ -22,15 +22,27 @@ namespace bioseq {
//----------------------------------------------------------------------------//
// template <class T>
// class no_init_alloc
// : public boost::container::allocator<T>
// {
// public:
// using boost::container::allocator<T>::allocator;
// template <class U, class... Args> void construct(U*, Args&&...) {}
// };
//----------------------------------------------------------------------------//
template
<
class CharT
, template <class> class AllocatorT
, class AllocatorT
, template <class,class> class ContainerT
, class ...ComponentT
>
class sequence_host
: public ContainerT<CharT, AllocatorT<CharT>>
: public ContainerT<CharT, AllocatorT>
, public ComponentT...
{
public:
......@@ -38,22 +50,20 @@ public:
self_type;
sequence_host()
: ContainerT<CharT, AllocatorT<CharT>>()
{}
: ContainerT<CharT, AllocatorT>()
{
// std::cout << "default constructor called" << std::endl;
}
explicit sequence_host(
const AllocatorT<CharT>& alloc)
: ContainerT<CharT, AllocatorT<CharT>>(alloc)
{}
explicit sequence_host(size_t count)
: ContainerT<CharT, AllocatorT<CharT>>(count)
const AllocatorT& alloc)
: ContainerT<CharT, AllocatorT>(alloc)
{}
sequence_host(
const CharT* s
, size_t count)
: ContainerT<CharT, AllocatorT<CharT>>()
: ContainerT<CharT, AllocatorT>()
{
self_type::insert(self_type::begin(), s, s + count);
}
......@@ -61,15 +71,15 @@ public:
sequence_host(
const CharT* s
, size_t count
, const AllocatorT<CharT>& alloc)
: ContainerT<CharT, AllocatorT<CharT>>(alloc)
, const AllocatorT& alloc)
: ContainerT<CharT, AllocatorT>(alloc)
{
self_type::insert(self_type::begin(), s, s + count);
}
sequence_host(
const CharT* s)
: ContainerT<CharT, AllocatorT<CharT>>()
: ContainerT<CharT, AllocatorT>()
{
size_t count = std::char_traits<CharT>::length(s);
self_type::insert(self_type::begin(), s, s + count);
......@@ -77,17 +87,25 @@ public:
sequence_host(
const CharT* s
, const AllocatorT<CharT>& alloc)
: ContainerT<CharT, AllocatorT<CharT>>(alloc)
, const AllocatorT& alloc)
: ContainerT<CharT, AllocatorT>(alloc)
{
size_t count = std::char_traits<CharT>::length(s);
self_type::insert(self_type::begin(), s, s + count);
}
template< class InputIt >
sequence_host(
InputIt first
, InputIt last
, const AllocatorT& alloc = AllocatorT() )
: ContainerT<CharT, AllocatorT>(first, last, alloc)
{}
sequence_host(
const sequence_host& other
, const AllocatorT<CharT>& alloc = AllocatorT<CharT>() )
: ContainerT<CharT, AllocatorT<CharT>>(other)
, const AllocatorT& alloc = AllocatorT() )
: ContainerT<CharT, AllocatorT>(other)
{
// std::cout << "copy called" << std::endl;
copy_name(other, has_name_component<self_type>());
......@@ -96,8 +114,8 @@ public:
sequence_host(
sequence_host&& other
, const AllocatorT<CharT>& alloc = AllocatorT<CharT>() )
: ContainerT<CharT, AllocatorT<CharT>>(std::forward<sequence_host>(other))
, const AllocatorT& alloc = AllocatorT() )
: ContainerT<CharT, AllocatorT>(std::forward<sequence_host>(other))
{
// std::cout << "move called" << std::endl;
move_name(
......@@ -110,24 +128,27 @@ public:
sequence_host(
std::initializer_list<CharT> init
, const AllocatorT<CharT>& alloc = AllocatorT<CharT>() )
: ContainerT<CharT, AllocatorT<CharT>>(init, alloc)
, const AllocatorT& alloc = AllocatorT() )
: ContainerT<CharT, AllocatorT>(init, alloc)
{}
sequence_host& operator= (const sequence_host& other)
{
// std::cout << "copy assignment operator called" << std::endl;
self_type::clear();
self_type::insert(self_type::begin(), other.cbegin(), other.cend());
ContainerT<CharT, AllocatorT>::operator=(other);
// self_type::clear();
// self_type::insert(self_type::begin(), other.cbegin(), other.cend());
copy_name(other, has_name_component<self_type>());
copy_dscr(other, has_description_component<self_type>());
return *this;
}
sequence_host& operator= (sequence_host&& other)
sequence_host& operator= (sequence_host&& other) noexcept
{
// std::cout << "move assignment operator called" << std::endl;
self_type::swap(other);
ContainerT<CharT, AllocatorT>::operator=(std::forward<sequence_host>(other));
// ContainerT<CharT, AllocatorT>::operator=(other);
// self_type::swap(other);
move_name(
std::forward<sequence_host>(other)
, has_name_component<self_type>() );
......@@ -203,7 +224,7 @@ template
<
class CharT
, class Traits
, template <class> class AllocatorT
, class AllocatorT
, template <class,class> class ContainerT
, class ...ComponentT
> inline
......@@ -223,7 +244,7 @@ template
<
class CharT
, class Traits
, template <class> class AllocatorT
, class AllocatorT
, template <class,class> class ContainerT
, class ...ComponentT
> inline
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment