From 85108f09b769bb50fbdfd1686978936ff0021456 Mon Sep 17 00:00:00 2001 From: Reinhard Pfau Date: Mon, 13 Apr 2009 00:21:27 +0200 Subject: [PATCH] added class FileStat to utils (wrapper for file stat) --- utils/asyncio_system_tools.cpp | 48 +++++++++++++++++++++++++++++++++++++-- utils/asyncio_system_tools.hpp | 29 +++++++++++++++++++++++- 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/utils/asyncio_system_tools.cpp b/utils/asyncio_system_tools.cpp index a681822..48efb53 100644 --- a/utils/asyncio_system_tools.cpp +++ b/utils/asyncio_system_tools.cpp @@ -27,6 +27,8 @@ on this file might be covered by the GNU General Public License. #include "asyncio_system_tools.hpp" +#include +#include #include namespace AsyncIo @@ -34,10 +36,50 @@ namespace AsyncIo namespace Utils { - bool unlink( const std::string& path ) - { +/* + * implementation of FileStat + */ + +FileStat::FileStat( const std::string& path) +: m_path( path ) +, m_is_valid( false ) +{ + refresh(); +}// end of FileStat::FileStat() + + +FileStat::~FileStat() +{ +} // end of FileStat::~FileStat() + + +void FileStat::refresh() +{ + struct stat file_stat[1]; + + int res= ::stat( m_path.c_str(), file_stat ); + + if (res) + { + m_is_valid= false; + return; + } + + m_is_regular_file= S_ISREG(file_stat->st_mode); + m_is_directory= S_ISDIR(file_stat->st_mode); + // TODO: implement more! +} // end of FileStat::refresh() + +/* + * funcs + */ + +bool unlink( const std::string& path ) +{ return ::unlink( path.c_str() ) == 0; - } // end of unlink(const std::string&) +} // end of unlink(const std::string&) + + } // end of namespace Utils diff --git a/utils/asyncio_system_tools.hpp b/utils/asyncio_system_tools.hpp index 4094d04..bad870e 100644 --- a/utils/asyncio_system_tools.hpp +++ b/utils/asyncio_system_tools.hpp @@ -37,7 +37,34 @@ namespace AsyncIo namespace Utils { - bool unlink( const std::string& path ); +bool unlink( const std::string& path ); + + +class FileStat +{ + public: + FileStat( const std::string& path); + ~FileStat(); + + void refresh(); + + bool is_valid() const { return m_is_valid; } + + operator bool() const { return m_is_valid; } + + bool is_regular_file() const { return m_is_regular_file; } + bool is_directory() const { return m_is_directory; } + + private: + std::string m_path; + + bool m_is_valid; + + bool m_is_regular_file; + bool m_is_directory; + +}; // end of FileStat + } // end of namespace Utils }// end of namespace AsyncIo -- 1.7.1