Move io functions into the util namespace

This commit is contained in:
Danny Robson 2011-10-01 01:58:10 +10:00
parent 6b0db35db7
commit f02501eb5e
3 changed files with 43 additions and 39 deletions

3
io.cpp
View File

@ -11,10 +11,11 @@
using namespace std; using namespace std;
using namespace util;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
uint8_t * uint8_t *
slurp (const boost::filesystem::path& path) { util::slurp (const boost::filesystem::path& path) {
fd_ref fd(open (path.string ().c_str (), O_RDONLY)); // | O_CLOEXEC)); fd_ref fd(open (path.string ().c_str (), O_RDONLY)); // | O_CLOEXEC));
// Calculate the total file size // Calculate the total file size

32
io.hpp
View File

@ -25,23 +25,25 @@
#include <cstdio> #include <cstdio>
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
#include <boost/filesystem.hpp> #include <boost/filesystem/path.hpp>
/// Specifies bitwise combinations of IO access rights.
enum access_t { namespace util {
/// Specifies bitwise combinations of IO access rights.
enum access_t {
ACCESS_READ = 1 << 0, ACCESS_READ = 1 << 0,
ACCESS_WRITE = 1 << 1, ACCESS_WRITE = 1 << 1,
ACCESS_READWRITE = ACCESS_READ | ACCESS_WRITE ACCESS_READWRITE = ACCESS_READ | ACCESS_WRITE
}; };
/// Reads an entire file into memory. Caller frees the result. Guarantees a /// Reads an entire file into memory. Caller frees the result. Guarantees a
/// null trailing byte. /// null trailing byte.
uint8_t * uint8_t *
slurp (const boost::filesystem::path&) mustuse; slurp (const boost::filesystem::path&) mustuse;
/// A simple RAII wrapper for file descriptors /// A simple RAII wrapper for file descriptors
struct fd_ref { struct fd_ref {
public: public:
int fd; int fd;
@ -49,12 +51,12 @@ struct fd_ref {
~fd_ref (); ~fd_ref ();
operator int (void) const; operator int (void) const;
}; };
#if defined(HAVE_MMAP) #if defined(HAVE_MMAP)
/// Wraps a mechanism to map a file into memory. Read only. /// Wraps a mechanism to map a file into memory. Read only.
class mapped_file { class mapped_file {
protected: protected:
fd_ref m_fd; fd_ref m_fd;
uint8_t *m_data; uint8_t *m_data;
@ -74,8 +76,8 @@ class mapped_file {
const uint8_t* data (void) const; const uint8_t* data (void) const;
size_t size (void) const; size_t size (void) const;
}; };
#endif #endif
}
#endif #endif

View File

@ -36,6 +36,7 @@
using namespace std; using namespace std;
using namespace util;
/* /*
* Parsing * Parsing