~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to source/Irrlicht/CFileList.h

  • Committer: Mantas Kriaučiūnas
  • Date: 2011-07-18 13:06:25 UTC
  • Revision ID: mantas@akl.lt-20110718130625-c5pvifp61e7kj1ol
Included whole irrlicht SVN libraries to work around launchpad recipe issue with quilt, see https://answers.launchpad.net/launchpad/+question/165193

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
 
2
// This file is part of the "Irrlicht Engine".
 
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
 
4
 
 
5
#ifndef __C_FILE_LIST_H_INCLUDED__
 
6
#define __C_FILE_LIST_H_INCLUDED__
 
7
 
 
8
#include "IFileList.h"
 
9
#include "irrString.h"
 
10
#include "irrArray.h"
 
11
 
 
12
 
 
13
namespace irr
 
14
{
 
15
namespace io
 
16
{
 
17
 
 
18
//! An entry in a list of files, can be a folder or a file.
 
19
struct SFileListEntry
 
20
{
 
21
        //! The name of the file
 
22
        /** If this is a file or folder in the virtual filesystem and the archive
 
23
        was created with the ignoreCase flag then the file name will be lower case. */
 
24
        io::path Name;
 
25
 
 
26
        //! The name of the file including the path
 
27
        /** If this is a file or folder in the virtual filesystem and the archive was
 
28
        created with the ignoreDirs flag then it will be the same as Name. */
 
29
        io::path FullName;
 
30
 
 
31
        //! The size of the file in bytes
 
32
        u32 Size;
 
33
 
 
34
        //! The ID of the file in an archive
 
35
        /** This is used to link the FileList entry to extra info held about this
 
36
        file in an archive, which can hold things like data offset and CRC. */
 
37
        u32 ID;
 
38
 
 
39
        //! FileOffset inside an archive
 
40
        u32 Offset;
 
41
 
 
42
        //! True if this is a folder, false if not.
 
43
        bool IsDirectory;
 
44
 
 
45
        //! The == operator is provided so that CFileList can slowly search the list!
 
46
        bool operator ==(const struct SFileListEntry& other) const
 
47
        {
 
48
                if (IsDirectory != other.IsDirectory)
 
49
                        return false;
 
50
 
 
51
                return FullName.equals_ignore_case(other.FullName);
 
52
        }
 
53
 
 
54
        //! The < operator is provided so that CFileList can sort and quickly search the list.
 
55
        bool operator <(const struct SFileListEntry& other) const
 
56
        {
 
57
                if (IsDirectory != other.IsDirectory)
 
58
                        return IsDirectory;
 
59
 
 
60
                return FullName.lower_ignore_case(other.FullName);
 
61
        }
 
62
};
 
63
 
 
64
 
 
65
//! Implementation of a file list
 
66
class CFileList : public IFileList
 
67
{
 
68
public:
 
69
 
 
70
        // CFileList methods
 
71
 
 
72
        //! Constructor
 
73
        /** \param path The path of this file archive */
 
74
        CFileList(const io::path& path, bool ignoreCase, bool ignorePaths);
 
75
 
 
76
        //! Destructor
 
77
        virtual ~CFileList();
 
78
 
 
79
        //! Add as a file or folder to the list
 
80
        /** \param fullPath The file name including path, up to the root of the file list.
 
81
        \param isDirectory True if this is a directory rather than a file.
 
82
        \param offset The offset where the file is stored in an archive
 
83
        \param size The size of the file in bytes.
 
84
        \param id The ID of the file in the archive which owns it */
 
85
        virtual u32 addItem(const io::path& fullPath, u32 offset, u32 size, bool isDirectory, u32 id=0);
 
86
 
 
87
        //! Sorts the file list. You should call this after adding any items to the file list
 
88
        virtual void sort();
 
89
 
 
90
        //! Returns the amount of files in the filelist.
 
91
        virtual u32 getFileCount() const;
 
92
 
 
93
        //! Gets the name of a file in the list, based on an index.
 
94
        virtual const io::path& getFileName(u32 index) const;
 
95
 
 
96
        //! Gets the full name of a file in the list, path included, based on an index.
 
97
        virtual const io::path& getFullFileName(u32 index) const;
 
98
 
 
99
        //! Returns the ID of a file in the file list, based on an index.
 
100
        virtual u32 getID(u32 index) const;
 
101
 
 
102
        //! Returns true if the file is a directory
 
103
        virtual bool isDirectory(u32 index) const;
 
104
 
 
105
        //! Returns the size of a file
 
106
        virtual u32 getFileSize(u32 index) const;
 
107
 
 
108
        //! Returns the offest of a file
 
109
        virtual u32 getFileOffset(u32 index) const;
 
110
 
 
111
        //! Searches for a file or folder within the list, returns the index
 
112
        virtual s32 findFile(const io::path& filename, bool isFolder) const;
 
113
 
 
114
        //! Returns the base path of the file list
 
115
        virtual const io::path& getPath() const;
 
116
 
 
117
protected:
 
118
 
 
119
        //! Ignore paths when adding or searching for files
 
120
        bool IgnorePaths;
 
121
 
 
122
        //! Ignore case when adding or searching for files
 
123
        bool IgnoreCase;
 
124
 
 
125
        //! Path to the file list
 
126
        io::path Path;
 
127
 
 
128
        //! List of files
 
129
        core::array<SFileListEntry> Files;
 
130
};
 
131
 
 
132
 
 
133
} // end namespace irr
 
134
} // end namespace io
 
135
 
 
136
 
 
137
#endif
 
138