// \file filesystem.hpp // // Copyright (C) 2015 MicroNeil Research Corporation. // // This program is part of the MicroNeil Research Open Library Project. For // more information go to http://www.microneil.com/OpenLibrary/index.html // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the // Free Software Foundation; either version 2 of the License, or (at your // option) any later version. // // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for // more details. // // You should have received a copy of the GNU General Public License along with // this program; if not, write to the Free Software Foundation, Inc., 59 Temple // Place, Suite 330, Boston, MA 02111-1307 USA //============================================================================== /* \brief The filesystem module provides classes to access the filesystem. */ #ifndef FILESYSTEM_HPP #define FILESYSTEM_HPP #include #include namespace CodeDweller { /** Abstracts OS specifics for identifying a file and provides access to meta data. */ class FileReference { public: /** Initialize with the name of the file. @param[in] fileName is the name of the file. */ FileReference(std::string fileName); /** Return timestamp. @returns the epoch modification time for file when FileReference was created or last refreshed, or zero if the file doesn't exist. */ time_t ModTimestamp() const; /** Get the file size. @returns the size of file when FileReference was created or last refreshed, or 0 if the file doesn't exist. */ size_t Size() const; /** Get full path. @returns a fully referenced path to the file. */ std:: string FullPath() const; /** Refreshes the FileReference object with the current data on the file system. */ void refresh(); /** Check if the file exists. @returns true if the file reference name exists in the file system, false otherwise. @throws std::runtime_error if an error occurs. */ bool exists() const; /** Check if the file is a directory. @returns true if the name provided on construction resulted in finding a directory not a file, and false otherwise or if the file doesn't exist. */ bool isDirectory() const; private: /// Return text for the most recent error. // // \returns Human-readable description of the most recent error. // static std::string getErrorText(); /// Reset all members but the name and path. */ void reset(); /** Name provided to constructor. */ std::string name; /** Full path. */ std::string path; /** Timestamp. */ time_t modTimestamp; /** Size in bytes. */ long size_bytes; /** True if the file exists, false otherwise. */ bool fileExists; /** True if the file is a directory, false otherwise. */ bool fileIsDirectory; }; } #endif // FILESYSTEM_HPP