zipios 2.3.4
Zipios -- a small C++ library providing 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-2022 Made to Order Software Corp. All Rights Reserved
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
37
38#include <ctime>
39#include <string>
40
41
42namespace zipios
43{
44
45
47{
48public:
49 FilePath(std::string const & path = std::string());
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 void clear();
61 std::string filename() const;
62 size_t length() const;
63 size_t size() const;
64 bool empty() const;
65 bool exists() const;
66 bool isRegular() const;
67 bool isDirectory() const;
68 bool isCharSpecial() const;
69 bool isBlockSpecial() const;
70 bool isSocket() const;
71 bool isFifo() const;
72 size_t fileSize() const;
73 std::time_t lastModificationTime() const;
74
75private:
76 void check() const;
77
78 std::string m_path = std::string();
79 mutable os_stat_t m_stat = {};
80 mutable bool m_checked = false;
81 mutable bool m_exists = false;
82};
83
84
85std::ostream & operator << (std::ostream & os, FilePath const & path);
86
87
88} // zipios namespace
89
90// Local Variables:
91// mode: cpp
92// indent-tabs-mode: nil
93// c-basic-offset: 4
94// tab-width: 4
95// End:
96
97// vim: ts=4 sw=4 et
98#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:478
void check() const
Read the file mode.
Definition filepath.cpp:119
FilePath operator+(FilePath const &name) const
Append the a child name to this path.
Definition filepath.cpp:185
bool isCharSpecial() const
Check whether the file is a character special file.
Definition filepath.cpp:436
bool isBlockSpecial() const
Check whether the file is a block special file.
Definition filepath.cpp:450
std::string m_path
Definition filepath.hpp:78
friend bool operator==(char const *lhs, FilePath const &rhs)
Check whether two FilePath represent the same file.
Definition filepath.cpp:235
void clear()
Clear the filename.
Definition filepath.cpp:301
os_stat_t m_stat
Definition filepath.hpp:79
bool isDirectory() const
Check whether the file is a directory.
Definition filepath.cpp:422
std::time_t lastModificationTime() const
Get the last modification time of the file.
Definition filepath.cpp:521
bool empty() const
Check whether the filename is empty.
Definition filepath.cpp:381
size_t fileSize() const
Get the size of the file.
Definition filepath.cpp:504
bool exists() const
Check whether the file exists.
Definition filepath.cpp:394
FilePath & operator=(std::string const &path)
Replace the path with a new path.
Definition filepath.cpp:149
size_t size() const
Get the length of the string.
Definition filepath.cpp:356
bool isRegular() const
Check whether the file is a regular file.
Definition filepath.cpp:408
std::string filename() const
Retrieve the basename.
Definition filepath.cpp:315
bool isSocket() const
Check whether the file is a socket.
Definition filepath.cpp:464
size_t length() const
Get the length of the string.
Definition filepath.cpp:336
The zipios namespace includes the Zipios library definitions.
std::ostream & operator<<(std::ostream &os, FileCollection const &collection)
Write a FileCollection to the output stream.
zipios configuration header.
struct stat os_stat_t