Skip to content

Commit

Permalink
Add is_open method to raw accessors, and typedef a default raw accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
antialize committed Dec 7, 2012
1 parent 91b940b commit 45d1c1c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tpie/file_accessor/file_accessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <tpie/file_accessor/win32.h>
namespace tpie {
namespace file_accessor {
typedef win32 raw_file_accessor;
typedef stream_accessor<win32> file_accessor;
}
}
Expand All @@ -39,13 +40,15 @@ typedef stream_accessor<win32> file_accessor;
#include <tpie/file_accessor/posix.h>
namespace tpie {
namespace file_accessor {
typedef posix raw_file_accessor;
typedef stream_accessor<posix> file_accessor;
}
}

#endif // WIN32

namespace tpie {
typedef file_accessor::raw_file_accessor default_raw_file_accessor;
typedef file_accessor::file_accessor default_file_accessor;
} // namespace tpie

Expand Down
1 change: 1 addition & 0 deletions tpie/file_accessor/posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class posix {
inline void seek_i(stream_size_type offset);
inline void close_i();
inline void truncate_i(stream_size_type bytes);
inline bool is_open() const;

///////////////////////////////////////////////////////////////////////////
/// \brief Check the global errno variable and throw an exception that
Expand Down
4 changes: 4 additions & 0 deletions tpie/file_accessor/posix.inl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ void posix::open_rw_new(const std::string & path) {
::posix_fadvise(m_fd, 0, 0, m_advice);
}

bool posix::is_open() const {
return m_fd != 0;
}

void posix::close_i() {
if (m_fd != 0) {
::close(m_fd);
Expand Down
1 change: 1 addition & 0 deletions tpie/file_accessor/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class win32 {
inline void seek_i(stream_size_type offset);
inline void close_i();
inline void truncate_i(stream_size_type bytes);
inline bool is_open() const;

inline void set_cache_hint(cache_hint cacheHint);
};
Expand Down
4 changes: 4 additions & 0 deletions tpie/file_accessor/win32.inl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ void win32::open_rw_new(const std::string & path) {
if (m_fd == INVALID_HANDLE_VALUE) throw_getlasterror();
}

bool win32::is_open() const {
return m_fd != INVALID_HANDLE_VALUE;
}

void win32::close_i() {
if (m_fd != INVALID_HANDLE_VALUE) {
CloseHandle(m_fd);
Expand Down

0 comments on commit 45d1c1c

Please sign in to comment.