# wiesel / src / common / wiesel / io / directory.h

 Christian Fische… b5d82b9 2012-04-18 Christian Fische… 194f094 2012-04-11 Christian Fische… b5d82b9 2012-04-18 Christian Fische… 194f094 2012-04-11 Christian Fische… 0c5cd71 2012-09-12 Christian Fische… 194f094 2012-04-11 Christian Fische… 0c5cd71 2012-09-12 Christian Fische… 194f094 2012-04-11 Christian Fische… 2d9179d 2012-05-02 Christian Fische… 194f094 2012-04-11 Christian Fische… c62ffea 2012-04-16 Christian Fische… 194f094 2012-04-11   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 /** * Copyright (C) 2012 * Christian Fischer * * https://bitbucket.org/baldur/wiesel/ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General * Public License along with this library; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA */ #ifndef __WIESEL_IO_DIRECTORY_H__ #define __WIESEL_IO_DIRECTORY_H__ #include #include "wiesel/util/shared_object.h" #include "file.h" #include #include #include namespace wiesel { class FileSystem; class Directory; /// Alias type for directory lists. typedef std::list DirectoryList; /** * @brief A class representing a directory within a \ref FileSystem. */ class WIESEL_COMMON_EXPORT Directory : public virtual SharedObject { private: Directory() {} protected: Directory(FileSystem *fs, Directory *parent); public: virtual ~Directory(); // getters public: /** * @brief Get the name of this directory. * The root directory's name may be empty. */ virtual std::string getName() const = 0; /** * @brief Get the full path of this directory. */ virtual std::string getFullPath(); /** * @brief get the directory's full path on the platform's native file system. * If there's no physical file system, for example on a in-memory stored * file system, this function will return an empty string. * @return the native path or an empty string, if there is no real filesystem. */ virtual std::string getNativePath(); /** * @brief get the \ref FileSystem, this directory is in. */ inline FileSystem* getFileSystem() { return fs; } /** * @brief get the parent-directory of this directory. * The root-directory will return \c NULL. */ inline Directory* getParent() { return parent; } // directory content access public: /** * @brief Get a list of all sub-directories. * Each time calling this function, the folder will be scanned for subdirectories. * There is no caching mechanism. */ virtual DirectoryList getSubDirectories() = 0; /** * @brief Get a list of all files in this directory. * Each time calling this function, the folder will be scanned for subdirectories. * There is no caching mechanism. */ virtual FileList getFiles() = 0; /** * @brief Get a direct subdirectory by it's name. * This function does not resolve relative path names or does a recursive search into other subdirectories. * @returns \c NULL, if there's no direct subdirectory with the given name. */ virtual Directory *getSubDirectory(const std::string &name); /** * @brief Tries to find a specific directory relative to the current directory by it's full name. * When the directory is not found, or the object which was found is a file-object, * \c findDirectory will return \c NULL. * To ensure platform compatibility, directories should be seperated by '/' characters, even on windows. */ virtual Directory *findDirectory(const std::string &name); /** * @brief Tries to find a specific file relative to the current directory by it's full name. * When the file is not found, or the object which was found is a directory, * \c findFile will return \c NULL. * To ensure platform compatibility, directories should be seperated by '/' characters, even on windows. */ virtual File *findFile(const std::string &name); // sort utilities public: /** * @brief Sort a list of directories by their names. */ static void sortByName(DirectoryList &list, bool asc=true); private: FileSystem* fs; Directory* parent; }; /** * @brief Predicate function to be used for sorting lists of directories by their names. */ inline bool DirectorySortByNameAscPredicate(const Directory *lhs, const Directory *rhs) { return lhs->getName() < rhs->getName(); } /** * @brief Predicate function to be used for sorting lists of directories by their names. */ inline bool DirectorySortByNameDescPredicate(const Directory *lhs, const Directory *rhs) { return lhs->getName() > rhs->getName(); } } /* namespace wiesel */ #endif /* __WIESEL_IO_DIRECTORY_H__ */