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 
36 #include "zipios/zipios-config.hpp"
37 
38 #include <ctime>
39 #include <string>
40 
41 
42 namespace zipios
43 {
44 
45 
46 class FilePath
47 {
48 public:
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 
73 private:
74  void check() const;
75 
76  std::string m_path;
77  mutable os_stat_t m_stat;
78  mutable bool m_checked = false;
79  mutable bool m_exists = false;
80 };
81 
82 
83 std::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
std::ostream & operator<<(std::ostream &os, FileCollection const &collection)
Write a FileCollection to the output stream.
The zipios namespace includes the Zipios library definitions.
Definition: backbuffer.cpp:35
std::string filename() const
Retrieve the basename.
Definition: filepath.cpp:306
bool isRegular() const
Check whether the file is a regular file.
Definition: filepath.cpp:374
FilePath(std::string const &path="")
Initialize a FilePath object.
Definition: filepath.cpp:103
bool isCharSpecial() const
Check whether the file is a character special file.
Definition: filepath.cpp:402
bool isSocket() const
Check whether the file is a socket.
Definition: filepath.cpp:430
os_stat_t m_stat
Definition: filepath.hpp:77
std::time_t lastModificationTime() const
Get the last modification time of the file.
Definition: filepath.cpp:487
bool isBlockSpecial() const
Check whether the file is a block special file.
Definition: filepath.cpp:416
FilePath & operator=(std::string const &path)
Replace the path with a new path.
Definition: filepath.cpp:154
std::string m_path
Definition: filepath.hpp:76
bool isDirectory() const
Check whether the file is a directory.
Definition: filepath.cpp:388
bool operator==(char const *rhs) const
Check whether two FilePath represent the same file.
Definition: filepath.cpp:219
bool exists() const
Check whether the file exists.
Definition: filepath.cpp:360
size_t fileSize() const
Get the size of the file.
Definition: filepath.cpp:470
zipios configuration header.
size_t size() const
Get the length of the string.
Definition: filepath.cpp:347
bool isFifo() const
Check whether the file is a pipe.
Definition: filepath.cpp:444
Handle a file path and name and its statistics.
Definition: filepath.hpp:46
size_t length() const
Get the length of the string.
Definition: filepath.cpp:327
FilePath operator+(FilePath const &name) const
Append the a child name to this path.
Definition: filepath.cpp:187
void check() const
Read the file mode.
Definition: filepath.cpp:124
struct stat os_stat_t