77 lines
2.2 KiB
C++
77 lines
2.2 KiB
C++
/**
|
|
This file is a part of rexy's general purpose library
|
|
Copyright (C) 2020 rexy712
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef REXY_FILERD_HPP
|
|
#define REXY_FILERD_HPP
|
|
|
|
#include <cstdio> //FILE
|
|
#include <cstddef> //size_t
|
|
#include <type_traits> //is_nothrow_constructible
|
|
|
|
#include "string.hpp"
|
|
#include "steal.hpp"
|
|
#include "binary.hpp"
|
|
#include "utility.hpp"
|
|
#include "rexy.hpp"
|
|
|
|
namespace rexy{
|
|
|
|
//RAII wrapper for FILE*
|
|
class filerd
|
|
{
|
|
private:
|
|
FILE* m_fp = nullptr;
|
|
|
|
public:
|
|
constexpr filerd(void)noexcept = default;
|
|
filerd(const char* f, const char* mode = "r")noexcept;
|
|
filerd(const filerd&) = delete;
|
|
constexpr filerd(filerd&& f)noexcept:
|
|
m_fp(exchange(f.m_fp, nullptr)){}
|
|
~filerd(void)noexcept;
|
|
filerd& operator=(const filerd&) = delete;
|
|
constexpr filerd& operator=(filerd&& f)noexcept{
|
|
swap(m_fp, f.m_fp);
|
|
return *this;
|
|
}
|
|
|
|
void reset(FILE* fp = nullptr)noexcept;
|
|
FILE* release(void)noexcept;
|
|
size_t length(void)noexcept;
|
|
size_t position(void)const noexcept;
|
|
void rewind(size_t pos = 0)noexcept;
|
|
|
|
operator FILE*(void)noexcept;
|
|
operator const FILE*(void)const noexcept;
|
|
FILE* get(void)noexcept;
|
|
const FILE* get(void)const noexcept;
|
|
operator bool(void)const noexcept;
|
|
|
|
size_t read(char* dest, size_t bytes)noexcept;
|
|
rexy::string read(size_t bytes)noexcept;
|
|
rexy::string readln(size_t max = 0)noexcept;
|
|
rexy::binary read_bin(size_t bytes)noexcept(std::is_nothrow_constructible<rexy::binary, rexy::steal<char*>, size_t, size_t>::value);
|
|
|
|
size_t write(const char* c, size_t bytes)noexcept;
|
|
size_t write(const rexy::string_base<char>& s)noexcept;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|