Skip to content

Instantly share code, notes, and snippets.

@bananu7
Created January 16, 2013 10:50
Show Gist options
  • Save bananu7/4546304 to your computer and use it in GitHub Desktop.
Save bananu7/4546304 to your computer and use it in GitHub Desktop.
#include <type_traits>
#include <vector>
namespace io {
using byte = unsigned char;
using sbyte = signed char;
template<class T>
struct is_byte : std::integral_constant<bool, false> {};
template<>
struct is_byte<byte> : std::integral_constant<bool, true> {};
template<>
struct is_byte<sbyte> : std::integral_constant<bool, true> {};
class io_error : public std::runtime_error {
public:
using std::runtime_error::runtime_error;
};
class file {
public:
explicit file(std::string const& filename);
file(file&&) noexcept = default;
file& operator=(file&&) noexcept = default;
~file();
template<class T>
typename std::enable_if<is_byte<T>::value, void>::type
write(std::vector<T> const& buffer);
template<class T>
typename std::enable_if<is_byte<T>::value, void>::type
write(std::vector<T> const& buffer, std::size_t count);
template<class T>
typename std::enable_if<is_byte<T>::value, void>::type
write(T const* begin, T const* end);
template<class T>
typename std::enable_if<is_byte<T>::value, void>::type
write(T x);
template<class T>
typename std::enable_if<is_byte<T>::value, std::vector<T>>::type
read(std::size_t count);
template<class T>
typename std::enable_if<is_byte<T>::value, std::size_t>::type
read(std::vector<T>& buffer, std::size_t count);
template<class T>
typename std::enable_if<is_byte<T>::value, std::size_t>::type
read(T* begin, T* end);
template<class T>
typename std::enable_if<is_byte<T>::value, T>::type
read();
void seek_absolutely(std::size_t index);
void seek_relatively(std::size_t offset);
void seek_to_end();
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment