IOLink  IOL_v1.1.0_release
StreamAccessFactory.h
1 #pragma once
2 
3 #include <iolink/IOLinkAPI.h>
4 #include <iolink/Uri.h>
5 #include <iolink/storage/HTTPHeaders.h>
6 #include <iolink/storage/RandomAccess.h>
7 #include <iolink/storage/StreamAccess.h>
8 
9 #include <iostream>
10 #include <map>
11 #include <memory>
12 
13 namespace iolink
14 {
15 
19 class IOLINK_API StreamAccessFactory
20 {
21 public:
22  StreamAccessFactory() = delete;
23  StreamAccessFactory(const StreamAccessFactory& other) = delete; // copy constructor
24  StreamAccessFactory(StreamAccessFactory&& other) = delete; // move constructor
25  StreamAccessFactory& operator=(const StreamAccessFactory& other) = delete; // copy assignment
26  StreamAccessFactory& operator=(StreamAccessFactory&& other) = delete; // move assignment
27 
33  static std::shared_ptr<StreamAccess> allocate(size_t size = 0);
34 
41  static std::shared_ptr<StreamAccess> copyInMemory(std::shared_ptr<StreamAccess> streamAccess);
42 
48  static std::shared_ptr<StreamAccess> fromStdStream(std::shared_ptr<std::istream> stream);
49 
55  static std::shared_ptr<StreamAccess> fromStdStream(std::shared_ptr<std::ostream> stream);
56 
62  static std::shared_ptr<StreamAccess> fromStdStream(std::shared_ptr<std::iostream> stream);
63 
69  static std::shared_ptr<std::istream> toStdIStream(std::shared_ptr<StreamAccess> streamAccess);
70 
76  static std::shared_ptr<std::ostream> toStdOStream(std::shared_ptr<StreamAccess> streamAccess);
77 
84  static std::shared_ptr<std::iostream> toStdStream(std::shared_ptr<StreamAccess> streamAccess);
85 
91  static std::shared_ptr<StreamAccess> openFileRead(const std::string& filePath);
92 
98  static std::shared_ptr<StreamAccess> openFileWrite(const std::string& filePath);
99 
106  static std::shared_ptr<StreamAccess> openFile(const std::string& filePath);
107 
116  static std::shared_ptr<StreamAccess> openURIWrite(const Uri& uri);
117 
127  static std::shared_ptr<StreamAccess> openHTTPWrite(const Uri& uri,
128  const std::string& method,
129  const HTTPHeaders& headers);
130 
137  static std::shared_ptr<StreamAccess> fromRandomAccess(std::shared_ptr<RandomAccess> randomAccess);
138 };
139 
140 } // end namespace iolink