staticlib_io  1.2.11
 All Classes Namespaces Files Functions Variables
shared_source.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015, 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: shared_source.hpp
19  * Author: alex
20  *
21  * Created on October 9, 2015, 12:41 PM
22  */
23 
24 #ifndef STATICLIB_IO_SHARED_SOURCE_HPP
25 #define STATICLIB_IO_SHARED_SOURCE_HPP
26 
27 #include <ios>
28 #include <memory>
29 
30 #include "staticlib/config.hpp"
31 
32 #include "staticlib/io/span.hpp"
33 
34 namespace staticlib {
35 namespace io {
36 
40 template <typename Source>
45  std::shared_ptr<Source> src;
46 
47 public:
53  shared_source(std::shared_ptr<Source> src) :
54  src(std::move(src)) { }
55 
61  shared_source(const shared_source& other) :
62  src(other.src) { }
63 
71  src = other.src;
72  return *this;
73  }
74 
80  shared_source(shared_source&& other) STATICLIB_NOEXCEPT :
81  src(std::move(other.src)) { }
82 
89  shared_source& operator=(shared_source&& other) STATICLIB_NOEXCEPT {
90  src = std::move(other.src);
91  return *this;
92  }
93 
100  std::streamsize read(span<char> span) {
101  return src->read(span);
102  }
103 
109  Source& get_source() {
110  return *src;
111  }
112 
113 };
114 
121 template <typename Source>
122 shared_source<Source> make_shared_source(std::shared_ptr<Source> source) {
123  return shared_source<Source>(std::move(source));
124 }
125 
126 } // namespace
127 }
128 
129 #endif /* STATICLIB_IO_SHARED_SOURCE_HPP */
130