1 ////////////////////////////////////////////////////////////////////////////////
3 // Author: Artur Szostak
4 // Email: artur@alice.phy.uct.ac.za | artursz@iafrica.com
6 // Author: Gareth de Vaux
7 // Email: devaux@lhc.phy.uct.ac.za | dhlt@lordcow.org
9 ////////////////////////////////////////////////////////////////////////////////
11 #ifndef dHLT_DDL_FILE_LIST_HPP
12 #define dHLT_DDL_FILE_LIST_HPP
15 #include "BasicTypes.hpp"
27 PATH_NOT_FOUND = 0x10020001
31 class PathNotFound : public Error
34 PathNotFound(const char* path) throw (OutOfMemory);
35 virtual ~PathNotFound() throw ();
37 virtual const char* Message() const throw();
38 virtual Int ErrorCode() const throw();
52 /* Creates a new file list and initialises it by adding the specified path.
54 FileList(const char* path, const bool recursive = true);
58 /* Returns true if the file list is empty.
62 /* Returns the number of files in the list.
66 /* If path contains a valid directory then all files in that directory are
67 added to the filelist. If recursive is true then all files in the sub
68 directories are also added.
69 If the path contains the name of a specific file then it is assumed the
70 file is a text file containing a list of paths to add to the list.
71 In this case the recursive flag should be applied to all the paths found.
73 void Add(const char* path, const bool recursive = true);
75 /* Checks if the file list contains the specified file name.
77 bool Contains(const char* filename) const;
79 /* Looks for the specifed file name in the file list and returns the index
81 -1 is returned if the file could not be found.
83 Int Find(const char* filename) const;
85 /* Returns the index'th file name in the list.
87 const char* FileName(const UInt index) const;
89 /* Returns the size of the index'th file in the list.
91 UInt FileSize(const UInt index) const;
93 /* Loads the specified file contents into memory. The calling process must
94 clean up the memory allocated with a call to delete [] buffer.
95 size is filled with the size of the buffer.
96 True is returned if the file was located in the file list.
98 bool Fetch(const char* filename, char*& buffer, UInt& size) const;
100 // Same as above but fetch the index'th file.
101 void Fetch(const UInt index, char*& buffer, UInt& size) const;
103 /* Loads the file contents just like above, however the buffer must be
104 preallocated by the caller. Only 'size' number of bytes are read from
105 the file and filled into the buffer. If the file is smaller than the
106 buffer size then the remaining bytes are left untouched.
108 bool Fetch(const char* filename, const UInt size, char* buffer) const;
110 // Same as above but fetch the index'th file.
111 void Fetch(const UInt index, const UInt size, char* buffer) const;
113 /* Empties the file list.
119 void AddFile(const char* filename); // Called by Add & constructor
121 void AddDir(const char* path, const bool recursive = true);
123 UInt ParseLine(const UInt currentStart, char* buffer, const UInt end);
125 std::vector<char*> list;
133 #endif // dHLT_DDL_FILE_LIST_HPP