ostream_dev.h
Go to the documentation of this file.
#ifndef __utl_dev_ostream_dev_h__
#define __utl_dev_ostream_dev_h__
#include <utl/core/impl.h>
#include <utl/core/crtp.h>
#include <utl/dev/dev_iterators.h>
#include <utl/meta/meta.h>
namespace utl {
template <typename impl_t, typename data_t>
class ostream_dev {
_CRTP_IMPL(impl_t);
using ostream_dev_t = ostream_dev <impl_t, data_t>;
public:
using data_type = data_t;
using pointer_type = data_t*;
using type = ostream_dev_t;
protected:
~ostream_dev () = default;
ostream_dev () = default;
ostream_dev(const ostream_dev_t&) = delete;
ostream_dev_t& operator= (const ostream_dev_t&) = delete;
private:
size_t put_ (const data_t& data) { return impl().put_ (data); }
size_t put_ (const data_t* data, size_t n) {
return impl().put_ (data, n);
}
public:
size_t put (const data_t& data) {
return put_ (data);
}
size_t put (const data_t* data, size_t n) {
return put_ (data, n);
}
public:
template <typename _Src_t>
ostream_dev_t& operator<< (const _Src_t& src) {
static_assert ((sizeof (_Src_t)%sizeof(data_t) == 0),
"Source size must be an integer multiple of device's data size");
put_ (reinterpret_cast<const data_t*>(&src), sizeof(_Src_t)/sizeof(data_t));
return *this;
}
template <typename _Src_t>
ostream_dev_t& operator<< (_Src_t* src) = delete;
ostream_dev_t& operator<< (const data_t& src) {
put_ (src);
return *this;
}
//ToDo: Add support for c-string, utl::string, ...
using iterator = ostreamdev_it <ostream_dev_t, data_t>;
using const_iterator = ostreamdev_it <const ostream_dev_t, data_t>;
iterator begin () noexcept { return iterator(this); }
const_iterator begin () const noexcept { return const_iterator(this); }
const_iterator cbegin () const noexcept { return const_iterator(this); }
iterator end () noexcept { return iterator(); }
const_iterator end () const noexcept { return const_iterator(); }
const_iterator cend () const noexcept { return const_iterator(); }
};
template <typename data_t>
class ostream_dev<virtual_tag, data_t> {
using ostream_dev_t = ostream_dev <virtual_tag, data_t>;
public:
using data_type = data_t;
using pointer_type = data_t*;
using type = ostream_dev_t;
public:
virtual ~ostream_dev () = default;
protected:
ostream_dev () = default;
ostream_dev(const ostream_dev_t&) = delete;
ostream_dev_t& operator= (const ostream_dev_t&) = delete;
private:
virtual size_t put_ (const data_t& data) =0;
virtual size_t put_ (const data_t* data, size_t n) =0;
public:
size_t put (const data_t& data) {
return put_ (data);
}
size_t put (const data_t* data, size_t n) {
return put_ (data, n);
}
public:
template <typename _Src_t>
ostream_dev_t& operator<< (const _Src_t& src) {
static_assert ((sizeof (_Src_t)%sizeof(data_t) == 0),
"Source size must be an integer multiple of device's data size");
put_ (reinterpret_cast<const data_t*>(&src), sizeof(_Src_t)/sizeof(data_t));
return *this;
}
template <typename _Src_t>
ostream_dev_t& operator<< (_Src_t* src) = delete;
ostream_dev_t& operator<< (const data_t& src) {
put_ (src);
return *this;
}
using iterator = ostreamdev_it <ostream_dev_t, data_t>;
using const_iterator = ostreamdev_it <const ostream_dev_t, data_t>;
iterator begin () noexcept { return iterator(this); }
const_iterator begin () const noexcept { return const_iterator(this); }
const_iterator cbegin () const noexcept { return const_iterator(this); }
iterator end () noexcept { return iterator(); }
const_iterator end () const noexcept { return const_iterator(); }
const_iterator cend () const noexcept { return const_iterator(); }
};
} //namespace utl
#endif /* #ifndef __utl_dev_out_dev_h__ */
utl::ostream_dev< virtual_tag, data_t >::cend
const_iterator cend() const noexcept
Definition: ostream_dev.h:277
utl::ostream_dev< virtual_tag, data_t >::cbegin
const_iterator cbegin() const noexcept
Definition: ostream_dev.h:272
utl::ostream_dev::iterator
ostreamdev_it< ostream_dev_t, data_t > iterator
Iterator.
Definition: ostream_dev.h:150
meta.h
Include all meta library.
utl::ostream_dev::end
const_iterator end() const noexcept
Definition: ostream_dev.h:160
utl::ostream_dev::put_
size_t put_(const data_t &data)
Definition: ostream_dev.h:77
utl::ostream_dev::~ostream_dev
~ostream_dev()=default
Allow destructor from derived only.
crtp.h
utl::ostream_dev< virtual_tag, data_t >::begin
iterator begin() noexcept
.begin implementation
Definition: ostream_dev.h:270
utl::ostream_dev< virtual_tag, data_t >::put
size_t put(const data_t *data, size_t n)
Put interface. This function should send a stream of data_t objects to device.
Definition: ostream_dev.h:225
utl::ostream_dev::ostream_dev_t
ostream_dev< impl_t, data_t > ostream_dev_t
class type syntactic sugar
Definition: ostream_dev.h:54
utl::ostream_dev::put
size_t put(const data_t *data, size_t n)
Put interface. This function should send a stream of data_t objects to device.
Definition: ostream_dev.h:108
utl::ostream_dev::pointer_type
data_t * pointer_type
Definition: ostream_dev.h:60
utl::ostream_dev< virtual_tag, data_t >::data_type
data_t data_type
Definition: ostream_dev.h:177
utl::ostream_dev
Abstract base classes for output stream devices.
Definition: ostream_dev.h:52
utl
STL&#39;s core language concepts.
Definition: _1wire.h:30
utl::ostream_dev::operator=
ostream_dev_t & operator=(const ostream_dev_t &)=delete
utl::ostream_dev::ostream_dev
ostream_dev()=default
A default constructor from derived only.
utl::ostream_dev< virtual_tag, data_t >::pointer_type
data_t * pointer_type
Definition: ostream_dev.h:178
utl::ostream_dev< virtual_tag, data_t >::end
iterator end() noexcept
Definition: ostream_dev.h:275
utl::ostream_dev< virtual_tag, data_t >
Definition: ostream_dev.h:171
utl::ostreamdev_it
Definition: dev_iterators.h:69
utl::ostream_dev::data_type
data_t data_type
Definition: ostream_dev.h:59
utl::ostream_dev::const_iterator
ostreamdev_it< const ostream_dev_t, data_t > const_iterator
Const iterator.
Definition: ostream_dev.h:151
utl::ostream_dev< virtual_tag, data_t >::begin
const_iterator begin() const noexcept
Definition: ostream_dev.h:271
dev_iterators.h
Iterator collection for devices.
utl::ostream_dev::put
size_t put(const data_t &data)
Put interface. This function should send a single data_t object to device.
Definition: ostream_dev.h:96
utl::ostream_dev::begin
iterator begin() noexcept
.begin implementation
Definition: ostream_dev.h:154
utl::ostream_dev::_CRTP_IMPL
_CRTP_IMPL(impl_t)
utl::ostream_dev::begin
const_iterator begin() const noexcept
Definition: ostream_dev.h:155
utl::virtual_tag
virtual support tag type
Definition: crtp.h:40
utl::ostream_dev::end
iterator end() noexcept
Definition: ostream_dev.h:159
utl::ostream_dev::operator<<
ostream_dev_t & operator<<(const _Src_t &src)
Template operator<< implementation for for all by value/ref parameters.
Definition: ostream_dev.h:128
utl::ostream_dev::cbegin
const_iterator cbegin() const noexcept
Definition: ostream_dev.h:156
utl::ostream_dev< virtual_tag, data_t >::end
const_iterator end() const noexcept
Definition: ostream_dev.h:276
impl.h
Implementation detail main forward header.
utl::ostream_dev< virtual_tag, data_t >::put
size_t put(const data_t &data)
Put interface. This function should send a single data_t object to device.
Definition: ostream_dev.h:213
utl::ostream_dev::cend
const_iterator cend() const noexcept
Definition: ostream_dev.h:161
utl::ostream_dev::put_
size_t put_(const data_t *data, size_t n)
Definition: ostream_dev.h:78