uTL
micro Template library
ostream_dev.h
Go to the documentation of this file.
1 
21 #ifndef __utl_dev_ostream_dev_h__
22 #define __utl_dev_ostream_dev_h__
23 
24 #include <utl/core/impl.h>
25 #include <utl/core/crtp.h>
26 #include <utl/dev/dev_iterators.h>
27 #include <utl/meta/meta.h>
28 
29 namespace utl {
30 
35 
51  template <typename impl_t, typename data_t>
52  class ostream_dev {
53  _CRTP_IMPL(impl_t);
55 
58  public:
59  using data_type = data_t;
60  using pointer_type = data_t*;
62  using type = ostream_dev_t;
63 
66  protected:
68  ~ostream_dev () = default;
69  ostream_dev () = default;
70  ostream_dev(const ostream_dev_t&) = delete;
71  ostream_dev_t& operator= (const ostream_dev_t&) = delete;
72 
76  private:
77  size_t put_ (const data_t& data) { return impl().put_ (data); }
78  size_t put_ (const data_t* data, size_t n) {
79  return impl().put_ (data, n);
80  }
82 
85  public:
96  size_t put (const data_t& data) {
97  return put_ (data);
98  }
99 
108  size_t put (const data_t* data, size_t n) {
109  return put_ (data, n);
110  }
112 
116  public:
127  template <typename _Src_t>
128  ostream_dev_t& operator<< (const _Src_t& src) {
129  static_assert ((sizeof (_Src_t)%sizeof(data_t) == 0),
130  "Source size must be an integer multiple of device's data size");
131  put_ (reinterpret_cast<const data_t*>(&src), sizeof(_Src_t)/sizeof(data_t));
132  return *this;
133  }
135  template <typename _Src_t>
136  ostream_dev_t& operator<< (_Src_t* src) = delete;
137 
139  ostream_dev_t& operator<< (const data_t& src) {
140  put_ (src);
141  return *this;
142  }
143  //ToDo: Add support for c-string, utl::string, ...
145 
152 
154  iterator begin () noexcept { return iterator(this); }
155  const_iterator begin () const noexcept { return const_iterator(this); }
156  const_iterator cbegin () const noexcept { return const_iterator(this); }
159  iterator end () noexcept { return iterator(); }
160  const_iterator end () const noexcept { return const_iterator(); }
161  const_iterator cend () const noexcept { return const_iterator(); }
164  };
165 
166 
167 
168 
169 
170  template <typename data_t>
171  class ostream_dev<virtual_tag, data_t> {
173 
176  public:
177  using data_type = data_t;
178  using pointer_type = data_t*;
180  using type = ostream_dev_t;
181 
184  public:
186  virtual ~ostream_dev () = default;
187  protected:
188  ostream_dev () = default;
189  ostream_dev(const ostream_dev_t&) = delete;
190  ostream_dev_t& operator= (const ostream_dev_t&) = delete;
191 
195  private:
196  virtual size_t put_ (const data_t& data) =0;
197  virtual size_t put_ (const data_t* data, size_t n) =0;
199 
202  public:
213  size_t put (const data_t& data) {
214  return put_ (data);
215  }
216 
225  size_t put (const data_t* data, size_t n) {
226  return put_ (data, n);
227  }
229 
233  public:
244  template <typename _Src_t>
245  ostream_dev_t& operator<< (const _Src_t& src) {
246  static_assert ((sizeof (_Src_t)%sizeof(data_t) == 0),
247  "Source size must be an integer multiple of device's data size");
248  put_ (reinterpret_cast<const data_t*>(&src), sizeof(_Src_t)/sizeof(data_t));
249  return *this;
250  }
252  template <typename _Src_t>
253  ostream_dev_t& operator<< (_Src_t* src) = delete;
254 
256  ostream_dev_t& operator<< (const data_t& src) {
257  put_ (src);
258  return *this;
259  }
261 
268 
270  iterator begin () noexcept { return iterator(this); }
271  const_iterator begin () const noexcept { return const_iterator(this); }
272  const_iterator cbegin () const noexcept { return const_iterator(this); }
275  iterator end () noexcept { return iterator(); }
276  const_iterator end () const noexcept { return const_iterator(); }
277  const_iterator cend () const noexcept { return const_iterator(); }
280  };
281 
282 
284 } //namespace utl
285 
286 #endif /* #ifndef __utl_dev_out_dev_h__ */
const_iterator cend() const noexcept
Definition: ostream_dev.h:277
const_iterator cbegin() const noexcept
Definition: ostream_dev.h:272
ostreamdev_it< ostream_dev_t, data_t > iterator
Iterator.
Definition: ostream_dev.h:150
Include all meta library.
const_iterator end() const noexcept
Definition: ostream_dev.h:160
size_t put_(const data_t &data)
Definition: ostream_dev.h:77
~ostream_dev()=default
Allow destructor from derived only.
iterator begin() noexcept
.begin implementation
Definition: ostream_dev.h:270
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
ostream_dev< impl_t, data_t > ostream_dev_t
class type syntactic sugar
Definition: ostream_dev.h:54
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
data_t * pointer_type
Definition: ostream_dev.h:60
Abstract base classes for output stream devices.
Definition: ostream_dev.h:52
STL&#39;s core language concepts.
Definition: _1wire.h:30
ostream_dev_t & operator=(const ostream_dev_t &)=delete
ostream_dev()=default
A default constructor from derived only.
ostreamdev_it< const ostream_dev_t, data_t > const_iterator
Const iterator.
Definition: ostream_dev.h:151
const_iterator begin() const noexcept
Definition: ostream_dev.h:271
Iterator collection for devices.
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
iterator begin() noexcept
.begin implementation
Definition: ostream_dev.h:154
const_iterator begin() const noexcept
Definition: ostream_dev.h:155
virtual support tag type
Definition: crtp.h:40
iterator end() noexcept
Definition: ostream_dev.h:159
ostream_dev_t & operator<<(const _Src_t &src)
Template operator<< implementation for for all by value/ref parameters.
Definition: ostream_dev.h:128
const_iterator cbegin() const noexcept
Definition: ostream_dev.h:156
const_iterator end() const noexcept
Definition: ostream_dev.h:276
Implementation detail main forward header.
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
const_iterator cend() const noexcept
Definition: ostream_dev.h:161
size_t put_(const data_t *data, size_t n)
Definition: ostream_dev.h:78