Support Class Library
A set of tools providing classes and utility
istream.h
Go to the documentation of this file.
1 #pragma once
2 #include <iostream>
3 #include <string>
4 #include <scl/stream/Stream.h>
7 
8 namespace scl{
9  namespace stream{
10  namespace creators{
11  namespace details{
18  template <class Char = char, class Traits = std::char_traits<Char>>
19  struct ByLine : public std::basic_string<Char, Traits>{
20  using stream_type = std::basic_istream<Char, Traits>;
21  using string_type = std::basic_string<Char, Traits>;
22 
23  using std::basic_string<Char, Traits>::basic_string;
24 
25  inline friend stream_type& operator>>(stream_type& is, ByLine& line){
26  std::getline(is, line);
27  return is;
28  }
29  };
30 
36  template <class Char = char, class Traits = std::char_traits<Char>>
37  struct ByLineIterator : public std::istream_iterator<ByLine<Char, Traits>>{
38  using std::istream_iterator<ByLine<Char, Traits>>::istream_iterator;
39 
41  };
42  }
43 
51  template <class Char = char, class Traits = std::char_traits<Char>>
52  Stream<std::basic_string<Char, Traits>> streamFrom(std::basic_istream<Char, Traits>& inputStream){
53  using iterator_t = details::ByLineIterator<Char, Traits>;
54  return streamFrom(iterator_t{inputStream}, iterator_t{});
55  }
56  }
57  }
58 }
Global namespace of the SCL.
Definition: alias.hpp:3
friend stream_type & operator>>(stream_type &is, ByLine &line)
Definition: istream.h:25
Class that exposes custom logic for reading a file line by line for use with std::istream_iterator.
Definition: istream.h:19
istream iterator for reading line by line with conversion to std::basic_string
Definition: istream.h:37
Stream< T > streamFrom(std::array< T, N > a)
Create an scl::stream::Stream from a std::array.
Definition: array.h:71
typename ByLine< Char, Traits >::string_type value_type
Definition: istream.h:40
std::basic_istream< Char, Traits > stream_type
Definition: istream.h:20
std::basic_string< Char, Traits > string_type
Definition: istream.h:21
Class representing a stream of data.
Definition: Stream.h:15