| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#if !defined( INCLUDED_IARCHIVE_H ) |
| 23 |
#define INCLUDED_IARCHIVE_H |
| 24 |
|
| 25 |
#include <cstddef> |
| 26 |
#include "generic/constant.h" |
| 27 |
|
| 28 |
class InputStream; |
| 29 |
|
| 30 |
|
| 31 |
class ArchiveFile |
| 32 |
{ |
| 33 |
public: |
| 34 |
virtual ~ArchiveFile() = default; |
| 35 |
|
| 36 |
virtual void release() = 0; |
| 37 |
|
| 38 |
virtual std::size_t size() const = 0; |
| 39 |
|
| 40 |
virtual const char* getName() const = 0; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
virtual InputStream& getInputStream() = 0; |
| 46 |
}; |
| 47 |
|
| 48 |
class TextInputStream; |
| 49 |
|
| 50 |
|
| 51 |
class ArchiveTextFile |
| 52 |
{ |
| 53 |
public: |
| 54 |
virtual ~ArchiveTextFile() = default; |
| 55 |
|
| 56 |
virtual void release() = 0; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
virtual TextInputStream& getInputStream() = 0; |
| 62 |
}; |
| 63 |
|
| 64 |
class ScopedArchiveFile |
| 65 |
{ |
| 66 |
ArchiveFile& m_file; |
| 67 |
public: |
| 68 |
ScopedArchiveFile( ArchiveFile& file ) : m_file( file ){ |
| 69 |
} |
| 70 |
~ScopedArchiveFile(){ |
| 71 |
m_file.release(); |
| 72 |
} |
| 73 |
}; |
| 74 |
|
| 75 |
class CustomArchiveVisitor; |
| 76 |
|
| 77 |
class Archive |
| 78 |
{ |
| 79 |
public: |
| 80 |
virtual ~Archive() = default; |
| 81 |
|
| 82 |
class Visitor |
| 83 |
{ |
| 84 |
public: |
| 85 |
virtual void visit( const char* name ) = 0; |
| 86 |
}; |
| 87 |
|
| 88 |
typedef CustomArchiveVisitor VisitorFunc; |
| 89 |
|
| 90 |
enum EMode |
| 91 |
{ |
| 92 |
eFiles = 0x01, |
| 93 |
eDirectories = 0x02, |
| 94 |
eFilesAndDirectories = 0x03, |
| 95 |
}; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
virtual void release() = 0; |
| 100 |
|
| 101 |
|
| 102 |
virtual ArchiveFile* openFile( const char* name ) = 0; |
| 103 |
|
| 104 |
|
| 105 |
virtual ArchiveTextFile* openTextFile( const char* name ) = 0; |
| 106 |
|
| 107 |
|
| 108 |
virtual bool containsFile( const char* name ) = 0; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
virtual void forEachFile( VisitorFunc visitor, const char* root ) = 0; |
| 117 |
}; |
| 118 |
|
| 119 |
class CustomArchiveVisitor |
| 120 |
{ |
| 121 |
Archive::Visitor* m_visitor; |
| 122 |
Archive::EMode m_mode; |
| 123 |
std::size_t m_depth; |
| 124 |
public: |
| 125 |
CustomArchiveVisitor( Archive::Visitor& visitor, Archive::EMode mode, std::size_t depth ) |
| 126 |
: m_visitor( &visitor ), m_mode( mode ), m_depth( depth ){ |
| 127 |
} |
| 128 |
void file( const char* name ){ |
| 129 |
if ( ( m_mode & Archive::eFiles ) != 0 ) { |
| 130 |
m_visitor->visit( name ); |
| 131 |
} |
| 132 |
} |
| 133 |
bool directory( const char* name, std::size_t depth ){ |
| 134 |
if ( ( m_mode & Archive::eDirectories ) != 0 ) { |
| 135 |
m_visitor->visit( name ); |
| 136 |
} |
| 137 |
if ( depth == m_depth ) { |
| 138 |
return true; |
| 139 |
} |
| 140 |
return false; |
| 141 |
} |
| 142 |
}; |
| 143 |
|
| 144 |
typedef Archive* ( *PFN_OPENARCHIVE )( const char* name ); |
| 145 |
|
| 146 |
class _QERArchiveTable |
| 147 |
{ |
| 148 |
public: |
| 149 |
INTEGER_CONSTANT( Version, 1 ); |
| 150 |
STRING_CONSTANT( Name, "archive" ); |
| 151 |
|
| 152 |
PFN_OPENARCHIVE m_pfnOpenArchive; |
| 153 |
}; |
| 154 |
|
| 155 |
template<typename Type> |
| 156 |
class Modules; |
| 157 |
typedef Modules<_QERArchiveTable> ArchiveModules; |
| 158 |
|
| 159 |
template<typename Type> |
| 160 |
class ModulesRef; |
| 161 |
typedef ModulesRef<_QERArchiveTable> ArchiveModulesRef; |
| 162 |
|
| 163 |
#endif |