zipios 2.2.0
Zipios -- a small C++ library that provides easy access to .zip files.
filepath.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef ZIPIOS_FILEPATH_HPP
3#define ZIPIOS_FILEPATH_HPP
4
5/*
6 Zipios -- a small C++ library that provides easy access to .zip files.
7
8 Copyright (C) 2000-2007 Thomas Sondergaard
9 Copyright (C) 2015-2019 Made to Order Software Corporation
10
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 2.1 of the License, or (at your option) any later version.
15
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
20
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
35
37
38#include <ctime>
39#include <string>
40
41
42namespace zipios
43{
44
45
47{
48public:
49 FilePath(std::string const& path = "");
50
51 operator std::string () const;
52 FilePath& operator = (std::string const& path);
53 FilePath operator + (FilePath const& name) const;
54 bool operator == (char const *rhs) const;
55 friend bool operator == (char const *lhs, FilePath const& rhs);
56 bool operator == (std::string const& rhs) const;
57 friend bool operator == (std::string const& lhs, FilePath const& rhs);
58 bool operator == (FilePath const& rhs) const;
59 // TBD: add all the other comparison operators for completeness
60 std::string filename() const;
61 size_t length() const;
62 size_t size() const;
63 bool exists() const;
64 bool isRegular() const;
65 bool isDirectory() const;
66 bool isCharSpecial() const;
67 bool isBlockSpecial() const;
68 bool isSocket() const;
69 bool isFifo() const;
70 size_t fileSize() const;
71 std::time_t lastModificationTime() const;
72
73private:
74 void check() const;
75
76 std::string m_path;
78 mutable bool m_checked = false;
79 mutable bool m_exists = false;
80};
81
82
83std::ostream& operator << (std::ostream& os, FilePath const& path);
84
85
86} // zipios namespace
87
88// Local Variables:
89// mode: cpp
90// indent-tabs-mode: nil
91// c-basic-offset: 4
92// tab-width: 4
93// End:
94
95// vim: ts=4 sw=4 et
96#endif
Handle a file path and name and its statistics.
Definition filepath.hpp:47
bool isFifo() const
Check whether the file is a pipe.
Definition filepath.cpp:444
void check() const
Read the file mode.
Definition filepath.cpp:124
FilePath operator+(FilePath const &name) const
Append the a child name to this path.
Definition filepath.cpp:187
bool isCharSpecial() const
Check whether the file is a character special file.
Definition filepath.cpp:402
bool isBlockSpecial() const
Check whether the file is a block special file.
Definition filepath.cpp:416
std::string m_path
Definition filepath.hpp:76
bool operator==(char const *rhs) const
Check whether two FilePath represent the same file.
Definition filepath.cpp:219
os_stat_t m_stat
Definition filepath.hpp:77
FilePath(std::string const &path="")
Initialize a FilePath object.
Definition filepath.cpp:103
bool isDirectory() const
Check whether the file is a directory.
Definition filepath.cpp:388
std::time_t lastModificationTime() const
Get the last modification time of the file.
Definition filepath.cpp:487
size_t fileSize() const
Get the size of the file.
Definition filepath.cpp:470
bool exists() const
Check whether the file exists.
Definition filepath.cpp:360
FilePath & operator=(std::string const &path)
Replace the path with a new path.
Definition filepath.cpp:154
size_t size() const
Get the length of the string.
Definition filepath.cpp:347
bool isRegular() const
Check whether the file is a regular file.
Definition filepath.cpp:374
std::string filename() const
Retrieve the basename.
Definition filepath.cpp:306
bool isSocket() const
Check whether the file is a socket.
Definition filepath.cpp:430
size_t length() const
Get the length of the string.
Definition filepath.cpp:327
The zipios namespace includes the Zipios library definitions.
std::ostream & operator<<(std::ostream &os, FileCollection const &collection)
Write a FileCollection to the output stream.
struct stat os_stat_t
zipios configuration header.