00001 00006 /* 00007 Copyright (C) 2001-2006, William Joseph. 00008 All Rights Reserved. 00009 00010 This file is part of GtkRadiant. 00011 00012 GtkRadiant is free software; you can redistribute it and/or modify 00013 it under the terms of the GNU General Public License as published by 00014 the Free Software Foundation; either version 2 of the License, or 00015 (at your option) any later version. 00016 00017 GtkRadiant is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 GNU General Public License for more details. 00021 00022 You should have received a copy of the GNU General Public License 00023 along with GtkRadiant; if not, write to the Free Software 00024 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00025 */ 00026 00027 #if !defined(INCLUDED_OS_DIR_H) 00028 #define INCLUDED_OS_DIR_H 00029 00030 #include <glib/gdir.h> 00031 00032 typedef GDir Directory; 00033 00034 inline bool directory_good (Directory* directory) 00035 { 00036 return directory != 0; 00037 } 00038 00039 inline Directory* directory_open (const std::string& name) 00040 { 00041 return g_dir_open(name.c_str(), 0, 0); 00042 } 00043 00044 inline void directory_close (Directory* directory) 00045 { 00046 g_dir_close(directory); 00047 } 00048 00049 inline const char* directory_read_and_increment (Directory* directory) 00050 { 00051 return g_dir_read_name(directory); 00052 } 00053 00054 template<typename Functor> 00055 void Directory_forEach(const std::string& path, const Functor& functor) { 00056 Directory* dir = directory_open(path); 00057 00058 if (directory_good(dir)) { 00059 for (;;) { 00060 const char* name = directory_read_and_increment(dir); 00061 if (name == 0) { 00062 break; 00063 } 00064 00065 functor(name); 00066 } 00067 00068 directory_close(dir); 00069 } 00070 } 00071 00072 #endif