Thoth
A functional, expressive, asynchronous C++26 webdev library
Loading...
Searching...
No Matches
FileOutputRange.hpp
Go to the documentation of this file.
1#pragma once
2#include <Hermes/Socket/_base/_base.hpp>
3#include <filesystem>
4#include <fstream>
5
6namespace Thoth::Dsa {
8 std::filesystem::path path;
9 std::optional<vector<Http::NHeaders::MimeType>> acceptedTypes{};
10 int maxSize{ INT_MAX };
11 int mode{};
12 };
13
14 template <Hermes::ByteLike T = char>
16
17 using value_type = T;
18 using BodyType = std::expected<FileOutputRange, Http::RequestError>;
19
20 static constexpr auto H_AsBody(const FileBuilderParams& params);
21 static constexpr auto H_AsBody(FileBuilderParams&& params);
22
23 static constexpr int Mode();
24
25 // change later to ensure that path is a regular file
26 explicit FileOutputRange(const std::filesystem::path& path, int mode = 0);
27 explicit FileOutputRange(std::filesystem::path&& path, int mode = 0);
28
29 explicit FileOutputRange(std::basic_ofstream<T>&& file);
30
32 FileOutputRange(const FileOutputRange& other) = delete;
33
35 FileOutputRange& operator=(const FileOutputRange& other) = delete;
36
37 constexpr bool operator==(const FileOutputRange& other) const = default;
38
39 [[nodiscard]] std::ostream_iterator<T, T> begin();
40
41 [[nodiscard]] static std::unreachable_sentinel_t end();
42
43 private:
44 std::basic_ofstream<T> _outStream;
45 };
46
49
50
51 static_assert(std::ranges::range<TextFileOutputRange>);
52}
53
54#include <Thoth/Dsa/FileOutputRange.tpp>
Definition Cow.hpp:5
Definition FileOutputRange.hpp:7
std::filesystem::path path
Definition FileOutputRange.hpp:8
int maxSize
Definition FileOutputRange.hpp:10
int mode
Definition FileOutputRange.hpp:11
std::optional< vector< Http::NHeaders::MimeType > > acceptedTypes
Definition FileOutputRange.hpp:9
Definition FileOutputRange.hpp:15
FileOutputRange & operator=(const FileOutputRange &other)=delete
FileOutputRange(std::filesystem::path &&path, int mode=0)
static constexpr auto H_AsBody(FileBuilderParams &&params)
constexpr bool operator==(const FileOutputRange &other) const =default
std::ostream_iterator< T, T > begin()
FileOutputRange(std::basic_ofstream< T > &&file)
static std::unreachable_sentinel_t end()
FileOutputRange(FileOutputRange &&other) noexcept
std::expected< FileOutputRange, Http::RequestError > BodyType
Definition FileOutputRange.hpp:18
static constexpr int Mode()
T value_type
Definition FileOutputRange.hpp:17
static constexpr auto H_AsBody(const FileBuilderParams &params)
FileOutputRange & operator=(FileOutputRange &&other) noexcept
FileOutputRange(const FileOutputRange &other)=delete
FileOutputRange(const std::filesystem::path &path, int mode=0)