C++ Essence Library 0.1.0
A Utility Library for Modern C++ Programming
Loading...
Searching...
No Matches
ostream.hpp
1/*
2 * Copyright (c) 2024 The RefValue Project
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include "../compat.hpp"
26#include "abstract/chunk_processor.hpp"
27
28#include <istream>
29#include <memory>
30#include <string_view>
31
32namespace essence::crypto {
36 class ostream : public std::ostream {
37 public:
41 ES_API(CPPESSENCE) ostream();
42
43
49 ES_API(CPPESSENCE) ostream(std::shared_ptr<std::ostream> output_stream, abstract::chunk_processor processor);
50
51
58 ES_API(CPPESSENCE)
59 ostream(std::string_view path, abstract::chunk_processor processor, openmode mode = out | binary);
60
61 ostream(const ostream&) = delete;
62 ostream(ostream&&) noexcept = delete;
63 ES_API(CPPESSENCE) ~ostream() override;
64 ostream& operator=(const ostream&) = delete;
65 ostream& operator=(ostream&&) noexcept = delete;
66
71 [[nodiscard]] ES_API(CPPESSENCE) bool is_open() const noexcept;
72
78 ES_API(CPPESSENCE)
79 void open(std::shared_ptr<std::ostream> output_stream, abstract::chunk_processor processor);
80
87 ES_API(CPPESSENCE)
88 void open(std::string_view path, abstract::chunk_processor processor, openmode mode = out | binary);
89
93 ES_API(CPPESSENCE) void close() const;
94
95 private:
96 void* opaque_;
97 };
98} // namespace essence::crypto
Provides a uniform interface for processing crypto chunks.
Definition chunk_processor.hpp:40
An output stream to transform input data by using a chunk processor(i.e. a chunk encryptor).
Definition ostream.hpp:36
ES_API(CPPESSENCE) ostream()
Creates an empty instance, of which the initialization is delayed when the open function is called.
ES_API(CPPESSENCE) ostream(std ostream(std::string_view path, abstract::chunk_processor processor, openmode mode=out|binary)
Creates an instance.
void open(std::shared_ptr< std::ostream > output_stream, abstract::chunk_processor processor)
Resets all internal states and opens a new output stream to write the transformed data.