17 #ifndef COM_BORA_SOFTWARE__BALAU_UTIL__FILES 18 #define COM_BORA_SOFTWARE__BALAU_UTIL__FILES 22 #include <boost/iostreams/filtering_streambuf.hpp> 23 #include <boost/iostreams/copy.hpp> 24 #include <boost/iostreams/filter/gzip.hpp> 30 template <>
struct hash<
boost::filesystem::directory_entry> {
31 size_t operator () (
const boost::filesystem::directory_entry & value)
const noexcept {
32 return hash<boost::filesystem::path::string_type>()(value.path().native());
36 template <>
struct equal_to<
boost::filesystem::directory_entry> {
37 bool operator () (
const boost::filesystem::directory_entry & x,
38 const boost::filesystem::directory_entry & y)
const {
52 template <
typename AllocatorT>
54 return toString<AllocatorT>(path.string());
62 inline std::string toString(
const boost::filesystem::path & path) {
95 boost::filesystem::ifstream inputStream(file.
getEntry());
96 std::vector<std::string> lines;
99 while (std::getline(inputStream, s)){
116 boost::filesystem::ifstream inputStream(file.
getEntry());
117 std::istreambuf_iterator<char> eos;
118 return std::string(std::istreambuf_iterator<char>(inputStream), eos);
131 boost::filesystem::ifstream inputStream(file.
getEntry());
132 std::istreambuf_iterator<char> eos;
133 return std::vector<char>(std::istreambuf_iterator<char>(inputStream), eos);
145 #endif // COM_BORA_SOFTWARE__BALAU_UTIL__FILES static std::string readToString(const Resource::File &file)
Read the specified file into a string.
Definition: Files.hpp:111
static std::vector< std::string > toLines(const Resource::File &file)
Read all lines of text of the specified file into a string vector.
Definition: Files.hpp:90
Definition: NetworkTypes.hpp:39
#define ThrowBalauException(ExceptionClass,...)
Throw a Balau style exception, with implicit file and line number, and optional stacktrace.
Definition: BalauException.hpp:45
boost::filesystem::directory_entry getEntry() const
Get the underlying directory entry for this file URI.
Definition: File.hpp:400
static void copy(const Resource::File &src, const Resource::File &dst)
Copy the contents of the source file into the destination file.
Definition: Files.hpp:79
A file on the local file system.
Definition: File.hpp:35
static std::vector< char > readToVector(const Resource::File &file)
Read the specified file into a character vector.
Definition: Files.hpp:126
Balau exceptions for resources.
Thrown when a resource is not found.
Definition: ResourceExceptions.hpp:63
std::basic_string< char, std::char_traits< char >, AllocatorT > U8String
UTF-8 string type with selectable allocator.
Definition: ToStringA.hpp:41
File utilities.
Definition: Files.hpp:73
bool exists() const
Returns true if an item exits in the file system for the file URI.
Definition: File.hpp:449