Line data Source code
1 : /*
2 : Zipios++ - a small C++ library that provides easy access to .zip files.
3 :
4 : Copyright (C) 2000-2007 Thomas Sondergaard
5 : Copyright (C) 2015 Made to Order Software Corporation
6 :
7 : This library is free software; you can redistribute it and/or
8 : modify it under the terms of the GNU Lesser General Public
9 : License as published by the Free Software Foundation; either
10 : version 2 of the License, or (at your option) any later version.
11 :
12 : This library is distributed in the hope that it will be useful,
13 : but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 : Lesser General Public License for more details.
16 :
17 : You should have received a copy of the GNU Lesser General Public
18 : License along with this library; if not, write to the Free Software
19 : Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 : */
21 :
22 : /** \file
23 : * \brief Implementation of zipios::DirectoryEntry.
24 : *
25 : * The declaration of a simple zipios::FileEntry used when reading
26 : * a directory from disk.
27 : */
28 :
29 : #include "zipios++/directoryentry.hpp"
30 :
31 : #include "zipios++/zipiosexceptions.hpp"
32 :
33 : #include "zipios_common.hpp"
34 :
35 :
36 : namespace zipios
37 : {
38 :
39 : /** \class DirectoryEntry
40 : * \brief A file entry that does not use compression.
41 : *
42 : * DirectoryEntry is a FileEntry that is suitable as a base class for
43 : * basic entries, that do not support any form of compression and
44 : * in most cases represent a file in a directtory.
45 : */
46 :
47 :
48 : /** \brief Initialize a DirectoryEntry object.
49 : *
50 : * This constructor initializes a DirectoryEntry which represents a
51 : * file on disk. If the basepath + filename does not exist or is
52 : * neither a regular file or a directory, then this entry is created
53 : * but marked as invalid.
54 : *
55 : * \param[in] filename The filename of the entry.
56 : * \param[in] comment A comment for the entry.
57 : */
58 143144 : DirectoryEntry::DirectoryEntry(FilePath const & filename, std::string const & comment)
59 143144 : : FileEntry(filename, comment)
60 : {
61 143144 : m_valid = m_filename.isRegular() || m_filename.isDirectory();
62 143144 : if(m_valid)
63 : {
64 143006 : m_uncompressed_size = m_filename.isDirectory() ? 0 : m_filename.fileSize();
65 143006 : m_unix_time = m_filename.lastModificationTime();
66 : }
67 143144 : }
68 :
69 :
70 : /** \brief Create a copy of the DirectoryEntry.
71 : *
72 : * The clone function creates a copy of this DirectoryEntry object.
73 : *
74 : * In most cases, when a collection is copied, a clone of each
75 : * entry is created to avoid potential problems with sharing
76 : * the same object between various lists.
77 : *
78 : * \return A shared pointer of the new DirectoryEntry object.
79 : */
80 150977 : DirectoryEntry::pointer_t DirectoryEntry::clone() const
81 : {
82 150977 : return DirectoryEntry::pointer_t(new DirectoryEntry(*this));
83 : }
84 :
85 :
86 : /** \brief Clean up a DirectoryEntry object.
87 : *
88 : * The destructor is defined as it has to be virtual.
89 : *
90 : * It will eventually clean up resources used by the DirectoryEntry class.
91 : */
92 456831 : DirectoryEntry::~DirectoryEntry()
93 : {
94 456831 : }
95 :
96 :
97 : /** \brief Compare two file entries for equality.
98 : *
99 : * This function compares most of the fields between two file
100 : * entries to see whether they are equal or not.
101 : *
102 : * \note
103 : * This function calls the base class isEqual() and also verifies
104 : * that the object comments are equal.
105 : *
106 : * \param[in] file_entry The file entry to compare this against.
107 : *
108 : * \return true if both FileEntry objects are considered equal.
109 : */
110 1557 : bool DirectoryEntry::isEqual(FileEntry const & file_entry) const
111 : {
112 1557 : DirectoryEntry const * const de(dynamic_cast<DirectoryEntry const * const>(&file_entry));
113 1557 : if(!de)
114 : {
115 1098 : return false;
116 : }
117 459 : return FileEntry::isEqual(file_entry);
118 : }
119 :
120 :
121 3 : } // zipios namespace
122 :
123 : // Local Variables:
124 : // mode: cpp
125 : // indent-tabs-mode: nil
126 : // c-basic-offset: 4
127 : // tab-width: 4
128 : // End:
129 :
130 : // vim: ts=4 sw=4 et
|