- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/Programmation/Sources/Tensor2/Utils/include/frost_utils_directory.h

Go to the documentation of this file.

    00001 /* ###################################### */
    00002 /* ###     Frost Engine, by Kalith    ### */
    00003 /* ###################################### */
    00004 /*                                        */
    00005 /*                                        */
    00006
    00007 #ifndef FROST_UTILS_DIRECTORY_H
    00008 #define FROST_UTILS_DIRECTORY_H
    00009
    00010 // Iterates through a Directory's sub directories
    00011 #define foreach_dir(subdir, dir) for ((subdir) = (dir).GetNextSubDirectory(); (subdir); (subdir) = (dir).GetNextSubDirectory())
    00012
    00013 #include "frost_utils_types.h"
    00014
    00015 namespace Frost
    00016 {
    00017     /// A tool for directory listing
    00018     /** This class iterates through every sub-
    00019     *   directories, store them in a vector and
    00020     *   list their sub-directories, ...
    00021     */
    00022     class Directory
    00023     {
    00024     public :
    00025
    00026         /// Call that constructor to open a directory.
    00027         /** \param sRelPath The directory path (relative to the program).
    00028         */
    00029         Directory(const s_str& sRelPath);
    00030
    00031         /// Iterates through sub-directories.
    00032         /** \return The next sub-directory, 'nullptr' if none
    00033         */
    00034         s_wptr<Directory> GetNextSubDirectory();
    00035
    00036         /// Returns the list of the contained files.
    00037         /** \param bWithPath       'true' to include this Directory's relative path
    00038         *   \param sExtensionFilter Use it to filter files depending on their extention
    00039         *   \return The list of the contained files
    00040         *   \note Example : if you use "xml" as the extention filter, then only *.xml
    00041         *         files will appear on the list.<br>
    00042         *         Example : if you use "xml, lua", then you'll only get *.xml and *.lua
    00043         *         files.
    00044         */
    00045         s_ctnr<s_str> GetFileList(const s_bool& bWithPath = false, const s_str& sExtensionFilter = "") const;
    00046
    00047         /// Returns the list of the contained files (recursive).
    00048         /** \param bWithPath       'true' to include this Directory's relative path
    00049         *   \param sExtensionFilter Use it to filter files depending on their extention
    00050         *   \return The list of the contained files (recursive)
    00051         *   \note Example : if you use "xml" as the extention filter, then only *.xml
    00052         *         files will appear on the list.<br>
    00053         *         Example : if you use "xml, lua", then you'll only get *.xml and *.lua
    00054         *         files.<br>
    00055         *         This function searches through subdirectories too.
    00056         */
    00057         s_ctnr<s_str> GetRecursiveFileList(const s_bool& bWithPath = false, const s_str& sExtensionFilter = "") const;
    00058
    00059         /// Returns this directory's name.
    00060         /** \return This directory's name
    00061         *   \note For example : Interface/Base_UI.<br>
    00062         *         This function would return "Base_UI".
    00063         */
    00064         const s_str& GetName() const;
    00065
    00066         /// Returns this directory's relative path.
    00067         /** \return This directory's relative path
    00068         *   \note For example : Interface/Base_UI.<br>
    00069         *         This function would return "Interface/Base_UI".
    00070         */
    00071         const s_str& GetRelPath() const;
    00072
    00073         /// Checks if a directory exists.
    00074         /** \param sPath The path to the directory to check
    00075         *   \return 'true' if the directory exists
    00076         */
    00077         static s_bool Exists(const s_str& sPath);
    00078
    00079         /// Creates a new directory.
    00080         /** \param sPath The path to the directory to create
    00081         *   \return 'true' if the operation was successful
    00082         *   \note This fuction doesn't check if the directory
    00083         *         already exists.
    00084         */
    00085         static s_bool Make(const s_str& sPath);
    00086
    00087         static const s_str CLASS_NAME;
    00088
    00089     private :
    00090
    00091         /// Creates a new directory.
    00092         /** \param sPath The path to the directory to create
    00093         *   \return 'true' if the operation was successful
    00094         *   \note This version is very low level, it does absolutely
    00095         *         no checks, nor does it support nested directories.
    00096         */
    00097         static s_bool Make_(const s_str& sPath);
    00098
    00099         /// The sub-directory list
    00100         s_ctnr< s_refptr<Directory> > lSubDirectoryList_;
    00101         /// The contained file list
    00102         s_ctnr<s_str>                 lFileList_;
    00103         /// The sub-directory iterator
    00104         s_uint uiIter_;
    00105         /// This directory name
    00106         s_str  sName_;
    00107         /// This directory relative path (with name)
    00108         s_str  sRelPath_;
    00109     };
    00110 }
    00111
    00112 #endif