staticlib_io  1.2.11
 All Classes Namespaces Files Functions Variables
source_istream.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016, alex at staticlibs.net
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /*
18  * File: source_istream.hpp
19  * Author: alex
20  *
21  * Created on April 15, 2016, 10:30 AM
22  */
23 
24 #ifndef STATICLIB_IO_SOURCE_ISTREAM_HPP
25 #define STATICLIB_IO_SOURCE_ISTREAM_HPP
26 
27 #include <ios>
28 #include <istream>
29 #include <memory>
30 
33 #include "staticlib/io/span.hpp"
34 
35 namespace staticlib {
36 namespace io {
37 
43 template <typename Source>
44 class source_istream : public std::istream {
49 
50 public:
51 
57  explicit source_istream(Source&& source) :
58  std::istream(std::addressof(streambuf)),
59  streambuf(std::move(source)) { }
60 
66  source_istream(const source_istream&) = delete;
67 
74  source_istream& operator=(const source_istream&) = delete;
75 
81  source_istream(source_istream&&) = delete;
82 
90 
91 };
92 
100 template <typename Source,
101  class = typename std::enable_if<!std::is_lvalue_reference<Source>::value>::type>
102 std::unique_ptr<std::istream> make_source_istream_ptr(Source&& source) {
103  return std::unique_ptr<std::istream>(new source_istream<Source>(std::move(source)));
104 }
105 
113 template <typename Source>
114 std::unique_ptr<std::istream> make_source_istream_ptr(Source& source) {
115  return std::unique_ptr<std::istream>(new source_istream<reference_source<Source>>(make_reference_source(source)));
116 }
117 
118 } // namespace
119 }
120 
121 #endif /* STATICLIB_IO_SOURCE_ISTREAM_HPP */
122