2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant 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
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #if !defined( INCLUDED_IARCHIVE_H )
23 #define INCLUDED_IARCHIVE_H
26 #include "generic/constant.h"
30 /// \brief A file opened in binary mode.
34 virtual ~ArchiveFile() = default;
35 /// \brief Destroys the file object.
36 virtual void release() = 0;
37 /// \brief Returns the size of the file data in bytes.
38 virtual std::size_t size() const = 0;
39 /// \brief Returns the path to this file (relative to the filesystem root)
40 virtual const char* getName() const = 0;
41 /// \brief Returns the stream associated with this file.
42 /// Subsequent calls return the same stream.
43 /// The stream may be read forwards until it is exhausted.
44 /// The stream remains valid for the lifetime of the file.
45 virtual InputStream& getInputStream() = 0;
48 class TextInputStream;
50 /// \brief A file opened in text mode.
54 virtual ~ArchiveTextFile() = default;
55 /// \brief Destroys the file object.
56 virtual void release() = 0;
57 /// \brief Returns the stream associated with this file.
58 /// Subsequent calls return the same stream.
59 /// The stream may be read forwards until it is exhausted.
60 /// The stream remains valid for the lifetime of the file.
61 virtual TextInputStream& getInputStream() = 0;
64 class ScopedArchiveFile
68 ScopedArchiveFile( ArchiveFile& file ) : m_file( file ){
75 class CustomArchiveVisitor;
80 virtual ~Archive() = default;
85 virtual void visit( const char* name ) = 0;
88 typedef CustomArchiveVisitor VisitorFunc;
94 eFilesAndDirectories = 0x03,
97 /// \brief Destroys the archive object.
98 /// Any unreleased file object associated with the archive remains valid. */
99 virtual void release() = 0;
100 /// \brief Returns a new object associated with the file identified by \p name, or 0 if the file cannot be opened.
101 /// Name comparisons are case-insensitive.
102 virtual ArchiveFile* openFile( const char* name ) = 0;
103 /// \brief Returns a new object associated with the file identified by \p name, or 0 if the file cannot be opened.
104 /// Name comparisons are case-insensitive.
105 virtual ArchiveTextFile* openTextFile( const char* name ) = 0;
106 /// Returns true if the file identified by \p name can be opened.
107 /// Name comparisons are case-insensitive.
108 virtual bool containsFile( const char* name ) = 0;
109 /// \brief Performs a depth-first traversal of the archive tree starting at \p root.
110 /// Traverses the entire tree if \p root is "".
111 /// When a file is encountered, calls \c visitor.file passing the file name.
112 /// When a directory is encountered, calls \c visitor.directory passing the directory name.
113 /// Skips the directory if \c visitor.directory returned true.
114 /// Root comparisons are case-insensitive.
115 /// Names are mixed-case.
116 virtual void forEachFile( VisitorFunc visitor, const char* root ) = 0;
119 class CustomArchiveVisitor
121 Archive::Visitor* m_visitor;
122 Archive::EMode m_mode;
125 CustomArchiveVisitor( Archive::Visitor& visitor, Archive::EMode mode, std::size_t depth )
126 : m_visitor( &visitor ), m_mode( mode ), m_depth( depth ){
128 void file( const char* name ){
129 if ( ( m_mode & Archive::eFiles ) != 0 ) {
130 m_visitor->visit( name );
133 bool directory( const char* name, std::size_t depth ){
134 if ( ( m_mode & Archive::eDirectories ) != 0 ) {
135 m_visitor->visit( name );
137 if ( depth == m_depth ) {
144 typedef Archive* ( *PFN_OPENARCHIVE )( const char* name );
146 class _QERArchiveTable
149 INTEGER_CONSTANT( Version, 1 );
150 STRING_CONSTANT( Name, "archive" );
152 PFN_OPENARCHIVE m_pfnOpenArchive;
155 template<typename Type>
157 typedef Modules<_QERArchiveTable> ArchiveModules;
159 template<typename Type>
161 typedef ModulesRef<_QERArchiveTable> ArchiveModulesRef;