added class FileStat to utils (wrapper for file stat)
authorReinhard Pfau <Reinhard.Pfau@gmx.de>
Sun, 12 Apr 2009 22:21:27 +0000 (00:21 +0200)
committerReinhard Pfau <Reinhard.Pfau@gmx.de>
Sun, 12 Apr 2009 22:21:27 +0000 (00:21 +0200)
utils/asyncio_system_tools.cpp
utils/asyncio_system_tools.hpp

index a681822..48efb53 100644 (file)
@@ -27,6 +27,8 @@ on this file might be covered by the GNU General Public License.
 
 #include "asyncio_system_tools.hpp"
 
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <unistd.h>
 
 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
index 4094d04..bad870e 100644 (file)
@@ -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